|
@@ -31,9 +31,11 @@ type InputPassword = {
|
|
|
|
|
|
|
|
let mainWindow: BrowserWindow | null
|
|
let mainWindow: BrowserWindow | null
|
|
|
let childView: WebContentsView | null
|
|
let childView: WebContentsView | null
|
|
|
|
|
+let childSideView: WebContentsView | null
|
|
|
|
|
|
|
|
let isSideOpen = true
|
|
let isSideOpen = true
|
|
|
let childViewAspectRatio = 0;
|
|
let childViewAspectRatio = 0;
|
|
|
|
|
+let childViewSideUrl : string | undefined;
|
|
|
let childViewInputPassword: InputPassword | undefined;
|
|
let childViewInputPassword: InputPassword | undefined;
|
|
|
const SIDE_WIDTH = 250
|
|
const SIDE_WIDTH = 250
|
|
|
const EXPAND_VIEW_SIZE = 40
|
|
const EXPAND_VIEW_SIZE = 40
|
|
@@ -82,37 +84,40 @@ function createWindow() {
|
|
|
allowRunningInsecureContent: true,
|
|
allowRunningInsecureContent: true,
|
|
|
},
|
|
},
|
|
|
})
|
|
})
|
|
|
|
|
+ childSideView = new WebContentsView({
|
|
|
|
|
+ webPreferences: {
|
|
|
|
|
+ allowRunningInsecureContent: true,
|
|
|
|
|
+ },
|
|
|
|
|
+ })
|
|
|
const expandButtonView = new WebContentsView({
|
|
const expandButtonView = new WebContentsView({
|
|
|
webPreferences: {
|
|
webPreferences: {
|
|
|
preload: path.join(__dirname, 'preload.mjs'),
|
|
preload: path.join(__dirname, 'preload.mjs'),
|
|
|
contextIsolation: true,
|
|
contextIsolation: true,
|
|
|
},
|
|
},
|
|
|
})
|
|
})
|
|
|
- const loadingView = new BrowserWindow({
|
|
|
|
|
- skipTaskbar: true,
|
|
|
|
|
- width: LOADING_VIEW_WIDTH,
|
|
|
|
|
- height: LOADING_VIEW_HEIGHT,
|
|
|
|
|
- parent: mainWindow,
|
|
|
|
|
- thickFrame: true,
|
|
|
|
|
- titleBarStyle: 'hidden',
|
|
|
|
|
|
|
+ const loadingView = new WebContentsView({
|
|
|
webPreferences: {
|
|
webPreferences: {
|
|
|
preload: path.join(__dirname, 'preload.mjs'),
|
|
preload: path.join(__dirname, 'preload.mjs'),
|
|
|
contextIsolation: true,
|
|
contextIsolation: true,
|
|
|
},
|
|
},
|
|
|
})
|
|
})
|
|
|
mainWindow.contentView.addChildView(childView)
|
|
mainWindow.contentView.addChildView(childView)
|
|
|
|
|
+ mainWindow.contentView.addChildView(childSideView)
|
|
|
mainWindow.contentView.addChildView(expandButtonView)
|
|
mainWindow.contentView.addChildView(expandButtonView)
|
|
|
- expandButtonView.setVisible(false)
|
|
|
|
|
|
|
+ mainWindow.contentView.addChildView(loadingView)
|
|
|
|
|
+ expandButtonView.setVisible(false)
|
|
|
|
|
+ childSideView.setVisible(false)
|
|
|
|
|
+ loadingView.setBackgroundColor('#00000000')
|
|
|
expandButtonView.setBackgroundColor('#00000000')
|
|
expandButtonView.setBackgroundColor('#00000000')
|
|
|
|
|
|
|
|
childView.webContents.on('did-start-loading', () => {
|
|
childView.webContents.on('did-start-loading', () => {
|
|
|
- loadingView.show()
|
|
|
|
|
|
|
+ loadingView.setVisible(true)
|
|
|
});
|
|
});
|
|
|
childView.webContents.on('did-stop-loading', () => {
|
|
childView.webContents.on('did-stop-loading', () => {
|
|
|
- loadingView.hide()
|
|
|
|
|
|
|
+ loadingView.setVisible(false)
|
|
|
});
|
|
});
|
|
|
childView.webContents.on('did-fail-load', (_, errorCode, errorDescription) => {
|
|
childView.webContents.on('did-fail-load', (_, errorCode, errorDescription) => {
|
|
|
- loadingView.hide()
|
|
|
|
|
|
|
+ loadingView.setVisible(false)
|
|
|
loadViewUrl(childView!, '/error?code=' + errorCode + '&message=' + errorDescription);
|
|
loadViewUrl(childView!, '/error?code=' + errorCode + '&message=' + errorDescription);
|
|
|
});
|
|
});
|
|
|
|
|
|
|
@@ -129,8 +134,8 @@ function createWindow() {
|
|
|
height: EXPAND_VIEW_SIZE
|
|
height: EXPAND_VIEW_SIZE
|
|
|
})
|
|
})
|
|
|
loadingView.setBounds({
|
|
loadingView.setBounds({
|
|
|
- x: bounds.x + (bounds.width - LOADING_VIEW_WIDTH) / 2,
|
|
|
|
|
- y: bounds.y + 30,
|
|
|
|
|
|
|
+ x: (bounds.width - LOADING_VIEW_WIDTH) / 2,
|
|
|
|
|
+ y: 30,
|
|
|
width: LOADING_VIEW_WIDTH,
|
|
width: LOADING_VIEW_WIDTH,
|
|
|
height: LOADING_VIEW_HEIGHT
|
|
height: LOADING_VIEW_HEIGHT
|
|
|
})
|
|
})
|
|
@@ -151,15 +156,33 @@ function createWindow() {
|
|
|
childHeight = childWidth / childViewAspectRatio;
|
|
childHeight = childWidth / childViewAspectRatio;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- const childX = availableX + (availableWidth - childWidth) / 2;
|
|
|
|
|
- const childY = (availableHeight - childHeight) / 2;
|
|
|
|
|
|
|
+ const remainingWidth = availableWidth - childWidth;
|
|
|
|
|
+ if (childHeight === availableHeight && remainingWidth > 0 && childViewSideUrl) {
|
|
|
|
|
+ childView!.setBounds({
|
|
|
|
|
+ x: availableX,
|
|
|
|
|
+ y: 0,
|
|
|
|
|
+ width: Math.round(childWidth),
|
|
|
|
|
+ height: Math.round(childHeight)
|
|
|
|
|
+ });
|
|
|
|
|
+ childSideView!.setBounds({
|
|
|
|
|
+ x: availableX + Math.round(childWidth),
|
|
|
|
|
+ y: 0,
|
|
|
|
|
+ width: Math.round(remainingWidth),
|
|
|
|
|
+ height: Math.round(availableHeight)
|
|
|
|
|
+ });
|
|
|
|
|
+ childSideView!.setVisible(true);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ const childX = availableX + (availableWidth - childWidth) / 2;
|
|
|
|
|
+ const childY = (availableHeight - childHeight) / 2;
|
|
|
|
|
|
|
|
- childView!.setBounds({
|
|
|
|
|
- x: Math.round(childX),
|
|
|
|
|
- y: Math.round(childY),
|
|
|
|
|
- width: Math.round(childWidth),
|
|
|
|
|
- height: Math.round(childHeight)
|
|
|
|
|
- });
|
|
|
|
|
|
|
+ childView!.setBounds({
|
|
|
|
|
+ x: Math.round(childX),
|
|
|
|
|
+ y: Math.round(childY),
|
|
|
|
|
+ width: Math.round(childWidth),
|
|
|
|
|
+ height: Math.round(childHeight)
|
|
|
|
|
+ });
|
|
|
|
|
+ childSideView!.setVisible(false);
|
|
|
|
|
+ }
|
|
|
} else {
|
|
} else {
|
|
|
childView!.setBounds({
|
|
childView!.setBounds({
|
|
|
x: availableX,
|
|
x: availableX,
|
|
@@ -167,11 +190,12 @@ function createWindow() {
|
|
|
width: availableWidth,
|
|
width: availableWidth,
|
|
|
height: availableHeight
|
|
height: availableHeight
|
|
|
});
|
|
});
|
|
|
|
|
+ childSideView!.setVisible(false);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
loadWindowPage(mainWindow, '/');
|
|
loadWindowPage(mainWindow, '/');
|
|
|
- loadWindowPage(loadingView, '/loading');
|
|
|
|
|
|
|
+ loadViewUrl(loadingView, '/loading');
|
|
|
loadViewUrl(childView, '/hello');
|
|
loadViewUrl(childView, '/hello');
|
|
|
loadViewUrl(expandButtonView, '/expand');
|
|
loadViewUrl(expandButtonView, '/expand');
|
|
|
updateChildWindowBounds();
|
|
updateChildWindowBounds();
|
|
@@ -280,11 +304,21 @@ function createWindow() {
|
|
|
})
|
|
})
|
|
|
ipcMain.on('toggle-dev-tools', toggleDevTools)
|
|
ipcMain.on('toggle-dev-tools', toggleDevTools)
|
|
|
// 加载子页URL
|
|
// 加载子页URL
|
|
|
- ipcMain.on('load-child-url', (_event, url: string, aspectRatio: number, inputPassword?: InputPassword) => {
|
|
|
|
|
|
|
+ ipcMain.on('load-child-url', (_event, url: string, aspectRatio: number, inputPassword?: InputPassword, sideUrl?: string) => {
|
|
|
if (childView)
|
|
if (childView)
|
|
|
childView.webContents.loadURL(url)
|
|
childView.webContents.loadURL(url)
|
|
|
|
|
+ if (childSideView) {
|
|
|
|
|
+ if (sideUrl) {
|
|
|
|
|
+ childSideView.webContents.loadURL(sideUrl)
|
|
|
|
|
+ } else {
|
|
|
|
|
+ childSideView.setVisible(false)
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ childViewSideUrl = sideUrl
|
|
|
childViewInputPassword = inputPassword;
|
|
childViewInputPassword = inputPassword;
|
|
|
childViewAspectRatio = aspectRatio
|
|
childViewAspectRatio = aspectRatio
|
|
|
|
|
+
|
|
|
updateChildWindowBounds()
|
|
updateChildWindowBounds()
|
|
|
})
|
|
})
|
|
|
// 子页侧边栏开关
|
|
// 子页侧边栏开关
|
|
@@ -413,6 +447,10 @@ function createWindow() {
|
|
|
await childView.webContents.session.clearCache()
|
|
await childView.webContents.session.clearCache()
|
|
|
childView.webContents.reloadIgnoringCache();
|
|
childView.webContents.reloadIgnoringCache();
|
|
|
}
|
|
}
|
|
|
|
|
+ if (childSideView && childViewSideUrl) {
|
|
|
|
|
+ await childSideView.webContents.session.clearCache()
|
|
|
|
|
+ childSideView.webContents.reloadIgnoringCache();
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
})
|
|
})
|
|
|
|
|
|