import { accountAuth } from "./account";
import createWindow from "./window";
-
export default async function main() {
/* initiate controls for frontend to use when needed */
import { config } from "@/config";
import useWebsockets from "./composables/useWebsockets";
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
-const uiState = new UIState()
+const uiState = new UIState();
// let audio = new Audio();
-
const onMessageCallback = (payload: string) => {
if (payload === "CLOSE_AUTH_FAIL") {
if (message.header === "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,
+ });
+ }
+
+ }
+ }
}
uiState.reset();
}
+