perf: 优化客户端

This commit is contained in:
kuaifan 2024-12-21 12:34:08 +08:00
parent 07254c9f27
commit 94af3822d8
3 changed files with 63 additions and 43 deletions

25
electron/electron.js vendored
View File

@ -578,8 +578,6 @@ function createWebTabWindow(args) {
// 创建父级窗口
if (!webTabWindow) {
let config = Object.assign(args.config || {}, userConf.get('webTabWindow', {}));
let webPreferences = args.webPreferences || {};
const titleBarOverlay = {
height: webTabHeight
}
@ -600,14 +598,14 @@ function createWebTabWindow(args) {
titleBarStyle: 'hidden',
titleBarOverlay,
backgroundColor: nativeTheme.shouldUseDarkColors ? '#3B3B3D' : '#EFF0F4',
webPreferences: Object.assign({
webPreferences: {
preload: path.join(__dirname, 'electron-preload.js'),
webSecurity: true,
nodeIntegration: true,
contextIsolation: true,
nativeWindowOpen: true
}, webPreferences),
}, config))
},
}, userConf.get('webTabWindow', {})))
webTabWindow.on('resize', () => {
resizeWebTab(0)
@ -672,15 +670,20 @@ function createWebTabWindow(args) {
webTabWindow.show();
// 创建 tab 子窗口
const browserView = new BrowserView({
const viewOptions = Object.assign({
useHTMLTitleAndIcon: true,
useLoadingView: true,
useErrorView: true,
webPreferences: {
preload: path.join(__dirname, 'electron-preload.js'),
}
})
if (nativeTheme.shouldUseDarkColors) {
}, args.config || {})
viewOptions.webPreferences = Object.assign({
preload: path.join(__dirname, 'electron-preload.js'),
nodeIntegration: true,
contextIsolation: true
}, args.webPreferences || {})
const browserView = new BrowserView(viewOptions)
if (args.backgroundColor) {
browserView.setBackgroundColor(args.backgroundColor)
} else if (nativeTheme.shouldUseDarkColors) {
browserView.setBackgroundColor('#575757')
} else {
browserView.setBackgroundColor('#FFFFFF')

View File

@ -180,6 +180,23 @@ export default {
return type;
},
async getUserData() {
if (!this.userInfo.userid && this.userId && this.userToken) {
this.$store.dispatch("showSpinner", 300).then(_ => {})
try {
await this.$store.dispatch("getUserInfo");
} catch (e) {
console.warn(e);
} finally {
this.$store.dispatch("hiddenSpinner").then(_ => {})
}
}
return {
"id": String(this.userInfo.userid),
"name": this.userInfo.nickname
}
},
loadFile(keyAppend = '') {
if (this.docEditor !== null) {
this.docEditor.destroyEditor();
@ -199,35 +216,32 @@ export default {
if (this.historyId > 0) {
fileKey += `-${this.historyId}`
}
const config = {
"document": {
"fileType": this.fileType,
"title": fileName,
"key": fileKey,
"url": `http://nginx/api/${this.fileUrl}`,
},
"editorConfig": {
"mode": "edit",
"lang": lang,
"user": {
"id": String(this.userInfo.userid),
"name": this.userInfo.nickname
},
"customization": {
"uiTheme": this.themeName === 'dark' ? "theme-dark" : "theme-classic-light",
"forcesave": true,
"help": false,
},
"callbackUrl": `http://nginx/api/file/content/office?id=${codeId}&dootask-token=${this.userToken}`,
},
"events": {
"onDocumentReady": this.onDocumentReady,
},
};
if (/\/hideenOfficeTitle\//.test(window.navigator.userAgent)) {
config.document.title = " ";
}
(async _ => {
const config = {
"document": {
"fileType": this.fileType,
"title": fileName,
"key": fileKey,
"url": `http://nginx/api/${this.fileUrl}`,
},
"editorConfig": {
"mode": "edit",
"lang": lang,
"user": await this.getUserData(),
"customization": {
"uiTheme": this.themeName === 'dark' ? "theme-dark" : "theme-classic-light",
"forcesave": true,
"help": false,
},
"callbackUrl": `http://nginx/api/file/content/office?id=${codeId}&dootask-token=${this.userToken}`,
},
"events": {
"onDocumentReady": this.onDocumentReady,
},
};
if (/\/hideenOfficeTitle\//.test(window.navigator.userAgent)) {
config.document.title = " ";
}
if (this.readOnly || this.historyId > 0) {
config.editorConfig.mode = "view";
config.editorConfig.callbackUrl = null;

View File

@ -1107,8 +1107,8 @@ export default {
* @param params
*/
async openChildWindow({dispatch}, params) {
const path = await dispatch("userUrl", params.path)
$A.Electron.sendMessage('openChildWindow', Object.assign(params, {path}))
params.path = await dispatch("userUrl", params.path)
$A.Electron.sendMessage('openChildWindow', params)
},
/**
@ -1117,10 +1117,13 @@ export default {
* @param url
*/
async openWebTabWindow({dispatch}, url) {
const params = {url}
if ($A.getDomain(url) == $A.getDomain($A.mainUrl())) {
url = await dispatch("userUrl", url)
params.url = await dispatch("userUrl", url)
} else {
params.webPreferences = {contextIsolation: false}
}
$A.Electron.sendMessage('openWebTabWindow', {url})
$A.Electron.sendMessage('openWebTabWindow', params)
},
/** *****************************************************************************************/