feat: persist and restore window size and position (#74)
Finished up saving and restoring of window position and size Signed-off-by: Jespercal <chap600@hotmail.com>
This commit is contained in:
Vendored
+4
@@ -6,6 +6,10 @@ declare type DesktopConfig = {
|
|||||||
hardwareAcceleration: boolean;
|
hardwareAcceleration: boolean;
|
||||||
discordRpc: boolean;
|
discordRpc: boolean;
|
||||||
windowState: {
|
windowState: {
|
||||||
|
x: number;
|
||||||
|
y: number;
|
||||||
|
width: number;
|
||||||
|
height: number;
|
||||||
isMaximised: boolean;
|
isMaximised: boolean;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|||||||
+16
-12
@@ -28,18 +28,18 @@ const schema = {
|
|||||||
windowState: {
|
windowState: {
|
||||||
type: "object",
|
type: "object",
|
||||||
properties: {
|
properties: {
|
||||||
// x: {
|
x: {
|
||||||
// type: 'number'
|
type: 'number'
|
||||||
// } as JSONSchema.Number,
|
} as JSONSchema.Number,
|
||||||
// y: {
|
y: {
|
||||||
// type: 'number'
|
type: 'number'
|
||||||
// } as JSONSchema.Number,
|
} as JSONSchema.Number,
|
||||||
// width: {
|
width: {
|
||||||
// type: 'number'
|
type: 'number'
|
||||||
// } as JSONSchema.Number,
|
} as JSONSchema.Number,
|
||||||
// height: {
|
height: {
|
||||||
// type: 'number'
|
type: 'number'
|
||||||
// } as JSONSchema.Number,
|
} as JSONSchema.Number,
|
||||||
isMaximised: {
|
isMaximised: {
|
||||||
type: "boolean",
|
type: "boolean",
|
||||||
} as JSONSchema.Boolean,
|
} as JSONSchema.Boolean,
|
||||||
@@ -57,6 +57,10 @@ const store = new Store({
|
|||||||
hardwareAcceleration: true,
|
hardwareAcceleration: true,
|
||||||
discordRpc: true,
|
discordRpc: true,
|
||||||
windowState: {
|
windowState: {
|
||||||
|
x: 0,
|
||||||
|
y: 0,
|
||||||
|
width: 0,
|
||||||
|
height: 0,
|
||||||
isMaximised: false,
|
isMaximised: false,
|
||||||
},
|
},
|
||||||
} as DesktopConfig,
|
} as DesktopConfig,
|
||||||
|
|||||||
@@ -62,6 +62,16 @@ export function createMainWindow() {
|
|||||||
mainWindow.maximize();
|
mainWindow.maximize();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// restore last position if it was moved previously
|
||||||
|
if(config.windowState.x > 0 || config.windowState.y > 0) {
|
||||||
|
mainWindow.setPosition(config.windowState.x ?? 0, config.windowState.y ?? 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
// restore last size if it was resized previously
|
||||||
|
if(config.windowState.width > 0 && config.windowState.height > 0) {
|
||||||
|
mainWindow.setSize(config.windowState.width ?? 1280, config.windowState.height ?? 720);
|
||||||
|
}
|
||||||
|
|
||||||
// load the entrypoint
|
// load the entrypoint
|
||||||
mainWindow.loadURL(BUILD_URL.toString());
|
mainWindow.loadURL(BUILD_URL.toString());
|
||||||
|
|
||||||
@@ -80,12 +90,18 @@ export function createMainWindow() {
|
|||||||
// keep track of window state
|
// keep track of window state
|
||||||
function generateState() {
|
function generateState() {
|
||||||
config.windowState = {
|
config.windowState = {
|
||||||
|
x: mainWindow.getPosition()[0],
|
||||||
|
y: mainWindow.getPosition()[1],
|
||||||
|
width: mainWindow.getSize()[0],
|
||||||
|
height: mainWindow.getSize()[1],
|
||||||
isMaximised: mainWindow.isMaximized(),
|
isMaximised: mainWindow.isMaximized(),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
mainWindow.on("maximize", generateState);
|
mainWindow.on("maximize", generateState);
|
||||||
mainWindow.on("unmaximize", generateState);
|
mainWindow.on("unmaximize", generateState);
|
||||||
|
mainWindow.on("moved", generateState);
|
||||||
|
mainWindow.on("resized", generateState);
|
||||||
|
|
||||||
// rebind zoom controls to be more sensible
|
// rebind zoom controls to be more sensible
|
||||||
mainWindow.webContents.on("before-input-event", (event, input) => {
|
mainWindow.webContents.on("before-input-event", (event, input) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user