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.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; diff --git a/src/helpers.ts b/src/helpers.ts index 33e3ae0..46bfe4c 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' +} 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 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