diff --git a/src/App.vue b/src/App.vue index 07f8fc2..1929108 100644 --- a/src/App.vue +++ b/src/App.vue @@ -48,11 +48,16 @@ export default defineComponent({ window.ipcRenderer.removeAllListeners('window-ready') }) - const callNavbar = (action: string) => { + const saveWindowState = async () => { + await invoke('window-save', ""); + } + + const callNavbar = async (action: string) => { // save messages before closing. if (action === 'close') { saveMessages(); + await saveWindowState(); } invoke('nav-bar', action); diff --git a/src/background/run.ts b/src/background/run.ts index 55aad46..a007ad5 100644 --- a/src/background/run.ts +++ b/src/background/run.ts @@ -12,11 +12,7 @@ let socket = false; export async function main() { // create main window. - await createWindow({ - width: 600, - height: 500, - resizable: true - }); + await createWindow(); // Instantiate socket session with crimata-platorm. if (!socket) initSession(); diff --git a/src/background/window.ts b/src/background/window.ts index 27aac38..d46da18 100644 --- a/src/background/window.ts +++ b/src/background/window.ts @@ -5,12 +5,7 @@ import { createProtocol } from "vue-cli-plugin-electron-builder/lib"; import { backgroundMitt } from './emitter'; import { RenderMessage } from "@/types/message/index"; import * as path from "path"; - -interface WindowSettings { - width: number; - height: number; - resizable: boolean; -} +import fs from 'fs'; interface IpcRendererPayload { endpoint: string; @@ -40,12 +35,28 @@ const renderMessage = (payload: IpcRendererPayload): void => { } } +const onWindowSave = (_event, _s: string) => { + if (win) { + const bounds = win.getBounds(); + const state = JSON.stringify({w: bounds.width, h: bounds.height}); + + fs.writeFile('windowstate.json', state, (err: Error) => { + if (err) throw err; + return; + }); + } + +} + // Do this on window mount. const windowMount = (): void => { backgroundMitt.emit('window-active', true); // handle win nav-bar event. ipcMain.removeHandler('nav-bar'); // avoid setting duplicate handlers ipcMain.handle('nav-bar', navBarHandler); + + ipcMain.removeHandler('window-save'); // avoid setting duplicate handlers + ipcMain.handle('window-save', onWindowSave); // render messages through ipc-renderer. backgroundMitt.on('ipc-renderer', renderMessage); } @@ -57,16 +68,20 @@ const windowDismount = (): void => { } // function used by run.ts to create the main window. -export async function createWindow(options: WindowSettings): Promise { +export async function createWindow(): Promise { return new Promise((resolve, _reject) => { // avoid creating duplicate windows. if (win) resolve(); + // read windowState from json. + const rawData = fs.readFileSync('windowState.json'); + const windowState = JSON.parse(rawData); + win = new BrowserWindow({ - width: options.width, - height: options.height, - resizable: options.resizable, + width: windowState.w, + height: windowState.h, + resizable: true, backgroundColor: '#EBEBEB', frame: false, minWidth: 350, diff --git a/src/types/animejs/index.ts b/src/types/animejs/index.ts deleted file mode 100644 index 9a2c0e7..0000000 --- a/src/types/animejs/index.ts +++ /dev/null @@ -1,18 +0,0 @@ - -interface AnimeFuncParams { - targets: Element | HTMLElement | SVGGElement | SVGElement; - translateY?: number; - translateX?: number | any[] | undefined; - transform?: string; - easing?: string; - duration?: number; - offset?: number; - begin?: () => void; - complete?: () => void; - stroke?: string; - opacity?: number; -} - -export default interface AnimeFunc { - (params: AnimeFuncParams): void | undefined; -} diff --git a/src/types/vue3/vueTransitionCallback/index.ts b/src/types/vue3/vueTransitionCallback/index.ts deleted file mode 100644 index 8c631d4..0000000 --- a/src/types/vue3/vueTransitionCallback/index.ts +++ /dev/null @@ -1,3 +0,0 @@ -export type VueTransitionCallback = { - (el?: SVGGElement | null): void; -} diff --git a/src/types/vueRef/index.ts b/src/types/vueRef/index.ts deleted file mode 100644 index 0acebab..0000000 --- a/src/types/vueRef/index.ts +++ /dev/null @@ -1,3 +0,0 @@ -export interface Ref { - value: A; -} \ No newline at end of file diff --git a/windowState.json b/windowState.json new file mode 100644 index 0000000..d637d9e --- /dev/null +++ b/windowState.json @@ -0,0 +1 @@ +{"w":352,"h":500} \ No newline at end of file