mirror of
https://github.com/toeverything/AFFiNE.git
synced 2025-01-05 06:12:11 +03:00
fix(electron): main window should be opened first before destroying onboard window (#5319)
The issue listed on the title will prevent main window from showing on windows.
This commit is contained in:
parent
e10609276d
commit
128f8066c3
1
packages/common/env/src/constant.ts
vendored
1
packages/common/env/src/constant.ts
vendored
@ -6,6 +6,7 @@ declare global {
|
|||||||
appInfo: {
|
appInfo: {
|
||||||
electron: boolean;
|
electron: boolean;
|
||||||
schema: string;
|
schema: string;
|
||||||
|
windowName: string;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -59,6 +59,9 @@ schema = isDev ? 'affine-dev' : schema;
|
|||||||
|
|
||||||
export const appInfo = {
|
export const appInfo = {
|
||||||
electron: true,
|
electron: true,
|
||||||
|
windowName: process.argv
|
||||||
|
.find(arg => arg.startsWith('--window-name='))
|
||||||
|
?.split('=')[1],
|
||||||
schema,
|
schema,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -16,19 +16,25 @@ const performanceMainLogger = performanceLogger.namespace('main');
|
|||||||
function main() {
|
function main() {
|
||||||
performanceMainLogger.info('start');
|
performanceMainLogger.info('start');
|
||||||
|
|
||||||
const rootStore = getCurrentStore();
|
// skip bootstrap setup for desktop onboarding
|
||||||
performanceMainLogger.info('setup start');
|
if (window.appInfo?.windowName !== 'onboarding') {
|
||||||
setup();
|
const rootStore = getCurrentStore();
|
||||||
performanceMainLogger.info('setup done');
|
performanceMainLogger.info('setup start');
|
||||||
|
setup();
|
||||||
|
performanceMainLogger.info('setup done');
|
||||||
|
|
||||||
bootstrapPluginSystem(rootStore).catch(err => {
|
bootstrapPluginSystem(rootStore).catch(err => {
|
||||||
console.error('Failed to bootstrap plugin system', err);
|
console.error('Failed to bootstrap plugin system', err);
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
mountApp();
|
||||||
|
}
|
||||||
|
|
||||||
|
function mountApp() {
|
||||||
performanceMainLogger.info('import app');
|
performanceMainLogger.info('import app');
|
||||||
const root = document.getElementById('app');
|
const root = document.getElementById('app');
|
||||||
assertExists(root);
|
assertExists(root);
|
||||||
|
|
||||||
performanceMainLogger.info('render app');
|
performanceMainLogger.info('render app');
|
||||||
createRoot(root).render(
|
createRoot(root).render(
|
||||||
<StrictMode>
|
<StrictMode>
|
||||||
|
@ -10,7 +10,6 @@ import { persistentConfig } from './config-storage/persist';
|
|||||||
import { setupDeepLink } from './deep-link';
|
import { setupDeepLink } from './deep-link';
|
||||||
import { registerEvents } from './events';
|
import { registerEvents } from './events';
|
||||||
import { registerHandlers } from './handlers';
|
import { registerHandlers } from './handlers';
|
||||||
import { ensureHelperProcess } from './helper-process';
|
|
||||||
import { logger } from './logger';
|
import { logger } from './logger';
|
||||||
import { registerProtocol } from './protocol';
|
import { registerProtocol } from './protocol';
|
||||||
import { registerUpdater } from './updater';
|
import { registerUpdater } from './updater';
|
||||||
@ -59,7 +58,9 @@ app.on('window-all-closed', () => {
|
|||||||
/**
|
/**
|
||||||
* @see https://www.electronjs.org/docs/latest/api/app#event-activate-macos Event: 'activate'
|
* @see https://www.electronjs.org/docs/latest/api/app#event-activate-macos Event: 'activate'
|
||||||
*/
|
*/
|
||||||
app.on('activate', launch);
|
app.on('activate', () => {
|
||||||
|
launch().catch(e => console.error('Failed launch:', e));
|
||||||
|
});
|
||||||
|
|
||||||
setupDeepLink(app);
|
setupDeepLink(app);
|
||||||
|
|
||||||
@ -71,7 +72,6 @@ app
|
|||||||
.then(registerProtocol)
|
.then(registerProtocol)
|
||||||
.then(registerHandlers)
|
.then(registerHandlers)
|
||||||
.then(registerEvents)
|
.then(registerEvents)
|
||||||
.then(ensureHelperProcess)
|
|
||||||
.then(launch)
|
.then(launch)
|
||||||
.then(createApplicationMenu)
|
.then(createApplicationMenu)
|
||||||
.then(registerUpdater)
|
.then(registerUpdater)
|
||||||
|
@ -14,8 +14,6 @@ import { parseCookie } from './utils';
|
|||||||
const IS_DEV: boolean =
|
const IS_DEV: boolean =
|
||||||
process.env.NODE_ENV === 'development' && !process.env.CI;
|
process.env.NODE_ENV === 'development' && !process.env.CI;
|
||||||
|
|
||||||
const DEV_TOOL = process.env.DEV_TOOL === 'true';
|
|
||||||
|
|
||||||
// todo: not all window need all of the exposed meta
|
// todo: not all window need all of the exposed meta
|
||||||
const getWindowAdditionalArguments = async () => {
|
const getWindowAdditionalArguments = async () => {
|
||||||
const { getExposedMeta } = await import('./exposed');
|
const { getExposedMeta } = await import('./exposed');
|
||||||
@ -25,6 +23,7 @@ const getWindowAdditionalArguments = async () => {
|
|||||||
return [
|
return [
|
||||||
`--main-exposed-meta=` + JSON.stringify(mainExposedMeta),
|
`--main-exposed-meta=` + JSON.stringify(mainExposedMeta),
|
||||||
`--helper-exposed-meta=` + JSON.stringify(helperExposedMeta),
|
`--helper-exposed-meta=` + JSON.stringify(helperExposedMeta),
|
||||||
|
`--window-name=main`,
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -92,12 +91,6 @@ async function createWindow(additionalArguments: string[]) {
|
|||||||
);
|
);
|
||||||
|
|
||||||
logger.info('main window is ready to show');
|
logger.info('main window is ready to show');
|
||||||
|
|
||||||
if (DEV_TOOL) {
|
|
||||||
browserWindow.webContents.openDevTools({
|
|
||||||
mode: 'detach',
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
browserWindow.on('close', e => {
|
browserWindow.on('close', e => {
|
||||||
|
@ -1,32 +1,23 @@
|
|||||||
import { assert } from 'console';
|
|
||||||
import { BrowserWindow, screen } from 'electron';
|
import { BrowserWindow, screen } from 'electron';
|
||||||
import { join } from 'path';
|
import { join } from 'path';
|
||||||
|
|
||||||
import { mainWindowOrigin } from './constants';
|
import { mainWindowOrigin } from './constants';
|
||||||
// import { getExposedMeta } from './exposed';
|
// import { getExposedMeta } from './exposed';
|
||||||
import { ensureHelperProcess } from './helper-process';
|
|
||||||
import { logger } from './logger';
|
import { logger } from './logger';
|
||||||
|
|
||||||
// todo: not all window need all of the exposed meta
|
// todo: not all window need all of the exposed meta
|
||||||
const getWindowAdditionalArguments = async () => {
|
const getWindowAdditionalArguments = async () => {
|
||||||
const { getExposedMeta } = await import('./exposed');
|
const { getExposedMeta } = await import('./exposed');
|
||||||
const mainExposedMeta = getExposedMeta();
|
const mainExposedMeta = getExposedMeta();
|
||||||
const helperProcessManager = await ensureHelperProcess();
|
|
||||||
const helperExposedMeta = await helperProcessManager.rpc?.getMeta();
|
|
||||||
return [
|
return [
|
||||||
`--main-exposed-meta=` + JSON.stringify(mainExposedMeta),
|
`--main-exposed-meta=` + JSON.stringify(mainExposedMeta),
|
||||||
`--helper-exposed-meta=` + JSON.stringify(helperExposedMeta),
|
`--window-name=onboarding`,
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
|
|
||||||
async function createOnboardingWindow(additionalArguments: string[]) {
|
async function createOnboardingWindow(additionalArguments: string[]) {
|
||||||
logger.info('creating onboarding window');
|
logger.info('creating onboarding window');
|
||||||
|
|
||||||
const helperProcessManager = await ensureHelperProcess();
|
|
||||||
const helperExposedMeta = await helperProcessManager.rpc?.getMeta();
|
|
||||||
|
|
||||||
assert(helperExposedMeta, 'helperExposedMeta should be defined');
|
|
||||||
|
|
||||||
// get user's screen size
|
// get user's screen size
|
||||||
const { width, height } = screen.getPrimaryDisplay().workAreaSize;
|
const { width, height } = screen.getPrimaryDisplay().workAreaSize;
|
||||||
|
|
||||||
@ -35,6 +26,7 @@ async function createOnboardingWindow(additionalArguments: string[]) {
|
|||||||
height,
|
height,
|
||||||
frame: false,
|
frame: false,
|
||||||
show: false,
|
show: false,
|
||||||
|
resizable: false,
|
||||||
closable: false,
|
closable: false,
|
||||||
minimizable: false,
|
minimizable: false,
|
||||||
maximizable: false,
|
maximizable: false,
|
||||||
|
@ -54,10 +54,17 @@ export const uiHandlers = {
|
|||||||
launchStage.value = 'main';
|
launchStage.value = 'main';
|
||||||
persistentConfig.patch('onBoarding', false);
|
persistentConfig.patch('onBoarding', false);
|
||||||
}
|
}
|
||||||
initMainWindow().catch(logger.error);
|
|
||||||
getOnboardingWindow()
|
try {
|
||||||
.then(w => w?.destroy())
|
const onboarding = await getOnboardingWindow();
|
||||||
.catch(logger.error);
|
onboarding?.hide();
|
||||||
|
await initMainWindow();
|
||||||
|
// need to destroy onboarding window after main window is ready
|
||||||
|
// otherwise the main window will be closed as well
|
||||||
|
onboarding?.destroy();
|
||||||
|
} catch (err) {
|
||||||
|
logger.error('handleOpenMainApp', err);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
getBookmarkDataByLink: async (_, link: string) => {
|
getBookmarkDataByLink: async (_, link: string) => {
|
||||||
if (
|
if (
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
import { logger } from '../logger';
|
||||||
import { initMainWindow } from '../main-window';
|
import { initMainWindow } from '../main-window';
|
||||||
import {
|
import {
|
||||||
getOnboardingWindow,
|
getOnboardingWindow,
|
||||||
@ -8,19 +9,19 @@ import { launchStage } from './stage';
|
|||||||
/**
|
/**
|
||||||
* Launch app depending on launch stage
|
* Launch app depending on launch stage
|
||||||
*/
|
*/
|
||||||
export function launch() {
|
export async function launch() {
|
||||||
const stage = launchStage.value;
|
const stage = launchStage.value;
|
||||||
if (stage === 'main') {
|
if (stage === 'main') {
|
||||||
initMainWindow().catch(e => {
|
initMainWindow().catch(e => {
|
||||||
console.error('Failed to restore or create window:', e);
|
logger.error('Failed to restore or create window:', e);
|
||||||
});
|
});
|
||||||
|
|
||||||
getOnboardingWindow()
|
getOnboardingWindow()
|
||||||
.then(w => w?.destroy())
|
.then(w => w?.destroy())
|
||||||
.catch(e => console.error('Failed to destroy onboarding window:', e));
|
.catch(e => logger.error('Failed to destroy onboarding window:', e));
|
||||||
}
|
}
|
||||||
if (stage === 'onboarding')
|
if (stage === 'onboarding')
|
||||||
getOrCreateOnboardingWindow().catch(e => {
|
getOrCreateOnboardingWindow().catch(e => {
|
||||||
console.error('Failed to restore or create onboarding window:', e);
|
logger.error('Failed to restore or create onboarding window:', e);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user