Skip to content

Commit 850e646

Browse files
authored
fix: electon rendering on windows (#14456)
fix #14450 fix #14401 fix #13983 fix #12766 fix #14404 fix #12019 #### PR Dependency Tree * **PR #14456** 👈 This tree was auto-generated by [Charcoal](https://github.com/danerwilliams/charcoal) <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Added new tab navigation functions: `switchTab`, `switchToNextTab`, and `switchToPreviousTab`. * **Bug Fixes** * Improved bounds validation for tab view resizing. * Enhanced tab lifecycle management during navigation events. * Refined background throttling behavior for active tabs. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
1 parent 728e02c commit 850e646

2 files changed

Lines changed: 34 additions & 19 deletions

File tree

  • packages/frontend/apps

packages/frontend/apps/electron-renderer/src/app/effects/events.ts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { DesktopApiService } from '@affine/core/modules/desktop-api';
21
import { WorkspaceDialogService } from '@affine/core/modules/dialogs';
32
import type { SettingTab } from '@affine/core/modules/dialogs/constant';
43
import { DocsService } from '@affine/core/modules/doc';
@@ -17,12 +16,6 @@ export function setupEvents(frameworkProvider: FrameworkProvider) {
1716
frameworkProvider.get(LifecycleService).applicationFocus();
1817
});
1918
frameworkProvider.get(LifecycleService).applicationStart();
20-
window.addEventListener('unload', () => {
21-
frameworkProvider
22-
.get(DesktopApiService)
23-
.api.handler.ui.pingAppLayoutReady(false)
24-
.catch(console.error);
25-
});
2619

2720
events?.applicationMenu.openInSettingModal(({ activeTab, scrollAnchor }) => {
2821
using currentWorkspace = getCurrentWorkspace(frameworkProvider);

packages/frontend/apps/electron/src/main/windows-manager/tab-views.ts

Lines changed: 34 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -789,12 +789,9 @@ export class WebContentViewsManager {
789789

790790
resizeView = (view: View) => {
791791
// app view will take full w/h of the main window
792-
view.setBounds({
793-
x: 0,
794-
y: 0,
795-
width: this.mainWindow?.getContentBounds().width ?? 0,
796-
height: this.mainWindow?.getContentBounds().height ?? 0,
797-
});
792+
const bounds = this.mainWindow?.getContentBounds();
793+
if (!bounds || bounds.width <= 0 || bounds.height <= 0) return;
794+
view.setBounds({ x: 0, y: 0, width: bounds.width, height: bounds.height });
798795
};
799796

800797
private readonly generateViewId = (type: 'app' | 'shell') => {
@@ -824,7 +821,7 @@ export class WebContentViewsManager {
824821
preload: join(__dirname, './preload.js'), // this points to the bundled preload module
825822
// serialize exposed meta that to be used in preload
826823
additionalArguments: additionalArguments,
827-
backgroundThrottling: true,
824+
backgroundThrottling: type === 'app',
828825
}),
829826
});
830827

@@ -881,6 +878,15 @@ export class WebContentViewsManager {
881878

882879
// shell process do not need to connect to helper process
883880
if (type !== 'shell') {
881+
view.webContents.on(
882+
'did-start-navigation',
883+
(_event, _url, isInPlace, isMainFrame) => {
884+
// Keep shell fallback lifecycle tied to main-frame navigation only.
885+
if (isMainFrame && !isInPlace) {
886+
this.setTabUIUnready(viewId);
887+
}
888+
}
889+
);
884890
view.webContents.on('did-finish-load', () => {
885891
disconnectHelperProcess?.();
886892
disconnectHelperProcess = helperProcessManager.connectRenderer(
@@ -935,7 +941,8 @@ export class WebContentViewsManager {
935941
const mainFocused = this.mainWindow?.isFocused() ?? false;
936942
const activeId = this.activeWorkbenchId;
937943
this.webViewsMap$.value.forEach((view, id) => {
938-
if (id === 'shell') {
944+
// skip active view to avoid windows rendering
945+
if (id === 'shell' || id === activeId) {
939946
return;
940947
}
941948
const shouldThrottle = !mainFocused || id !== activeId;
@@ -1156,13 +1163,28 @@ export const showDevTools = (id?: string) => {
11561163
};
11571164

11581165
export const pingAppLayoutReady = (wc: WebContents, ready: boolean) => {
1159-
const viewId =
1160-
WebContentViewsManager.instance.getWorkbenchIdFromWebContentsId(wc.id);
1166+
const manager = WebContentViewsManager.instance;
1167+
const viewId = manager.getWorkbenchIdFromWebContentsId(wc.id);
11611168
if (viewId) {
11621169
if (ready) {
1163-
WebContentViewsManager.instance.setTabUIReady(viewId);
1170+
manager.setTabUIReady(viewId);
11641171
} else {
1165-
WebContentViewsManager.instance.setTabUIUnready(viewId);
1172+
const isActive = manager.activeWorkbenchId === viewId;
1173+
const view = manager.getViewById(viewId);
1174+
const isLoadingMainFrame =
1175+
view?.webContents.isLoadingMainFrame?.() ??
1176+
view?.webContents.isLoading?.() ??
1177+
false;
1178+
// Renderer unload can be noisy on Windows when resizing;
1179+
// keep active tab visible unless it is truly navigating.
1180+
if (isActive && !isLoadingMainFrame) {
1181+
logger.warn('ignore pingAppLayoutReady(false) for active tab', {
1182+
viewId,
1183+
senderId: wc.id,
1184+
});
1185+
return;
1186+
}
1187+
manager.setTabUIUnready(viewId);
11661188
}
11671189
}
11681190
};

0 commit comments

Comments
 (0)