Skip to content

Commit

Permalink
Consolidate fullscreen APIs (#125)
Browse files Browse the repository at this point in the history
  • Loading branch information
sergeichestakov authored Sep 7, 2023
1 parent 16a279e commit 627c4b1
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 16 deletions.
4 changes: 2 additions & 2 deletions src/createWindow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -214,11 +214,11 @@ export function createWindow(props?: WindowProps): BrowserWindow {
});

window.on('enter-full-screen', () => {
window.webContents.send(events.ON_ENTER_FULLSCREEN);
window.webContents.send(events.ON_FULLSCREEN_CHANGED, true);
});

window.on('leave-full-screen', () => {
window.webContents.send(events.ON_LEAVE_FULLSCREEN);
window.webContents.send(events.ON_FULLSCREEN_CHANGED, false);
});

// Bypass the browser's cache when initially loading the remote URL
Expand Down
3 changes: 1 addition & 2 deletions src/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ export enum events {
LOGOUT = 'LOGOUT',
SHOW_MESSAGE_BOX = 'SHOW_MESSAGE_BOX',
CHECK_FOR_UPDATES = 'CHECK_FOR_UPDATES',
ON_ENTER_FULLSCREEN = 'ON_ENTER_FULLSCREEN',
ON_LEAVE_FULLSCREEN = 'ON_LEAVE_FULLSCREEN',
ON_FULLSCREEN_CHANGED = 'ON_FULLSCREEN_CHANGED',
THEME_VALUES_CHANGED = 'THEME_VALUES_CHANGED',
}
24 changes: 12 additions & 12 deletions src/preload.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,6 @@
import { contextBridge, ipcRenderer, IpcRendererEvent } from 'electron';
import { events } from './events';

function makeEventHandler(event: events) {
return function (callback: () => void) {
ipcRenderer.on(event, callback);

return () => {
ipcRenderer.removeListener(event, callback);
};
};
}

function parseArgument(name: string) {
// Must be passed in as an entry to the `additionalArguments` array in `webPreferences`
const arg = process.argv.find((a) => a.includes(`--${name}=`));
Expand Down Expand Up @@ -45,8 +35,18 @@ contextBridge.exposeInMainWorld('replitDesktop', {
},
showMessageBox: async (params: Electron.MessageBoxOptions) =>
ipcRenderer.invoke(events.SHOW_MESSAGE_BOX, params),
onEnterFullscreen: makeEventHandler(events.ON_ENTER_FULLSCREEN),
onLeaveFullscreen: makeEventHandler(events.ON_LEAVE_FULLSCREEN),

onFullScreenChanged: (callback: (isFullScreen: boolean) => void) => {
function listener(_event: IpcRendererEvent, isFullScreen: boolean) {
callback(isFullScreen);
}

ipcRenderer.on(events.ON_FULLSCREEN_CHANGED, listener);

return () => {
ipcRenderer.removeListener(events.ON_FULLSCREEN_CHANGED, listener);
};
},
updateThemeValues: (themeValues: {
backgroundRoot: string;
foregroundDefault: string;
Expand Down

0 comments on commit 627c4b1

Please sign in to comment.