diff --git a/electron/electron.js b/electron/electron.js index c3b5e9cdc..d5ad7bba8 100644 --- a/electron/electron.js +++ b/electron/electron.js @@ -910,6 +910,7 @@ function createWebTabWindow(args) { event: 'stop-loading', id: browserView.webContents.id, }).then(_ => { }) + // 加载完成暗黑模式下把窗口背景色改成白色,避免透明网站背景色穿透 if (nativeTheme.shouldUseDarkColors) { browserView.setBackgroundColor('#FFFFFF') @@ -1320,6 +1321,99 @@ ipcMain.on('webTabDestroyAll', (event) => { event.returnValue = "ok" }) +/** + * 内置浏览器 - 后退 + */ +ipcMain.on('webTabGoBack', (event) => { + const item = currentWebTab() + if (!item) { + return + } + if (item.view.webContents.canGoBack()) { + item.view.webContents.goBack() + // 导航后更新状态 + setTimeout(() => { + utils.onDispatchEvent(webTabWindow.webContents, { + event: 'navigation-state', + id: item.id, + canGoBack: item.view.webContents.canGoBack(), + canGoForward: item.view.webContents.canGoForward() + }).then(_ => { }) + }, 100) + } + event.returnValue = "ok" +}) + +/** + * 内置浏览器 - 前进 + */ +ipcMain.on('webTabGoForward', (event) => { + const item = currentWebTab() + if (!item) { + return + } + if (item.view.webContents.canGoForward()) { + item.view.webContents.goForward() + // 导航后更新状态 + setTimeout(() => { + utils.onDispatchEvent(webTabWindow.webContents, { + event: 'navigation-state', + id: item.id, + canGoBack: item.view.webContents.canGoBack(), + canGoForward: item.view.webContents.canGoForward() + }).then(_ => { }) + }, 100) + } + event.returnValue = "ok" +}) + +/** + * 内置浏览器 - 刷新 + */ +ipcMain.on('webTabReload', (event) => { + const item = currentWebTab() + if (!item) { + return + } + item.view.webContents.reload() + // 刷新完成后会触发 did-stop-loading 事件,在那里会更新导航状态 + event.returnValue = "ok" +}) + +/** + * 内置浏览器 - 停止加载 + */ +ipcMain.on('webTabStop', (event) => { + const item = currentWebTab() + if (!item) { + return + } + item.view.webContents.stop() + event.returnValue = "ok" +}) + +/** + * 内置浏览器 - 获取导航状态 + */ +ipcMain.on('webTabGetNavigationState', (event) => { + const item = currentWebTab() + if (!item) { + return + } + + const canGoBack = item.view.webContents.canGoBack() + const canGoForward = item.view.webContents.canGoForward() + + utils.onDispatchEvent(webTabWindow.webContents, { + event: 'navigation-state', + id: item.id, + canGoBack, + canGoForward + }).then(_ => { }) + + event.returnValue = "ok" +}) + /** * 隐藏窗口(mac、win隐藏,其他关闭) */ diff --git a/electron/render/tabs/assets/css/style.css b/electron/render/tabs/assets/css/style.css index f064cc3a6..fac7c7d94 100644 --- a/electron/render/tabs/assets/css/style.css +++ b/electron/render/tabs/assets/css/style.css @@ -2,7 +2,7 @@ --tab-font-family: -apple-system, 'Segoe UI', roboto, oxygen-sans, ubuntu, cantarell, 'Helvetica Neue', sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'; --tab-font-size: 12px; --tab-transition: background-color 200ms ease-out, color 200ms ease-out; - --tab-cursor: pointer; /* 设置鼠标指针为手型 */ + --tab-cursor: pointer; --tab-color: #7f8792; --tab-background: #EFF0F4; --tab-active-color: #222529; @@ -15,7 +15,8 @@ padding: 0; } -html, body { +html, +body { margin: 0; padding: 0; font-family: 'Roboto', sans-serif; @@ -39,8 +40,43 @@ html, body { -webkit-app-region: drag; } -.nav ul { +/* 导航按钮 */ +.nav-controls { display: flex; + align-items: center; + margin-right: 12px; + -webkit-app-region: none; +} + +.nav-controls div { + display: flex; + justify-content: center; + align-items: center; + width: 32px; + height: 32px; + cursor: pointer; +} + +.nav-controls svg { + width: 16px; + height: 16px; + color: var(--tab-active-color); +} + +.nav-controls .disabled { + cursor: not-allowed !important; +} + +.nav-controls .disabled svg { + opacity: 0.3; +} + +/* 标签 */ +.nav-tabs { + min-width: 0; + flex: 1; + display: flex; + gap: 8px; height: 35px; margin-top: 5px; user-select: none; @@ -48,18 +84,17 @@ html, body { overflow-y: hidden; } -.nav ul::-webkit-scrollbar { +.nav-tabs::-webkit-scrollbar { display: none; } -.nav ul li { +.nav-tabs li { display: inline-flex; position: relative; box-sizing: border-box; align-items: center; height: calc(100% - 5px); padding: 7px 8px; - margin: 0 8px 0 0; min-width: 100px; max-width: 240px; scroll-margin: 12px; @@ -70,24 +105,23 @@ html, body { -webkit-app-region: none; } -.nav ul li:first-child { - margin-left: 8px; +.nav-tabs li:first-child { border-left: none; } -.nav ul li.active { +.nav-tabs li.active { color: var(--tab-active-color); background: var(--tab-active-background); border-radius: 4px; } -.nav ul li.active .tab-icon.background { +.nav-tabs li.active .tab-icon.background { background-image: url(../image/link_normal_selected_icon.png); } -.nav ul li:not(.active)::after { +.nav-tabs li:not(.active)::after { position: absolute; right: 0; width: 1px; @@ -96,22 +130,24 @@ html, body { content: ''; } -.nav ul li:not(.active):last-child::after { +.nav-tabs li:not(.active):last-child::after { content: none; } /* 浏览器打开 */ -.browser { +.nav-browser { flex-shrink: 0; display: flex; align-items: center; height: 40px; padding: 0 14px; + margin: 0 2px; cursor: pointer; background-color: var(--tab-background); -webkit-app-region: none; } -.browser span { + +.nav-browser span { display: inline-block; width: 18px; height: 18px; @@ -161,6 +197,7 @@ html, body { 0% { transform: scale(0.8) rotate(0deg); } + 100% { transform: scale(0.8) rotate(360deg); } @@ -205,18 +242,17 @@ html, body { } /* 不同平台样式 */ -body.win32 .nav ul { - margin-left: 8px; - margin-right: 186px; +body.win32 .nav { + padding-left: 8px; + padding-right: 186px; } -body.win32 .browser { - right: 140px; + +body.darwin .nav { + padding-left: 76px; } -body.darwin .nav ul { - margin-left: 76px; -} -body.darwin.full-screen .nav ul { - margin-left: 8px; + +body.darwin.full-screen .nav { + padding-left: 8px; } /* 暗黑模式 */ @@ -229,15 +265,15 @@ body.darwin.full-screen .nav ul { --tab-close-color: #E3E3E3; } - .nav ul li.active .tab-icon.background { + .nav-tabs li.active .tab-icon.background { background-image: url(../image/dark/link_normal_selected_icon.png); } - .browser span { + .nav-browser span { background-image: url(../image/dark/link_normal_selected_icon.png); } .tab-icon.background { background-image: url(../image/dark/link_normal_icon.png); } -} +} \ No newline at end of file diff --git a/electron/render/tabs/index.html b/electron/render/tabs/index.html index 69f0697e0..5f96a665b 100644 --- a/electron/render/tabs/index.html +++ b/electron/render/tabs/index.html @@ -9,7 +9,19 @@