mirror of
https://github.com/kuaifan/dootask.git
synced 2025-12-13 03:52:50 +00:00
perf: 优化客户端打开服务器链接
This commit is contained in:
parent
0ed9afd1bd
commit
6848b126c5
26
electron/electron.js
vendored
26
electron/electron.js
vendored
@ -56,7 +56,9 @@ function createMainWindow() {
|
||||
const originalUA = mainWindow.webContents.session.getUserAgent() || mainWindow.webContents.getUserAgent()
|
||||
mainWindow.webContents.setUserAgent(originalUA + " MainTaskWindow/" + process.platform + "/" + os.arch() + "/1.0");
|
||||
mainWindow.webContents.setWindowOpenHandler(({url}) => {
|
||||
openExternal(url)
|
||||
utils.onBeforeOpenWindow(mainWindow.webContents, url).then(() => {
|
||||
openExternal(url)
|
||||
})
|
||||
return {action: 'deny'}
|
||||
})
|
||||
electronMenu.webContentsMenu(mainWindow.webContents)
|
||||
@ -157,23 +159,31 @@ function createSubWindow(args) {
|
||||
const originalUA = browser.webContents.session.getUserAgent() || browser.webContents.getUserAgent()
|
||||
browser.webContents.setUserAgent(originalUA + " SubTaskWindow/" + process.platform + "/" + os.arch() + "/1.0" + (args.userAgent ? (" " + args.userAgent) : ""));
|
||||
browser.webContents.setWindowOpenHandler(({url}) => {
|
||||
openExternal(url)
|
||||
utils.onBeforeOpenWindow(browser.webContents, url).then(() => {
|
||||
openExternal(url)
|
||||
})
|
||||
return {action: 'deny'}
|
||||
})
|
||||
electronMenu.webContentsMenu(browser.webContents)
|
||||
|
||||
const hash = args.hash || args.path;
|
||||
if (/^https?:\/\//i.test(hash)) {
|
||||
browser.loadURL(hash).then(_ => {
|
||||
|
||||
})
|
||||
return;
|
||||
}
|
||||
if (devloadUrl) {
|
||||
browser.loadURL(devloadUrl + '#' + hash).then(_ => {
|
||||
|
||||
})
|
||||
} else {
|
||||
browser.loadFile('./public/index.html', {
|
||||
hash
|
||||
}).then(_ => {
|
||||
|
||||
})
|
||||
return;
|
||||
}
|
||||
browser.loadFile('./public/index.html', {
|
||||
hash
|
||||
}).then(_ => {
|
||||
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
19
electron/utils.js
vendored
19
electron/utils.js
vendored
@ -313,6 +313,25 @@ module.exports = {
|
||||
})
|
||||
},
|
||||
|
||||
/**
|
||||
* 新窗口打开事件
|
||||
* @param webContents
|
||||
* @param url
|
||||
* @returns {Promise<unknown>}
|
||||
*/
|
||||
onBeforeOpenWindow(webContents, url) {
|
||||
return new Promise(resolve => {
|
||||
const encodeUrl = encodeURIComponent(url)
|
||||
webContents.executeJavaScript(`if(typeof window.__onBeforeOpenWindow === 'function'){window.__onBeforeOpenWindow({url:decodeURIComponent("${encodeUrl}")})}`, true).then(options => {
|
||||
if (options !== true) {
|
||||
resolve()
|
||||
}
|
||||
}).catch(_ => {
|
||||
resolve()
|
||||
})
|
||||
})
|
||||
},
|
||||
|
||||
/**
|
||||
* 版本比较
|
||||
* @param version1
|
||||
|
||||
@ -264,6 +264,22 @@ export default {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
window.__onBeforeOpenWindow = ({url}) => {
|
||||
if ($A.getDomain(url) != $A.getDomain($A.apiUrl('../'))) {
|
||||
return false;
|
||||
}
|
||||
this.$Electron.sendMessage('windowRouter', {
|
||||
name: `window-${encodeURIComponent(url)}`,
|
||||
path: url,
|
||||
force: false,
|
||||
config: {
|
||||
parent: null,
|
||||
width: Math.min(window.screen.availWidth, 1440),
|
||||
height: Math.min(window.screen.availHeight, 900),
|
||||
},
|
||||
});
|
||||
return true;
|
||||
}
|
||||
this.$Electron.registerMsgListener('dispatch', args => {
|
||||
if (!$A.isJson(args)) {
|
||||
return;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user