mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-09-07 01:09:54 +08:00
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 -->
This commit is contained in:
@@ -1,4 +1,3 @@
|
|||||||
import { DesktopApiService } from '@affine/core/modules/desktop-api';
|
|
||||||
import { WorkspaceDialogService } from '@affine/core/modules/dialogs';
|
import { WorkspaceDialogService } from '@affine/core/modules/dialogs';
|
||||||
import type { SettingTab } from '@affine/core/modules/dialogs/constant';
|
import type { SettingTab } from '@affine/core/modules/dialogs/constant';
|
||||||
import { DocsService } from '@affine/core/modules/doc';
|
import { DocsService } from '@affine/core/modules/doc';
|
||||||
@@ -17,12 +16,6 @@ export function setupEvents(frameworkProvider: FrameworkProvider) {
|
|||||||
frameworkProvider.get(LifecycleService).applicationFocus();
|
frameworkProvider.get(LifecycleService).applicationFocus();
|
||||||
});
|
});
|
||||||
frameworkProvider.get(LifecycleService).applicationStart();
|
frameworkProvider.get(LifecycleService).applicationStart();
|
||||||
window.addEventListener('unload', () => {
|
|
||||||
frameworkProvider
|
|
||||||
.get(DesktopApiService)
|
|
||||||
.api.handler.ui.pingAppLayoutReady(false)
|
|
||||||
.catch(console.error);
|
|
||||||
});
|
|
||||||
|
|
||||||
events?.applicationMenu.openInSettingModal(({ activeTab, scrollAnchor }) => {
|
events?.applicationMenu.openInSettingModal(({ activeTab, scrollAnchor }) => {
|
||||||
using currentWorkspace = getCurrentWorkspace(frameworkProvider);
|
using currentWorkspace = getCurrentWorkspace(frameworkProvider);
|
||||||
|
|||||||
@@ -789,12 +789,9 @@ export class WebContentViewsManager {
|
|||||||
|
|
||||||
resizeView = (view: View) => {
|
resizeView = (view: View) => {
|
||||||
// app view will take full w/h of the main window
|
// app view will take full w/h of the main window
|
||||||
view.setBounds({
|
const bounds = this.mainWindow?.getContentBounds();
|
||||||
x: 0,
|
if (!bounds || bounds.width <= 0 || bounds.height <= 0) return;
|
||||||
y: 0,
|
view.setBounds({ x: 0, y: 0, width: bounds.width, height: bounds.height });
|
||||||
width: this.mainWindow?.getContentBounds().width ?? 0,
|
|
||||||
height: this.mainWindow?.getContentBounds().height ?? 0,
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
private readonly generateViewId = (type: 'app' | 'shell') => {
|
private readonly generateViewId = (type: 'app' | 'shell') => {
|
||||||
@@ -824,7 +821,7 @@ export class WebContentViewsManager {
|
|||||||
preload: join(__dirname, './preload.js'), // this points to the bundled preload module
|
preload: join(__dirname, './preload.js'), // this points to the bundled preload module
|
||||||
// serialize exposed meta that to be used in preload
|
// serialize exposed meta that to be used in preload
|
||||||
additionalArguments: additionalArguments,
|
additionalArguments: additionalArguments,
|
||||||
backgroundThrottling: true,
|
backgroundThrottling: type === 'app',
|
||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -881,6 +878,15 @@ export class WebContentViewsManager {
|
|||||||
|
|
||||||
// shell process do not need to connect to helper process
|
// shell process do not need to connect to helper process
|
||||||
if (type !== 'shell') {
|
if (type !== 'shell') {
|
||||||
|
view.webContents.on(
|
||||||
|
'did-start-navigation',
|
||||||
|
(_event, _url, isInPlace, isMainFrame) => {
|
||||||
|
// Keep shell fallback lifecycle tied to main-frame navigation only.
|
||||||
|
if (isMainFrame && !isInPlace) {
|
||||||
|
this.setTabUIUnready(viewId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
view.webContents.on('did-finish-load', () => {
|
view.webContents.on('did-finish-load', () => {
|
||||||
disconnectHelperProcess?.();
|
disconnectHelperProcess?.();
|
||||||
disconnectHelperProcess = helperProcessManager.connectRenderer(
|
disconnectHelperProcess = helperProcessManager.connectRenderer(
|
||||||
@@ -935,7 +941,8 @@ export class WebContentViewsManager {
|
|||||||
const mainFocused = this.mainWindow?.isFocused() ?? false;
|
const mainFocused = this.mainWindow?.isFocused() ?? false;
|
||||||
const activeId = this.activeWorkbenchId;
|
const activeId = this.activeWorkbenchId;
|
||||||
this.webViewsMap$.value.forEach((view, id) => {
|
this.webViewsMap$.value.forEach((view, id) => {
|
||||||
if (id === 'shell') {
|
// skip active view to avoid windows rendering
|
||||||
|
if (id === 'shell' || id === activeId) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const shouldThrottle = !mainFocused || id !== activeId;
|
const shouldThrottle = !mainFocused || id !== activeId;
|
||||||
@@ -1156,13 +1163,28 @@ export const showDevTools = (id?: string) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export const pingAppLayoutReady = (wc: WebContents, ready: boolean) => {
|
export const pingAppLayoutReady = (wc: WebContents, ready: boolean) => {
|
||||||
const viewId =
|
const manager = WebContentViewsManager.instance;
|
||||||
WebContentViewsManager.instance.getWorkbenchIdFromWebContentsId(wc.id);
|
const viewId = manager.getWorkbenchIdFromWebContentsId(wc.id);
|
||||||
if (viewId) {
|
if (viewId) {
|
||||||
if (ready) {
|
if (ready) {
|
||||||
WebContentViewsManager.instance.setTabUIReady(viewId);
|
manager.setTabUIReady(viewId);
|
||||||
} else {
|
} else {
|
||||||
WebContentViewsManager.instance.setTabUIUnready(viewId);
|
const isActive = manager.activeWorkbenchId === viewId;
|
||||||
|
const view = manager.getViewById(viewId);
|
||||||
|
const isLoadingMainFrame =
|
||||||
|
view?.webContents.isLoadingMainFrame?.() ??
|
||||||
|
view?.webContents.isLoading?.() ??
|
||||||
|
false;
|
||||||
|
// Renderer unload can be noisy on Windows when resizing;
|
||||||
|
// keep active tab visible unless it is truly navigating.
|
||||||
|
if (isActive && !isLoadingMainFrame) {
|
||||||
|
logger.warn('ignore pingAppLayoutReady(false) for active tab', {
|
||||||
|
viewId,
|
||||||
|
senderId: wc.id,
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
manager.setTabUIUnready(viewId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user