add window state management to store
This commit is contained in:
parent
2dee81fb36
commit
f1a5cad4db
3 changed files with 29 additions and 15 deletions
|
|
@ -9,6 +9,7 @@ import { app, protocol } from "electron";
|
||||||
import createWindow from "./window";
|
import createWindow from "./window";
|
||||||
import main from "./main";
|
import main from "./main";
|
||||||
import { backgroundMitt } from '@/composables/useEmitter';
|
import { backgroundMitt } from '@/composables/useEmitter';
|
||||||
|
import {setWindow, getWindow } from './store';
|
||||||
|
|
||||||
console.log('Starting Crimata electron app.');
|
console.log('Starting Crimata electron app.');
|
||||||
|
|
||||||
|
|
@ -19,11 +20,9 @@ protocol.registerSchemesAsPrivileged([
|
||||||
|
|
||||||
const isDev = require('electron-is-dev');
|
const isDev = require('electron-is-dev');
|
||||||
|
|
||||||
let win: boolean;
|
|
||||||
|
|
||||||
// Listen for window creation.
|
// Listen for window creation.
|
||||||
backgroundMitt.on('window-active', (state: boolean) => {
|
backgroundMitt.on('window-active', (state: boolean) => {
|
||||||
win = state;
|
setWindow(state)
|
||||||
});
|
});
|
||||||
|
|
||||||
/* Start main process on ready */
|
/* Start main process on ready */
|
||||||
|
|
@ -41,7 +40,7 @@ app.on("window-all-closed", () => {
|
||||||
|
|
||||||
// When user clicks app icon (re-open)
|
// When user clicks app icon (re-open)
|
||||||
app.on("activate", () => {
|
app.on("activate", () => {
|
||||||
if (!win) createWindow();
|
if (!getWindow()) createWindow();
|
||||||
});
|
});
|
||||||
|
|
||||||
// Exit cleanly on request from parent process in development mode.
|
// Exit cleanly on request from parent process in development mode.
|
||||||
|
|
|
||||||
|
|
@ -5,13 +5,7 @@ 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';
|
import { Notification } from 'electron';
|
||||||
|
import { getWindow } from './store';
|
||||||
let win: boolean;
|
|
||||||
|
|
||||||
// Listen for window creation.
|
|
||||||
backgroundMitt.on('window-active', (state: boolean) => {
|
|
||||||
win = state;
|
|
||||||
});
|
|
||||||
|
|
||||||
function showNotification (options: {
|
function showNotification (options: {
|
||||||
title: string;
|
title: string;
|
||||||
|
|
@ -47,7 +41,7 @@ const onMessageCallback = (payload: string) => {
|
||||||
uiState.update(body);
|
uiState.update(body);
|
||||||
|
|
||||||
// show notification if window is not active
|
// show notification if window is not active
|
||||||
if (!win) {
|
if (!getWindow()) {
|
||||||
if (body.name === "add") {
|
if (body.name === "add") {
|
||||||
const data = body.data as Message;
|
const data = body.data as Message;
|
||||||
showNotification({
|
showNotification({
|
||||||
|
|
|
||||||
21
src/store.ts
21
src/store.ts
|
|
@ -3,6 +3,9 @@ const Store = require('electron-store');
|
||||||
const schema = {
|
const schema = {
|
||||||
token: {
|
token: {
|
||||||
type: 'string',
|
type: 'string',
|
||||||
|
},
|
||||||
|
window: {
|
||||||
|
type: 'boolean'
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -11,6 +14,9 @@ const store = new Store({
|
||||||
encryptionKey: "super user test"
|
encryptionKey: "super user test"
|
||||||
});
|
});
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Token state management
|
||||||
|
* */
|
||||||
export const setToken = (token: string): void => {
|
export const setToken = (token: string): void => {
|
||||||
store.set("token", token);
|
store.set("token", token);
|
||||||
}
|
}
|
||||||
|
|
@ -22,3 +28,18 @@ export const getToken = (): string | undefined => {
|
||||||
export const clearToken = (): void => {
|
export const clearToken = (): void => {
|
||||||
store.delete("token");
|
store.delete("token");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Window state management
|
||||||
|
* */
|
||||||
|
export const setWindow = (state: boolean): void => {
|
||||||
|
store.set("window", state);
|
||||||
|
}
|
||||||
|
|
||||||
|
export const getWindow = (): boolean | undefined => {
|
||||||
|
return store.get("window");
|
||||||
|
}
|
||||||
|
|
||||||
|
export const clearWindow = (): void => {
|
||||||
|
store.delete("window");
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue