Merge remote-tracking branch 'origin/main' into main
Writing something here because it's forcing me to.
This commit is contained in:
commit
1d9f2e0eb6
7 changed files with 33 additions and 40 deletions
|
|
@ -48,11 +48,16 @@ export default defineComponent({
|
||||||
window.ipcRenderer.removeAllListeners('window-ready')
|
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.
|
// save messages before closing.
|
||||||
if (action === 'close') {
|
if (action === 'close') {
|
||||||
saveMessages();
|
saveMessages();
|
||||||
|
await saveWindowState();
|
||||||
}
|
}
|
||||||
|
|
||||||
invoke('nav-bar', action);
|
invoke('nav-bar', action);
|
||||||
|
|
|
||||||
|
|
@ -12,11 +12,7 @@ let socket = false;
|
||||||
export async function main() {
|
export async function main() {
|
||||||
|
|
||||||
// create main window.
|
// create main window.
|
||||||
await createWindow({
|
await createWindow();
|
||||||
width: 600,
|
|
||||||
height: 500,
|
|
||||||
resizable: true
|
|
||||||
});
|
|
||||||
|
|
||||||
// Instantiate socket session with crimata-platorm.
|
// Instantiate socket session with crimata-platorm.
|
||||||
if (!socket) initSession();
|
if (!socket) initSession();
|
||||||
|
|
|
||||||
|
|
@ -5,12 +5,7 @@ import { createProtocol } from "vue-cli-plugin-electron-builder/lib";
|
||||||
import { backgroundMitt } from './emitter';
|
import { backgroundMitt } from './emitter';
|
||||||
import { RenderMessage } from "@/types/message/index";
|
import { RenderMessage } from "@/types/message/index";
|
||||||
import * as path from "path";
|
import * as path from "path";
|
||||||
|
import fs from 'fs';
|
||||||
interface WindowSettings {
|
|
||||||
width: number;
|
|
||||||
height: number;
|
|
||||||
resizable: boolean;
|
|
||||||
}
|
|
||||||
|
|
||||||
interface IpcRendererPayload {
|
interface IpcRendererPayload {
|
||||||
endpoint: string;
|
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.
|
// Do this on window mount.
|
||||||
const windowMount = (): void => {
|
const windowMount = (): void => {
|
||||||
backgroundMitt.emit('window-active', true);
|
backgroundMitt.emit('window-active', true);
|
||||||
// handle win nav-bar event.
|
// handle win nav-bar event.
|
||||||
ipcMain.removeHandler('nav-bar'); // avoid setting duplicate handlers
|
ipcMain.removeHandler('nav-bar'); // avoid setting duplicate handlers
|
||||||
ipcMain.handle('nav-bar', navBarHandler);
|
ipcMain.handle('nav-bar', navBarHandler);
|
||||||
|
|
||||||
|
ipcMain.removeHandler('window-save'); // avoid setting duplicate handlers
|
||||||
|
ipcMain.handle('window-save', onWindowSave);
|
||||||
// render messages through ipc-renderer.
|
// render messages through ipc-renderer.
|
||||||
backgroundMitt.on('ipc-renderer', renderMessage);
|
backgroundMitt.on('ipc-renderer', renderMessage);
|
||||||
}
|
}
|
||||||
|
|
@ -57,16 +68,20 @@ const windowDismount = (): void => {
|
||||||
}
|
}
|
||||||
|
|
||||||
// function used by run.ts to create the main window.
|
// function used by run.ts to create the main window.
|
||||||
export async function createWindow(options: WindowSettings): Promise<void> {
|
export async function createWindow(): Promise<void> {
|
||||||
return new Promise((resolve, _reject) => {
|
return new Promise((resolve, _reject) => {
|
||||||
|
|
||||||
// avoid creating duplicate windows.
|
// avoid creating duplicate windows.
|
||||||
if (win) resolve();
|
if (win) resolve();
|
||||||
|
|
||||||
|
// read windowState from json.
|
||||||
|
const rawData = fs.readFileSync('windowState.json');
|
||||||
|
const windowState = JSON.parse(rawData);
|
||||||
|
|
||||||
win = new BrowserWindow({
|
win = new BrowserWindow({
|
||||||
width: options.width,
|
width: windowState.w,
|
||||||
height: options.height,
|
height: windowState.h,
|
||||||
resizable: options.resizable,
|
resizable: true,
|
||||||
backgroundColor: '#EBEBEB',
|
backgroundColor: '#EBEBEB',
|
||||||
frame: false,
|
frame: false,
|
||||||
minWidth: 350,
|
minWidth: 350,
|
||||||
|
|
|
||||||
|
|
@ -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;
|
|
||||||
}
|
|
||||||
|
|
@ -1,3 +0,0 @@
|
||||||
export type VueTransitionCallback = {
|
|
||||||
(el?: SVGGElement | null): void;
|
|
||||||
}
|
|
||||||
|
|
@ -1,3 +0,0 @@
|
||||||
export interface Ref<A> {
|
|
||||||
value: A;
|
|
||||||
}
|
|
||||||
1
windowState.json
Normal file
1
windowState.json
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
{"w":352,"h":500}
|
||||||
Loading…
Reference in a new issue