import createWindow from "./window";
import main from "./main";
import { backgroundMitt } from '@/composables/useEmitter';
-import {setWindow, getWindow } from './store';
+import {setWindowOpen, getWindowOpen } from './store';
console.log('Starting Crimata electron app.');
// Listen for window creation.
backgroundMitt.on('window-active', (state: boolean) => {
- setWindow(state)
+ setWindowOpen(state)
});
/* Start main process on ready */
// When user clicks app icon (re-open)
app.on("activate", () => {
- if (!getWindow()) createWindow();
+ if (!getWindowOpen()) createWindow();
});
// Exit cleanly on request from parent process in development mode.
-
import { IpcListener } from "@/composables/useIpcMain"
import { sendMessage } from '@/session';
import { updateAppState } from "@/account";
import { onNavBar } from "@/window";
+import { setWindowFocus } from '@/store';
const CLIENT_MESSAGE_CHANNEL = "post-session-send"
const APP_MOUNT_CHANNEL = "post-app-mount";
const NAV_BAR_CHANNEL = "post-nav-bar";
+const POST_WINDOW_FOCUS = 'post-window-focus';
export const messageListener = new IpcListener<Raw | Request>({
channel: CLIENT_MESSAGE_CHANNEL,
channel: NAV_BAR_CHANNEL,
listenerCallback: onNavBar
});
+
+export const windowFocusListener = new IpcListener<FocusPayload>({
+ channel: POST_WINDOW_FOCUS,
+ listenerCallback: ({ isFocused }) => setWindowFocus(isFocused)
+});
import { profile } from "@/render/shared/profile";
import { messages } from "@/render/shared/messages";
import useScroll from "@/render/composables/useScroll";
-import { postMessage } from "@/render/ipc";
+import { postMessage, postWindowFocus } from "@/render/ipc";
export default defineComponent({
name: "Messenger",
setup() {
const onFocus = () => {
+ postWindowFocus({ isFocused: true });
postMessage({
intent: "focus",
params: { "focus": true },
}
const onBlur = () => {
+ postWindowFocus({ isFocused: false });
postMessage({
intent: "focus",
params: { "focus": false },
*
*/
-export const postWindowBlur = (payload: { isFocused: boolean }): void => (
+export const postWindowFocus = (payload: { isFocused: boolean }): void => (
post('post-window-focus', payload)
);
import useWebsockets from "./composables/useWebsockets";
import { backgroundMitt, ipcEmit } from "@/composables/useEmitter";
import { Notification } from 'electron';
-import { getWindow } from './store';
+import { getWindowFocus, getWindowOpen } from './store';
function showNotification (options: {
title: string;
const body = message.body as Update;
uiState.update(body);
+ const isFocused = getWindowFocus();
+ const isOpen = getWindowOpen();
// show notification if window is not active
- if (!getWindow()) {
+ if (!isFocused || !isOpen) {
if (body.name === "add") {
const data = body.data as Message;
showNotification({
uiState.emit();
}
-export function sendMessage<Message>(message: Raw | Request): void {
+export function sendMessage(message: Raw | Request): void {
send(message);
}
token: {
type: 'string',
},
- window: {
- type: 'boolean'
- }
};
const store = new Store({
/*
* Window state management
* */
-export const setWindow = (state: boolean): void => {
- store.set("window", state);
+export const setWindowOpen = (state: boolean): void => {
+ store.set("window.isOpen", state);
}
-export const getWindow = (): boolean | undefined => {
- return store.get("window");
+export const getWindowOpen = (): boolean | undefined => {
+ return store.get("window.isOpen");
}
-export const clearWindow = (): void => {
- store.delete("window");
+export const setWindowFocus = (state: boolean): void => {
+ store.set("window.isFocused", state);
}
+
+export const getWindowFocus = (): boolean | undefined => {
+ return store.get("window.isFocused");
+}
+
payload: T | null;
}
+interface FocusPayload {
+ isFocused: boolean;
+}
+