Skip to content

Commit dcf96e2

Browse files
committed
perf: 优化访问链接
1 parent d4697cb commit dcf96e2

File tree

4 files changed

+40
-20
lines changed

4 files changed

+40
-20
lines changed

app/Http/Controllers/IndexController.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -471,15 +471,15 @@ public function online__preview()
471471
action: "eeuiAppSendMessage",
472472
data: [
473473
{
474-
action: 'setPageData',
474+
action: 'setPageData', // 设置页面数据
475475
data: {
476476
showProgress: true,
477477
titleFixed: true,
478478
urlFixed: true,
479479
}
480480
},
481481
{
482-
action: 'createTarget',
482+
action: 'createTarget', // 创建目标(访问新地址)
483483
url: "{$redirectUrl}",
484484
}
485485
]

electron/electron.js

+15-8
Original file line numberDiff line numberDiff line change
@@ -442,11 +442,16 @@ function createChildWindow(args) {
442442
// 加载地址
443443
const hash = `${args.hash || args.path}`;
444444
if (/^https?:/i.test(hash)) {
445-
browser.loadURL(hash).then(_ => { }).catch(_ => { })
445+
browser.loadURL(hash)
446+
.then(_ => { })
447+
.catch(_ => { })
446448
} else if (isPreload) {
447-
browser.webContents.executeJavaScript(`if(typeof window.__initializeApp === 'function'){window.__initializeApp('${hash}')}else{throw new Error('no function')}`, true).catch(() => {
448-
utils.loadUrlOrFile(browser, devloadUrl, hash)
449-
});
449+
browser
450+
.webContents
451+
.executeJavaScript(`if(typeof window.__initializeApp === 'function'){window.__initializeApp('${hash}')}else{throw new Error('no function')}`, true)
452+
.catch(() => {
453+
utils.loadUrlOrFile(browser, devloadUrl, hash)
454+
});
450455
} else {
451456
utils.loadUrlOrFile(browser, devloadUrl, hash)
452457
}
@@ -567,10 +572,6 @@ function createWebTabWindow(args) {
567572
args = {url: args}
568573
}
569574

570-
if (!allowedUrls.test(args.url)) {
571-
return;
572-
}
573-
574575
// 创建父级窗口
575576
if (!webTabWindow) {
576577
const titleBarOverlay = {
@@ -602,6 +603,12 @@ function createWebTabWindow(args) {
602603
},
603604
}, userConf.get('webTabWindow', {})))
604605

606+
const originalClose = webTabWindow.close;
607+
webTabWindow.close = function() {
608+
webTabClosedByShortcut = true;
609+
return originalClose.apply(this, arguments);
610+
};
611+
605612
webTabWindow.on('resize', () => {
606613
resizeWebTab(0)
607614
})

electron/render/tabs/assets/css/style.css

+11-6
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,17 @@ html, body {
2323
color: #333;
2424
}
2525

26+
.app {
27+
display: flex;
28+
align-items: center;
29+
}
30+
2631
.nav {
2732
font-family: var(--tab-font-family);
2833
font-feature-settings: 'clig', 'kern';
34+
flex: 1;
35+
width: 0;
2936
display: flex;
30-
width: 100%;
3137
cursor: default;
3238
background-color: var(--tab-background);
3339
-webkit-app-region: drag;
@@ -36,7 +42,7 @@ html, body {
3642
.nav ul {
3743
display: flex;
3844
height: 35px;
39-
margin: 5px 46px 0 0;
45+
margin-top: 5px;
4046
user-select: none;
4147
overflow-x: auto;
4248
overflow-y: hidden;
@@ -96,14 +102,13 @@ html, body {
96102

97103
/* 浏览器打开 */
98104
.browser {
99-
position: absolute;
100-
top: 0;
101-
right: 0;
105+
flex-shrink: 0;
102106
display: flex;
103107
align-items: center;
104-
height: 38px;
108+
height: 40px;
105109
padding: 0 14px;
106110
cursor: pointer;
111+
background-color: var(--tab-background);
107112
-webkit-app-region: none;
108113
}
109114
.browser span {

electron/render/tabs/index.html

+12-4
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
</li>
2121
</ul>
2222
</div>
23-
<div v-if="tabs.length > 0" class="browser" @click="onBrowser">
23+
<div v-if="canBrowser" class="browser" @click="onBrowser">
2424
<span></span>
2525
</div>
2626
</div>
@@ -119,15 +119,23 @@
119119
}
120120
},
121121
computed: {
122+
activeItem() {
123+
if (this.tabs.length === 0) {
124+
return null
125+
}
126+
return this.tabs.find(item => item.id === this.activeId)
127+
},
122128
pageTitle() {
123-
const activeItem = this.tabs.find(item => item.id === this.activeId)
124-
return activeItem ? activeItem.title : 'Untitled'
129+
return this.activeItem ? this.activeItem.title : 'Untitled'
130+
},
131+
canBrowser() {
132+
return !(this.activeItem && /^file:/.test(this.activeItem.url))
125133
}
126134
},
127135
watch: {
128136
pageTitle(title) {
129137
document.title = title;
130-
}
138+
},
131139
},
132140
methods: {
133141
onSwitch(item) {

0 commit comments

Comments
 (0)