Call BrowserWindow.isMaximized and related events from renderer
This commit is contained in:
parent
e63cff7a52
commit
b84d57d1d2
4 changed files with 29 additions and 1 deletions
|
@ -93,6 +93,8 @@ handle(IpcEvents.MAXIMIZE, e => {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
handleSync(IpcEvents.IS_MAXIMIZED, () => mainWin.isMaximized());
|
||||||
|
|
||||||
handle(IpcEvents.SPELLCHECK_SET_LANGUAGES, (_, languages: string[]) => {
|
handle(IpcEvents.SPELLCHECK_SET_LANGUAGES, (_, languages: string[]) => {
|
||||||
const ses = session.defaultSession;
|
const ses = session.defaultSession;
|
||||||
|
|
||||||
|
|
|
@ -359,6 +359,14 @@ function initSpellCheck(win: BrowserWindow) {
|
||||||
win.webContents.send(IpcEvents.SPELLCHECK_RESULT, data.misspelledWord, data.dictionarySuggestions);
|
win.webContents.send(IpcEvents.SPELLCHECK_RESULT, data.misspelledWord, data.dictionarySuggestions);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
function initMaximizedHook(win: BrowserWindow) {
|
||||||
|
win.on("maximize", () => {
|
||||||
|
win.webContents.send(IpcEvents.MAXIMIZED, true);
|
||||||
|
});
|
||||||
|
win.on("unmaximize", () => {
|
||||||
|
win.webContents.send(IpcEvents.MAXIMIZED, false);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
function createMainWindow() {
|
function createMainWindow() {
|
||||||
// Clear up previous settings listeners
|
// Clear up previous settings listeners
|
||||||
|
@ -425,6 +433,7 @@ function createMainWindow() {
|
||||||
makeLinksOpenExternally(win);
|
makeLinksOpenExternally(win);
|
||||||
initSettingsListeners(win);
|
initSettingsListeners(win);
|
||||||
initSpellCheck(win);
|
initSpellCheck(win);
|
||||||
|
initMaximizedHook(win);
|
||||||
|
|
||||||
win.webContents.setUserAgent(UserAgent);
|
win.webContents.setUserAgent(UserAgent);
|
||||||
|
|
||||||
|
|
|
@ -19,6 +19,14 @@ ipcRenderer.on(IpcEvents.SPELLCHECK_RESULT, (_, w: string, s: string[]) => {
|
||||||
spellCheckCallbacks.forEach(cb => cb(w, s));
|
spellCheckCallbacks.forEach(cb => cb(w, s));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
type MaximizedCallback = (isMaximized: boolean) => void;
|
||||||
|
|
||||||
|
const maximizedCallbacks = new Set<MaximizedCallback>();
|
||||||
|
|
||||||
|
ipcRenderer.on(IpcEvents.MAXIMIZED, (_, v: boolean) => {
|
||||||
|
maximizedCallbacks.forEach(cb => cb(v));
|
||||||
|
});
|
||||||
|
|
||||||
export const VesktopNative = {
|
export const VesktopNative = {
|
||||||
app: {
|
app: {
|
||||||
relaunch: () => invoke<void>(IpcEvents.RELAUNCH),
|
relaunch: () => invoke<void>(IpcEvents.RELAUNCH),
|
||||||
|
@ -54,7 +62,14 @@ export const VesktopNative = {
|
||||||
focus: () => invoke<void>(IpcEvents.FOCUS),
|
focus: () => invoke<void>(IpcEvents.FOCUS),
|
||||||
close: (key?: string) => invoke<void>(IpcEvents.CLOSE, key),
|
close: (key?: string) => invoke<void>(IpcEvents.CLOSE, key),
|
||||||
minimize: () => invoke<void>(IpcEvents.MINIMIZE),
|
minimize: () => invoke<void>(IpcEvents.MINIMIZE),
|
||||||
maximize: () => invoke<void>(IpcEvents.MAXIMIZE)
|
maximize: () => invoke<void>(IpcEvents.MAXIMIZE),
|
||||||
|
isMaximized: () => sendSync<boolean>(IpcEvents.IS_MAXIMIZED),
|
||||||
|
onMaximized(cb: MaximizedCallback) {
|
||||||
|
maximizedCallbacks.add(cb);
|
||||||
|
},
|
||||||
|
offMaximized(cb: MaximizedCallback) {
|
||||||
|
maximizedCallbacks.delete(cb);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
capturer: {
|
capturer: {
|
||||||
getLargeThumbnail: (id: string) => invoke<string>(IpcEvents.CAPTURER_GET_LARGE_THUMBNAIL, id)
|
getLargeThumbnail: (id: string) => invoke<string>(IpcEvents.CAPTURER_GET_LARGE_THUMBNAIL, id)
|
||||||
|
|
|
@ -18,6 +18,8 @@ export const enum IpcEvents {
|
||||||
FOCUS = "VCD_FOCUS",
|
FOCUS = "VCD_FOCUS",
|
||||||
MINIMIZE = "VCD_MINIMIZE",
|
MINIMIZE = "VCD_MINIMIZE",
|
||||||
MAXIMIZE = "VCD_MAXIMIZE",
|
MAXIMIZE = "VCD_MAXIMIZE",
|
||||||
|
IS_MAXIMIZED = "VCD_IS_MAXIMIZED",
|
||||||
|
MAXIMIZED = "VCD_MAXIMIZED",
|
||||||
|
|
||||||
SHOW_ITEM_IN_FOLDER = "VCD_SHOW_ITEM_IN_FOLDER",
|
SHOW_ITEM_IN_FOLDER = "VCD_SHOW_ITEM_IN_FOLDER",
|
||||||
GET_SETTINGS = "VCD_GET_SETTINGS",
|
GET_SETTINGS = "VCD_GET_SETTINGS",
|
||||||
|
|
Reference in a new issue