mirror of
https://github.com/finos/SymphonyElectron.git
synced 2026-10-25 14:20:04 -05:00
SDA-4844 - SDA-4843 - SDA-4842 - Fix windows shortcut & fix fullscreen & maximize state (#2325)
* SDA-4844 - SDA-4843 - SDA-4842 - Fix windows shortcut & fix fullscreen & maximize state * SDA-4844 - SDA-4843 - SDA-4842 - Fix windows shortcut & fix fullscreen & maximize state
This commit is contained in:
1 parent
b232c3405a
commit
cfc88885c5
6 files changed
+89
-31
No files matched your search
@@ -351,9 +351,6 @@ describe('app menu', () => {
|
||||
const menuItem = findMenuItemBuildWindowMenu('Mini View');
|
||||
await menuItem.click(item);
|
||||
expect(activateMiniView).toHaveBeenCalled();
|
||||
expect(windowHandler.setIsMiniViewTransition).toHaveBeenCalledWith(
|
||||
true,
|
||||
);
|
||||
});
|
||||
|
||||
it('should deactivate mini view when "Exit Mini View" is clicked', async () => {
|
||||
@@ -367,9 +364,6 @@ describe('app menu', () => {
|
||||
const menuItem = findMenuItemBuildWindowMenu('Exit Mini View');
|
||||
await menuItem.click(item);
|
||||
expect(deactivateMiniView).toHaveBeenCalled();
|
||||
expect(windowHandler.setIsMiniViewTransition).toHaveBeenCalledWith(
|
||||
true,
|
||||
);
|
||||
});
|
||||
|
||||
it('should not show mini view options when feature is disabled', () => {
|
||||
|
||||
+1
-5
@@ -428,14 +428,12 @@ export class AppMenu {
|
||||
: isWindowsOS || isLinux
|
||||
? windowsAccelerator.miniView
|
||||
: '';
|
||||
const mainWindow = windowHandler.getMainWindow();
|
||||
|
||||
const submenu: MenuItemConstructorOptions[] = [
|
||||
this.assignRoleOrLabel({ role: 'minimize', label: i18n.t('Minimize')() }),
|
||||
this.assignRoleOrLabel({ role: 'close', label: i18n.t('Close')() }),
|
||||
{
|
||||
click: async () => {
|
||||
windowHandler.setIsMiniViewTransition(true);
|
||||
if (windowHandler.getIsMiniViewEnabled()) {
|
||||
deactivateMiniView();
|
||||
} else {
|
||||
@@ -447,9 +445,7 @@ export class AppMenu {
|
||||
? i18n.t('Exit Mini View')()
|
||||
: i18n.t('Mini View')(),
|
||||
type: 'normal',
|
||||
visible:
|
||||
windowHandler.getIsMiniViewFeatureEnabled() &&
|
||||
!mainWindow?.isFullScreen(),
|
||||
visible: windowHandler.getIsMiniViewFeatureEnabled(),
|
||||
},
|
||||
this.buildSeparator(),
|
||||
{
|
||||
|
||||
+11
-20
@@ -43,6 +43,7 @@ import {
|
||||
activateMiniView,
|
||||
deactivateMiniView,
|
||||
handleKeyPress,
|
||||
unMaximizeMainWindow,
|
||||
} from './window-actions';
|
||||
import { ICustomBrowserWindow, windowHandler } from './window-handler';
|
||||
import {
|
||||
@@ -384,6 +385,9 @@ ipcMain.on(
|
||||
main?.setThumbarButtons([]);
|
||||
presenceStatus.onSignOut();
|
||||
await appStats.sendAnalytics(SDAUserSessionActionTypes.Logout);
|
||||
// reset mini view state
|
||||
windowHandler.setIsMiniViewFeatureEnabled(false);
|
||||
windowHandler.setIsMiniViewEnabled(false);
|
||||
break;
|
||||
case apiCmds.setZoomLevel:
|
||||
if (typeof arg.zoomLevel === 'number') {
|
||||
@@ -433,25 +437,16 @@ ipcMain.on(
|
||||
// Give focus back to main webContents
|
||||
if (mainWebContents && !mainWebContents.isDestroyed()) {
|
||||
mainWebContents.focus();
|
||||
if (
|
||||
windowHandler.getIsMiniViewFeatureEnabled() &&
|
||||
windowHandler.getIsMiniViewEnabled()
|
||||
) {
|
||||
mainWebContents.send('set-mini-view', false);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case apiCmds.unmaximizeMainWindow:
|
||||
const mainWindow =
|
||||
windowHandler.getMainWindow() as ICustomBrowserWindow;
|
||||
if (mainWindow && windowExists(mainWindow)) {
|
||||
if (mainWindow.isFullScreen()) {
|
||||
mainWindow.setFullScreen(false);
|
||||
} else {
|
||||
mainWindow.unmaximize();
|
||||
setTimeout(() => {
|
||||
windowHandler.forceUnmaximize();
|
||||
}, 100);
|
||||
}
|
||||
}
|
||||
// Give focus back to main webContents
|
||||
if (mainWebContents && !mainWebContents.isDestroyed()) {
|
||||
mainWebContents.focus();
|
||||
}
|
||||
unMaximizeMainWindow();
|
||||
break;
|
||||
case apiCmds.browserLogin:
|
||||
await config.updateUserConfig({
|
||||
@@ -526,19 +521,15 @@ ipcMain.on(
|
||||
case apiCmds.isMiniViewFeatureEnabled:
|
||||
const { isMiniViewFeatureEnabled } = arg;
|
||||
windowHandler.setIsMiniViewFeatureEnabled(isMiniViewFeatureEnabled);
|
||||
windowHandler?.appMenu?.buildMenu();
|
||||
break;
|
||||
case apiCmds.isMiniViewEnabled:
|
||||
const { isMiniViewEnabled } = arg;
|
||||
windowHandler.setIsMiniViewEnabled(isMiniViewEnabled);
|
||||
windowHandler?.appMenu?.buildMenu();
|
||||
break;
|
||||
case apiCmds.onEnterMiniView:
|
||||
windowHandler.setIsMiniViewTransition(true);
|
||||
activateMiniView();
|
||||
break;
|
||||
case apiCmds.onExitMiniView:
|
||||
windowHandler.setIsMiniViewTransition(true);
|
||||
deactivateMiniView();
|
||||
break;
|
||||
case apiCmds.connectCloud9Pipe:
|
||||
|
||||
@@ -663,9 +663,16 @@ export const registerConsoleMessages = () => {
|
||||
* @returns {void}
|
||||
*/
|
||||
export const activateMiniView = (): void => {
|
||||
windowHandler.setIsMiniViewTransition(true);
|
||||
logger.info('window-actions: activateMiniView called');
|
||||
const mainWindow = windowHandler.getMainWindow();
|
||||
if (mainWindow && windowExists(mainWindow)) {
|
||||
if (mainWindow.isFullScreen()) {
|
||||
mainWindow.setFullScreen(false);
|
||||
}
|
||||
if (mainWindow.isMaximized()) {
|
||||
unMaximizeMainWindow();
|
||||
}
|
||||
const { mainWinPosInMiniView } = config.getUserConfigFields([
|
||||
'mainWinPosInMiniView',
|
||||
]);
|
||||
@@ -711,6 +718,7 @@ export const activateMiniView = (): void => {
|
||||
* @returns {void}
|
||||
*/
|
||||
export const deactivateMiniView = (): void => {
|
||||
windowHandler.setIsMiniViewTransition(true);
|
||||
logger.info('window-actions: deactivateMiniView called');
|
||||
const mainWindow = windowHandler.getMainWindow();
|
||||
if (mainWindow && windowExists(mainWindow)) {
|
||||
@@ -747,3 +755,28 @@ export const deactivateMiniView = (): void => {
|
||||
'window-actions: activateMiniView main window does not exist or is invalid',
|
||||
);
|
||||
};
|
||||
|
||||
/**
|
||||
* Unmaximizes the main window, exiting fullscreen if necessary, and restores focus.
|
||||
*
|
||||
* @function unMaximizeMainWindow
|
||||
* @returns {void}
|
||||
*/
|
||||
export const unMaximizeMainWindow = (): void => {
|
||||
const mainWindow = windowHandler.getMainWindow() as ICustomBrowserWindow;
|
||||
if (mainWindow && windowExists(mainWindow)) {
|
||||
if (mainWindow.isFullScreen()) {
|
||||
mainWindow.setFullScreen(false);
|
||||
} else {
|
||||
mainWindow.unmaximize();
|
||||
setTimeout(() => {
|
||||
windowHandler.forceUnmaximize();
|
||||
}, 100);
|
||||
}
|
||||
}
|
||||
const mainWebContents = windowHandler.getMainWebContents();
|
||||
// Give focus back to main webContents
|
||||
if (mainWebContents && !mainWebContents.isDestroyed()) {
|
||||
mainWebContents.focus();
|
||||
}
|
||||
};
|
||||
@@ -32,6 +32,7 @@ import { ScreenShotAnnotation } from '../common/ipcEvent';
|
||||
import { logger } from '../common/logger';
|
||||
import {
|
||||
calculatePercentage,
|
||||
debounce,
|
||||
getCommandLineArgs,
|
||||
getGuid,
|
||||
throttle,
|
||||
@@ -61,6 +62,8 @@ import { winStore } from './stores';
|
||||
import { checkIfBuildExpired } from './ttl-handler';
|
||||
import { versionHandler } from './version-handler';
|
||||
import {
|
||||
activateMiniView,
|
||||
deactivateMiniView,
|
||||
handlePermissionRequests,
|
||||
monitorWindowActions,
|
||||
onConsoleMessages,
|
||||
@@ -165,6 +168,7 @@ export class WindowHandler {
|
||||
}
|
||||
return format(parsedUrl);
|
||||
}
|
||||
|
||||
public mainView: ICustomWebContentsView | null = null;
|
||||
public titleBarView: ICustomWebContentsView | null = null;
|
||||
public mainWebContents: WebContents | undefined;
|
||||
@@ -483,6 +487,15 @@ export class WindowHandler {
|
||||
: ClientSwitchType.STARTPAGE_CLIENT_2_0_DAILY;
|
||||
windowHandler.switchClient(clientSwitchType);
|
||||
}, SHORTCUT_KEY_THROTTLE);
|
||||
|
||||
// throttled mini view switch
|
||||
const throttledSwitchMiniView = debounce(() => {
|
||||
if (this.isMiniViewEnabled) {
|
||||
deactivateMiniView();
|
||||
} else {
|
||||
activateMiniView();
|
||||
}
|
||||
}, SHORTCUT_KEY_THROTTLE);
|
||||
this.mainWebContents.on('before-input-event', (event, input) => {
|
||||
const windowsDevTools =
|
||||
input.control && input.shift && input.key.toLowerCase() === 'i';
|
||||
@@ -511,6 +524,13 @@ export class WindowHandler {
|
||||
}
|
||||
}
|
||||
}
|
||||
if (isWindowsOS && this.isMiniViewFeatureEnabled) {
|
||||
const isSwitchMiniView =
|
||||
input.control && input.shift && input.key.toLowerCase() === 'm';
|
||||
if (isSwitchMiniView) {
|
||||
throttledSwitchMiniView();
|
||||
}
|
||||
}
|
||||
});
|
||||
if (isMaximized || isMaximizedFlag) {
|
||||
this.mainWindow.maximize();
|
||||
@@ -882,6 +902,7 @@ export class WindowHandler {
|
||||
): void => {
|
||||
this.isMiniViewFeatureEnabled = isMiniViewFeatureEnabled;
|
||||
mainEvents.publish('on-mini-view-feature', [isMiniViewFeatureEnabled]);
|
||||
this.appMenu?.buildMenu();
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -899,6 +920,7 @@ export class WindowHandler {
|
||||
public setIsMiniViewEnabled = (isMiniViewEnabled: boolean): void => {
|
||||
this.isMiniViewEnabled = isMiniViewEnabled;
|
||||
mainEvents.publish('on-mini-view', [isMiniViewEnabled]);
|
||||
this.appMenu?.buildMenu();
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
@@ -227,6 +227,28 @@ export const throttle = (
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
* Debounces a function, ensuring it's only called after a specified delay
|
||||
* has passed since the last invocation.
|
||||
*
|
||||
* @template T The type of the function to debounce.
|
||||
* @param {T} func The function to debounce.
|
||||
* @param {number} delay The delay in milliseconds before the function is invoked.
|
||||
* @returns {(...args: Parameters<T>) => void} A debounced version of the function.
|
||||
*/
|
||||
export const debounce = <T extends (...args: any[]) => void>(
|
||||
func: T,
|
||||
delay: number,
|
||||
): ((...args: Parameters<T>) => void) => {
|
||||
let timer: ReturnType<typeof setTimeout>;
|
||||
return (...args: Parameters<T>): void => {
|
||||
clearTimeout(timer);
|
||||
timer = setTimeout(() => {
|
||||
func(...args);
|
||||
}, delay);
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
* Formats a string with dynamic values
|
||||
* @param str {String} String to be formatted
|
||||
|
||||
Reference in new issue
Block a user