From 7f389d10ecd52bf3664ddc8a3cc8c0f35ae3c732 Mon Sep 17 00:00:00 2001 From: FileX <79639219+cd-FileX@users.noreply.github.com> Date: Tue, 27 Jun 2023 17:40:36 +0200 Subject: [PATCH 1/6] Added isMaximized? option --- lib/helpers.d.ts | 1 + lib/helpers.js | 3 ++- lib/index.d.ts | 2 +- lib/index.js | 11 +++++++++++ lib/types.d.ts | 4 ++++ 5 files changed, 19 insertions(+), 2 deletions(-) diff --git a/lib/helpers.d.ts b/lib/helpers.d.ts index 6e7caca..3f63488 100644 --- a/lib/helpers.d.ts +++ b/lib/helpers.d.ts @@ -2,4 +2,5 @@ export declare const ipc: { MINIMIZE: string; TOGGLE_MAXIMIZE: string; CLOSE: string; + MAXIMIZED: string; }; diff --git a/lib/helpers.js b/lib/helpers.js index 33eb9d7..6216d04 100644 --- a/lib/helpers.js +++ b/lib/helpers.js @@ -4,5 +4,6 @@ exports.ipc = void 0; exports.ipc = { MINIMIZE: 'WINDOW_MINIMIZE', TOGGLE_MAXIMIZE: 'WINDOW_TOGGLE_MAXIMIZE', - CLOSE: 'WINDOW_CLOSE' + CLOSE: 'WINDOW_CLOSE', + MAXIMIZED: 'WINDOW_MAXIMIZED' }; diff --git a/lib/index.d.ts b/lib/index.d.ts index 897a08a..6a63b33 100644 --- a/lib/index.d.ts +++ b/lib/index.d.ts @@ -1,4 +1,4 @@ -import { Options, FinalOptions, WindowMethods } from './types'; +import { Options, FinalOptions, WindowMethods } from 'electron-window-controls/lib/types'; /** * Control your Electron Browser Window securely from the renderer. * @example diff --git a/lib/index.js b/lib/index.js index 46f64d0..6114096 100644 --- a/lib/index.js +++ b/lib/index.js @@ -20,6 +20,8 @@ var helpers_1 = require("./helpers"); BrowserWindow.toggleMaximize() BrowserWindow.close() + + BrowserWindow.isMaximized() ``` */ var ElectronWindowControls = /** @class */ (function () { @@ -60,6 +62,12 @@ var ElectronWindowControls = /** @class */ (function () { throw new Error('[electron-window-controls] No window found'); win.close(); }); + electron_1.ipcMain.on(helpers_1.ipc.MAXIMIZED, function (event) { + var win = electron_1.BrowserWindow.fromWebContents(event.sender); + if (!win) + throw new Error('[electron-window-controls] No window found'); + event.returnValue = win.isMaximized(); + }); }; /** * Initialize the Electron main process. @@ -97,6 +105,9 @@ var ElectronWindowControls = /** @class */ (function () { }, toggleMaximize: function () { electron_1.ipcRenderer.send(helpers_1.ipc.TOGGLE_MAXIMIZE); + }, + isMaximized: function() { + return electron_1.ipcRenderer.sendSync(helpers_1.ipc.MAXIMIZED); } }; }; diff --git a/lib/types.d.ts b/lib/types.d.ts index 20103b0..23d7902 100644 --- a/lib/types.d.ts +++ b/lib/types.d.ts @@ -23,5 +23,9 @@ export interface WindowMethods { * Toggle the maximized state of the window */ toggleMaximize: () => void; + /** + * Returns the maximization state of the window + */ + isMaximized: () => boolean; } export declare type FinalOptions = SetRequired; From a7b210d238192acca78270bcda9a725da03d2290 Mon Sep 17 00:00:00 2001 From: FileX <79639219+cd-FileX@users.noreply.github.com> Date: Tue, 27 Jun 2023 17:43:43 +0200 Subject: [PATCH 2/6] Added maximized channel --- src/helpers.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/helpers.ts b/src/helpers.ts index 33e3ae0..d51b0a4 100644 --- a/src/helpers.ts +++ b/src/helpers.ts @@ -1,5 +1,6 @@ export const ipc = { MINIMIZE: 'WINDOW_MINIMIZE', TOGGLE_MAXIMIZE: 'WINDOW_TOGGLE_MAXIMIZE', - CLOSE: 'WINDOW_CLOSE' -} \ No newline at end of file + CLOSE: 'WINDOW_CLOSE', + MAXIMIZED: 'WINDOW_MAXIMIZED' +} From 1b275d6879d985fceff678e7350871e7b0847b7c Mon Sep 17 00:00:00 2001 From: FileX <79639219+cd-FileX@users.noreply.github.com> Date: Tue, 27 Jun 2023 17:44:36 +0200 Subject: [PATCH 3/6] Updated formatting --- src/helpers.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/helpers.ts b/src/helpers.ts index d51b0a4..46bfe4c 100644 --- a/src/helpers.ts +++ b/src/helpers.ts @@ -2,5 +2,5 @@ export const ipc = { MINIMIZE: 'WINDOW_MINIMIZE', TOGGLE_MAXIMIZE: 'WINDOW_TOGGLE_MAXIMIZE', CLOSE: 'WINDOW_CLOSE', - MAXIMIZED: 'WINDOW_MAXIMIZED' + MAXIMIZED: 'WINDOW_MAXIMIZED' } From a19e0cac6c80cd0614394a1d15ee0b7a35ab915e Mon Sep 17 00:00:00 2001 From: FileX <79639219+cd-FileX@users.noreply.github.com> Date: Tue, 27 Jun 2023 17:52:09 +0200 Subject: [PATCH 4/6] Added isMaximized --- src/index.ts | 33 ++++++++++++++++++++++----------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/src/index.ts b/src/index.ts index 5607a93..443d6dd 100644 --- a/src/index.ts +++ b/src/index.ts @@ -6,21 +6,23 @@ import { Options, FinalOptions, WindowMethods } from './types' /** * Control your Electron Browser Window securely from the renderer. * @example - ``` - // Main process - import WindowControls from 'electron-window-controls' + ``` + // Main process + import WindowControls from 'electron-window-controls' - WindowControls.initMain() + WindowControls.initMain() - // Renderer process - import { BrowserWindow } from 'electron-window-controls' + // Renderer process + import { BrowserWindow } from 'electron-window-controls' - BrowserWindow.minimize() + BrowserWindow.minimize() - BrowserWindow.toggleMaximize() + BrowserWindow.toggleMaximize() - BrowserWindow.close() - ``` + BrowserWindow.close() + + BrowserWindow.isMaximized() + ``` */ class ElectronWindowControls { @@ -66,6 +68,12 @@ class ElectronWindowControls { win.close() }) + + ipcMain.on(ipc.MAXIMIZED, (event) => { + var win = ElectronBrowserWindow.fromWebContents(event.sender); + if (!win) throw new Error('[electron-window-controls] No window found'); + event.returnValue = win.isMaximized(); + }); } /** @@ -106,6 +114,9 @@ class ElectronWindowControls { }, toggleMaximize: () => { ipcRenderer.send(ipc.TOGGLE_MAXIMIZE) + }, + isMaximized: () => { + return ipcRenderer.sendSync(ipc.MAXIMIZED); } } } @@ -116,4 +127,4 @@ class ElectronWindowControls { */ export const BrowserWindow = ElectronWindowControls.initRenderer() -export default ElectronWindowControls \ No newline at end of file +export default ElectronWindowControls From 11401b628b14c30c9082c90931f361e15821be71 Mon Sep 17 00:00:00 2001 From: FileX <79639219+cd-FileX@users.noreply.github.com> Date: Tue, 27 Jun 2023 17:53:51 +0200 Subject: [PATCH 5/6] Inserted isMaximized --- src/types.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/types.ts b/src/types.ts index bca0814..f005872 100644 --- a/src/types.ts +++ b/src/types.ts @@ -28,6 +28,10 @@ export interface WindowMethods { * Toggle the maximized state of the window */ toggleMaximize: () => void + /** + * Returns the maximization state of the window + */ + isMaximized: () => boolean } -export type FinalOptions = SetRequired \ No newline at end of file +export type FinalOptions = SetRequired From d3618e92016f25c50ca68eab9d073cb78ba73ae9 Mon Sep 17 00:00:00 2001 From: FileX <79639219+cd-FileX@users.noreply.github.com> Date: Tue, 27 Jun 2023 17:57:29 +0200 Subject: [PATCH 6/6] Reversed import update --- lib/index.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/index.d.ts b/lib/index.d.ts index 6a63b33..897a08a 100644 --- a/lib/index.d.ts +++ b/lib/index.d.ts @@ -1,4 +1,4 @@ -import { Options, FinalOptions, WindowMethods } from 'electron-window-controls/lib/types'; +import { Options, FinalOptions, WindowMethods } from './types'; /** * Control your Electron Browser Window securely from the renderer. * @example