Skip to content

Commit

Permalink
fix: resize of popup
Browse files Browse the repository at this point in the history
  • Loading branch information
linonetwo committed Jun 30, 2024
1 parent 7e4bd2b commit 7e7c72a
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 14 deletions.
4 changes: 2 additions & 2 deletions src/services/view/handleNewWindow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ export function handleNewWindow(
nextDomain,
});
meta.forceNewWindow = false;
const metadataConfig = {
const webPreferences = {
additionalArguments: [
`${MetaDataChannel.browserViewMetaData}${WindowNames.view}`,
`${MetaDataChannel.browserViewMetaData}${encodeURIComponent(JSON.stringify(browserViewMetaData))}`,
Expand All @@ -106,7 +106,7 @@ export function handleNewWindow(
y: windowWithBrowserViewState.y,
width: windowWithBrowserViewState.width,
height: windowWithBrowserViewState.height,
webPreferences: metadataConfig,
webPreferences,
autoHideMenuBar: true,
};

Expand Down
17 changes: 13 additions & 4 deletions src/services/view/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import { logger } from '@services/libs/log';
import { INativeService } from '@services/native/interface';
import { IBrowserViewMetaData, WindowNames } from '@services/windows/WindowProperties';
import { IWorkspace } from '@services/workspaces/interface';
import debounce from 'lodash/debounce';
import { setViewEventName } from './constants';
import { ViewLoadUrlError } from './error';
import { IViewService } from './interface';
Expand Down Expand Up @@ -149,6 +150,7 @@ export class View implements IViewService {
// if item is called in popup window
// modify menu bar in the popup window instead
if (browserWindow === undefined) return;
// TODO: on popup (secondary) window, browserWindow here seems can't get the correct webContent, so this never returns. And can't set zoom of popup.
const { isPopup } = await getFromRenderer<IBrowserViewMetaData>(MetaDataChannel.getViewMetaData, browserWindow);
if (isPopup === true) {
const contents = browserWindow.webContents;
Expand Down Expand Up @@ -308,11 +310,18 @@ export class View implements IViewService {
const contentSize = browserWindow.getContentSize();
const newViewBounds = await getViewBounds(contentSize as [number, number], { windowName });
view.setBounds(newViewBounds);
// view.setAutoResize({
// width: true,
// height: true,
// });
}
// handle autoResize on user drag the window's edge
const debouncedOnResize = debounce(async () => {
logger.debug('debouncedOnResize');
if (browserWindow === undefined) return;
if (windowName === WindowNames.secondary || windowName === WindowNames.main) {
const contentSize = browserWindow.getContentSize();
const newViewBounds = await getViewBounds(contentSize as [number, number], { windowName });
view.setBounds(newViewBounds);
}
}, 200);
browserWindow.on('resize', debouncedOnResize);
return view;
}

Expand Down
8 changes: 0 additions & 8 deletions src/services/windows/registerBrowserViewWindowListeners.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import { container } from '@services/container';
import { logger } from '@services/libs/log';
import { IPreferenceService } from '@services/preferences/interface';
import serviceIdentifier from '@services/serviceIdentifier';
import { IViewService } from '@services/view/interface';
import { IWorkspaceViewService } from '@services/workspacesView/interface';
import { BrowserWindow } from 'electron';
import debounce from 'lodash/debounce';
import { IWindowService } from './interface';
import { WindowNames } from './WindowProperties';

Expand Down Expand Up @@ -61,10 +59,4 @@ export function registerBrowserViewWindowListeners(newWindow: BrowserWindow, win
newWindow?.webContents?.send?.('is-fullscreen-updated', false);
await workspaceViewService.realignActiveWorkspace();
});
const debouncedOnResize = debounce(() => {
logger.debug('debouncedOnResize');
if (windowName !== WindowNames.main || newWindow === undefined) return;
void workspaceViewService.realignActiveWorkspace();
}, 250);
newWindow.on('resize', debouncedOnResize);
}

0 comments on commit 7e7c72a

Please sign in to comment.