add notification on new message when window is closed
This commit is contained in:
parent
5811f89942
commit
2dee81fb36
2 changed files with 40 additions and 4 deletions
|
|
@ -13,7 +13,6 @@ import initIpcMain from "@/ipc/index";
|
||||||
import { accountAuth } from "./account";
|
import { accountAuth } from "./account";
|
||||||
import createWindow from "./window";
|
import createWindow from "./window";
|
||||||
|
|
||||||
|
|
||||||
export default async function main() {
|
export default async function main() {
|
||||||
|
|
||||||
/* initiate controls for frontend to use when needed */
|
/* initiate controls for frontend to use when needed */
|
||||||
|
|
|
||||||
|
|
@ -4,13 +4,33 @@ import UIState from "@/uiState";
|
||||||
import { config } from "@/config";
|
import { config } from "@/config";
|
||||||
import useWebsockets from "./composables/useWebsockets";
|
import useWebsockets from "./composables/useWebsockets";
|
||||||
import { backgroundMitt, ipcEmit } from "@/composables/useEmitter";
|
import { backgroundMitt, ipcEmit } from "@/composables/useEmitter";
|
||||||
|
import { Notification } from 'electron';
|
||||||
|
|
||||||
|
let win: boolean;
|
||||||
|
|
||||||
|
// Listen for window creation.
|
||||||
|
backgroundMitt.on('window-active', (state: boolean) => {
|
||||||
|
win = state;
|
||||||
|
});
|
||||||
|
|
||||||
|
function showNotification (options: {
|
||||||
|
title: string;
|
||||||
|
subtitle?: string;
|
||||||
|
body: string;
|
||||||
|
}) {
|
||||||
|
new Notification(
|
||||||
|
{
|
||||||
|
title: options.title,
|
||||||
|
subtitle: options.subtitle,
|
||||||
|
body: options.body,
|
||||||
|
}).show()
|
||||||
|
}
|
||||||
|
|
||||||
// UI state
|
// UI state
|
||||||
const uiState = new UIState()
|
const uiState = new UIState();
|
||||||
|
|
||||||
// let audio = new Audio();
|
// let audio = new Audio();
|
||||||
|
|
||||||
|
|
||||||
const onMessageCallback = (payload: string) => {
|
const onMessageCallback = (payload: string) => {
|
||||||
|
|
||||||
if (payload === "CLOSE_AUTH_FAIL") {
|
if (payload === "CLOSE_AUTH_FAIL") {
|
||||||
|
|
@ -22,7 +42,23 @@ const onMessageCallback = (payload: string) => {
|
||||||
|
|
||||||
if (message.header === "init") {
|
if (message.header === "init") {
|
||||||
uiState.set(message.body as Init);
|
uiState.set(message.body as Init);
|
||||||
} else uiState.update(message.body as Update);
|
} else {
|
||||||
|
const body = message.body as Update;
|
||||||
|
uiState.update(body);
|
||||||
|
|
||||||
|
// show notification if window is not active
|
||||||
|
if (!win) {
|
||||||
|
if (body.name === "add") {
|
||||||
|
const data = body.data as Message;
|
||||||
|
showNotification({
|
||||||
|
title: 'New Message',
|
||||||
|
subtitle: data.context.text as string,
|
||||||
|
body: data.content[0].text,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -69,3 +105,4 @@ export function endSession() {
|
||||||
uiState.reset();
|
uiState.reset();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue