perf: 优化客户端子窗口

This commit is contained in:
kuaifan 2024-11-19 20:25:48 +08:00
parent 91533c5cac
commit 1e83c7442a
6 changed files with 39 additions and 14 deletions

View File

@ -310,6 +310,7 @@ function createChildWindow(args) {
const name = args.name || "auto_" + utils.randomString(6);
const wind = childWindow.find(item => item.name == name);
let browser = wind ? wind.browser : null;
let isPreload = false;
if (browser) {
browser.focus();
if (args.force === false) {
@ -340,6 +341,7 @@ function createChildWindow(args) {
// 使用预加载窗口
browser = preloadWindow;
preloadWindow = null;
isPreload = true;
setTimeout(() => onShowWindow(browser), 300)
browser.once('resize', () => setTimeout(() => onShowWindow(browser), 10))
browser.setSize(options.width, options.height);
@ -419,6 +421,10 @@ function createChildWindow(args) {
const hash = args.hash || args.path;
if (/^https?:/i.test(hash)) {
browser.loadURL(hash).then(_ => { }).catch(_ => { })
} else if (isPreload) {
browser.webContents.executeJavaScript(`if(typeof $A.goForward === 'function'){$A.goForward('${hash}')}else{throw new Error('no function')}`, true).catch(() => {
utils.loadUrlOrFile(browser, devloadUrl, hash)
});
} else {
utils.loadUrlOrFile(browser, devloadUrl, hash)
}
@ -1221,7 +1227,7 @@ ipcMain.on('bindScreenshotKey', (event, args) => {
screenshotKey = key
globalShortcut.register(key, () => {
screenshotObj.startCapture().then(_ => {
screenshotObj.view.webContents.executeJavaScript('if(typeof window.__initializeShortcuts===\'undefined\'){window.__initializeShortcuts=true;document.addEventListener(\'keydown\',function(e){console.log(e);if(e.keyCode===27){window.screenshots.cancel()}})}', true).catch(() => {});
screenshotObj.view.webContents.executeJavaScript(`if(typeof window.__initializeShortcuts==='undefined'){window.__initializeShortcuts=true;document.addEventListener('keydown',function(e){console.log(e);if(e.keyCode===27){window.screenshots.cancel()}})}`, true).catch(() => {});
screenshotObj.view.webContents.focus()
})
})

4
electron/utils.js vendored
View File

@ -301,11 +301,11 @@ const utils = {
return new Promise(resolve => {
const contents = app.webContents
if (contents != null) {
contents.executeJavaScript('if(typeof window.__onBeforeUnload === \'function\'){window.__onBeforeUnload()}', true).then(options => {
contents.executeJavaScript(`if(typeof window.__onBeforeUnload === 'function'){window.__onBeforeUnload()}`, true).then(options => {
if (utils.isJson(options)) {
let choice = dialog.showMessageBoxSync(app, options)
if (choice === 1) {
contents.executeJavaScript('if(typeof window.__removeBeforeUnload === \'function\'){window.__removeBeforeUnload()}', true).catch(() => {});
contents.executeJavaScript(`if(typeof window.__removeBeforeUnload === 'function'){window.__removeBeforeUnload()}`, true).catch(() => {});
resolve()
}
} else if (options !== true) {

0
public/js/recorder/frequency.histogram.view.js vendored Normal file → Executable file
View File

0
public/js/recorder/lib.fft.js vendored Normal file → Executable file
View File

2
public/js/recorder/recorder.mp3.min.js vendored Normal file → Executable file

File diff suppressed because one or more lines are too long

View File

@ -127,25 +127,44 @@ if (!isSoftware) {
}
// 加载路由
Vue.prototype.goForward = function(location, isReplace) {
if (typeof location === 'string') {
location = {name: location};
Vue.prototype.goForward = function(route, isReplace) {
// 处理路由格式
if (typeof route === 'string') {
if ($A.strExists(route, '/')) {
if (/^https?:\/\//.test(route)) {
if ($A.getDomain(route) === $A.getDomain($A.mainUrl())) {
route = route.replace(/^https?:\/\/[^\/]+/, '');
} else {
// 处理外部链接
if (isReplace) {
window.location.replace(route);
} else {
window.location.href = route;
}
return;
}
}
route = { path: route };
} else {
route = { name: route };
}
}
// 初始化路由历史
if (app.$store.state.routeHistorys.length === 0) {
app.$store.state.routeHistorys.push(app.$route)
}
if (isReplace === true) {
app.$router.replace(location).then(to => {
// 执行路由跳转
const routerMethod = isReplace ? 'replace' : 'push';
app.$router[routerMethod](route).then(to => {
if (isReplace) {
app.$store.state.routeHistorys.pop();
app.$store.state.routeHistorys.push(to);
}).catch(_ => {});
} else {
app.$router.push(location).then(to => {
} else {
const length = app.$store.state.routeHistorys.push(to)
length > 120 && app.$store.state.routeHistorys.splice(length - 100)
app.$store.state.routeHistoryLast = length >= 2 ? app.$store.state.routeHistorys[length - 2] : {};
}).catch(_ => {});
}
}
}).catch(err => console.warn('路由跳转失败:', err));
};
// 返回路由