Skip to content

Commit

Permalink
Expose Desktop API in Calls popout window (#3258)
Browse files Browse the repository at this point in the history
  • Loading branch information
streamer45 authored Jan 20, 2025
1 parent a0ac399 commit 34932df
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 1 deletion.
1 change: 1 addition & 0 deletions i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@
"main.menus.app.view.developerModeDisableUserActivityMonitor": "Disable User Activity Monitor",
"main.menus.app.view.devToolsAppWrapper": "Developer Tools for Application Wrapper",
"main.menus.app.view.devToolsCurrentCallWidget": "Developer Tools for Call Widget",
"main.menus.app.view.devToolsCurrentCallWidgetPopout": "Developer Tools for Call Widget Popout",
"main.menus.app.view.devToolsCurrentServer": "Developer Tools for Current Server",
"main.menus.app.view.devToolsSubMenu": "Developer Tools",
"main.menus.app.view.downloads": "Downloads",
Expand Down
16 changes: 16 additions & 0 deletions src/main/menus/app.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,7 @@ describe('main/menus/app', () => {

it('should show menu item if widget window is open', () => {
CallsWidgetWindow.isOpen = jest.fn(() => true);
CallsWidgetWindow.isPopoutOpen = jest.fn(() => false);
const menu = createTemplate(config);

const appMenu = menu.find((item) => item.label === 'main.menus.app.view');
Expand All @@ -371,4 +372,19 @@ describe('main/menus/app', () => {
const menuItem = devToolsSubMenu.submenu.find((item) => item.label === 'main.menus.app.view.devToolsCurrentCallWidget');
expect(menuItem).not.toBe(undefined);
});

it('should show additional menu item if widget popout is open', () => {
CallsWidgetWindow.isOpen = jest.fn(() => true);
CallsWidgetWindow.isPopoutOpen = jest.fn(() => true);
const menu = createTemplate(config);

const appMenu = menu.find((item) => item.label === 'main.menus.app.view');
expect(appMenu).not.toBe(undefined);

const devToolsSubMenu = appMenu.submenu.find((item) => item.label === 'main.menus.app.view.devToolsSubMenu');
expect(devToolsSubMenu).not.toBe(undefined);

const menuItem = devToolsSubMenu.submenu.find((item) => item.label === 'main.menus.app.view.devToolsCurrentCallWidgetPopout');
expect(menuItem).not.toBe(undefined);
});
});
9 changes: 9 additions & 0 deletions src/main/menus/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,15 @@ export function createTemplate(config: Config, updateManager: UpdateManager) {
CallsWidgetWindow.openDevTools();
},
});

if (CallsWidgetWindow.isPopoutOpen()) {
devToolsSubMenu.push({
label: localizeMessage('main.menus.app.view.devToolsCurrentCallWidgetPopout', 'Developer Tools for Call Widget Popout'),
click() {
CallsWidgetWindow.openPopoutDevTools();
},
});
}
}

if (DeveloperMode.enabled()) {
Expand Down
8 changes: 7 additions & 1 deletion src/main/windows/callsWidgetWindow.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ jest.mock('main/views/viewManager', () => ({
jest.mock('../utils', () => ({
openScreensharePermissionsSettingsMacOS: jest.fn(),
resetScreensharePermissionsMacOS: jest.fn(),
getLocalPreload: jest.fn(),
getLocalPreload: jest.fn((file) => file),
composeUserAgent: jest.fn(),
}));

Expand Down Expand Up @@ -369,6 +369,12 @@ describe('main/windows/callsWidgetWindow', () => {
urlUtils.isCallsPopOutURL.mockReturnValue(false);
expect(callsWidgetWindow.onPopOutOpen({url: 'http://localhost:8065/notpopouturl'})).toHaveProperty('action', 'deny');
});

it('should pop out and make sure preload is set', () => {
urlUtils.isCallsPopOutURL.mockReturnValue(true);
expect(callsWidgetWindow.onPopOutOpen({url: 'http://localhost:8065/popouturl'})).toHaveProperty('action', 'allow');
expect(callsWidgetWindow.onPopOutOpen({url: 'http://localhost:8065/popouturl'})).toHaveProperty('overrideBrowserWindowOptions.webPreferences.preload', 'externalAPI.js');
});
});

describe('handlePopOutFocus', () => {
Expand Down
15 changes: 15 additions & 0 deletions src/main/windows/callsWidgetWindow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,10 @@ export class CallsWidgetWindow {
return Boolean(this.win && !this.win.isDestroyed());
}

public isPopoutOpen() {
return Boolean(this.popOut && !this.popOut.isDestroyed());
}

/**
* Helper functions
*/
Expand All @@ -105,6 +109,10 @@ export class CallsWidgetWindow {
this.win?.webContents.openDevTools({mode: 'detach'});
};

public openPopoutDevTools = () => {
this.popOut?.webContents.openDevTools({mode: 'detach'});
};

getViewURL = () => {
return this.mainView?.view.server.url;
};
Expand Down Expand Up @@ -292,6 +300,9 @@ export class CallsWidgetWindow {
action: 'allow' as const,
overrideBrowserWindowOptions: {
autoHideMenuBar: true,
webPreferences: {
preload: getLocalPreload('externalAPI.js'),
},
},
};
}
Expand All @@ -318,7 +329,11 @@ export class CallsWidgetWindow {
const contextMenu = new ContextMenu({}, this.popOut);
contextMenu.reload();

// Update menu to show the developer tools option for this window.
ipcMain.emit(UPDATE_SHORTCUT_MENU);

this.popOut.on('closed', () => {
ipcMain.emit(UPDATE_SHORTCUT_MENU);
delete this.popOut;
contextMenu.dispose();
this.setWidgetWindowStacking({onTop: true});
Expand Down

0 comments on commit 34932df

Please sign in to comment.