mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-13 21:05:19 +00:00
feat: add open app route (#3899)
This commit is contained in:
@@ -95,7 +95,13 @@ async function createWindow() {
|
||||
|
||||
browserWindow.on('close', e => {
|
||||
e.preventDefault();
|
||||
browserWindow.destroy();
|
||||
// close and destroy all windows
|
||||
BrowserWindow.getAllWindows().forEach(w => {
|
||||
if (!w.isDestroyed()) {
|
||||
w.close();
|
||||
w.destroy();
|
||||
}
|
||||
});
|
||||
helperConnectionUnsub?.();
|
||||
// TODO: gracefully close the app, for example, ask user to save unsaved changes
|
||||
});
|
||||
@@ -123,44 +129,12 @@ async function createWindow() {
|
||||
|
||||
// singleton
|
||||
let browserWindow: BrowserWindow | undefined;
|
||||
let popup: BrowserWindow | undefined;
|
||||
|
||||
function createPopupWindow() {
|
||||
if (!popup || popup?.isDestroyed()) {
|
||||
const mainExposedMeta = getExposedMeta();
|
||||
popup = new BrowserWindow({
|
||||
width: 1200,
|
||||
height: 600,
|
||||
alwaysOnTop: true,
|
||||
resizable: false,
|
||||
webPreferences: {
|
||||
preload: join(__dirname, './preload.js'),
|
||||
additionalArguments: [
|
||||
`--main-exposed-meta=` + JSON.stringify(mainExposedMeta),
|
||||
// popup window does not need helper process, right?
|
||||
],
|
||||
},
|
||||
});
|
||||
popup.on('close', e => {
|
||||
e.preventDefault();
|
||||
popup?.destroy();
|
||||
popup = undefined;
|
||||
});
|
||||
browserWindow?.webContents.once('did-finish-load', () => {
|
||||
closePopup();
|
||||
});
|
||||
}
|
||||
return popup;
|
||||
}
|
||||
|
||||
/**
|
||||
* Restore existing BrowserWindow or Create new BrowserWindow
|
||||
*/
|
||||
export async function restoreOrCreateWindow() {
|
||||
browserWindow =
|
||||
browserWindow || BrowserWindow.getAllWindows().find(w => !w.isDestroyed());
|
||||
|
||||
if (browserWindow === undefined) {
|
||||
if (!browserWindow || browserWindow.isDestroyed()) {
|
||||
browserWindow = await createWindow();
|
||||
}
|
||||
|
||||
@@ -172,17 +146,29 @@ export async function restoreOrCreateWindow() {
|
||||
return browserWindow;
|
||||
}
|
||||
|
||||
export async function handleOpenUrlInPopup(url: string) {
|
||||
const popup = createPopupWindow();
|
||||
await popup.loadURL(url);
|
||||
}
|
||||
|
||||
export function closePopup() {
|
||||
if (!popup?.isDestroyed()) {
|
||||
popup?.close();
|
||||
popup?.destroy();
|
||||
popup = undefined;
|
||||
}
|
||||
export async function handleOpenUrlInHiddenWindow(url: string) {
|
||||
const mainExposedMeta = getExposedMeta();
|
||||
const win = new BrowserWindow({
|
||||
width: 1200,
|
||||
height: 600,
|
||||
webPreferences: {
|
||||
preload: join(__dirname, './preload.js'),
|
||||
additionalArguments: [
|
||||
`--main-exposed-meta=` + JSON.stringify(mainExposedMeta),
|
||||
// popup window does not need helper process, right?
|
||||
],
|
||||
},
|
||||
show: false,
|
||||
});
|
||||
win.on('close', e => {
|
||||
e.preventDefault();
|
||||
if (!win.isDestroyed()) {
|
||||
win.destroy();
|
||||
}
|
||||
});
|
||||
logger.info('loading page at', url);
|
||||
await win.loadURL(url);
|
||||
return win;
|
||||
}
|
||||
|
||||
export function reloadApp() {
|
||||
|
||||
Reference in New Issue
Block a user