diff --git a/electron/electron.js b/electron/electron.js index ff8ace348..f41eb29d1 100644 --- a/electron/electron.js +++ b/electron/electron.js @@ -41,7 +41,7 @@ const config = require('./package.json'); const electronDown = require("./electron-down"); const electronMenu = require("./electron-menu"); const { startMCPServer, stopMCPServer } = require("./lib/mcp"); -const {onRenderer} = require("./lib/renderer"); +const {onRenderer, renderer} = require("./lib/renderer"); const {onExport} = require("./lib/pdf-export"); const {allowedCalls, isWin} = require("./lib/other"); @@ -341,10 +341,10 @@ function createMainWindow() { // 新窗口处理 mainWindow.webContents.setWindowOpenHandler(({url}) => { if (allowedCalls.test(url)) { - openExternal(url).catch(() => {}) + renderer.openExternal(url).catch(() => {}) } else { utils.onBeforeOpenWindow(mainWindow.webContents, url).then(() => { - openExternal(url).catch(() => {}) + renderer.openExternal(url).catch(() => {}) }) } return {action: 'deny'} @@ -600,10 +600,10 @@ function createChildWindow(args) { // 新窗口处理 browser.webContents.setWindowOpenHandler(({url}) => { if (allowedCalls.test(url)) { - openExternal(url).catch(() => {}) + renderer.openExternal(url).catch(() => {}) } else { utils.onBeforeOpenWindow(browser.webContents, url).then(() => { - openExternal(url).catch(() => {}) + renderer.openExternal(url).catch(() => {}) }) } return {action: 'deny'} @@ -891,9 +891,9 @@ function createWebTabWindow(args) { }) browserView.webContents.setWindowOpenHandler(({url}) => { if (allowedCalls.test(url)) { - openExternal(url).catch(() => {}) + renderer.openExternal(url).catch(() => {}) } else { - createWebTabWindow({url}) + createWebTabWindow({url, afterId: browserView.webContents.id}) } return {action: 'deny'} }) @@ -941,9 +941,6 @@ function createWebTabWindow(args) { }).then(_ => { }) }) browserView.webContents.on('did-start-loading', _ => { - webTabView.forEach(({id: vid, view}) => { - view.setVisible(vid === browserView.webContents.id) - }) if (!webTabWindow) return utils.onDispatchEvent(webTabWindow.webContents, { event: 'start-loading', @@ -981,10 +978,22 @@ function createWebTabWindow(args) { electronMenu.webContentsMenu(browserView.webContents, true) browserView.webContents.loadURL(args.url).then(_ => { }).catch(_ => { }) + browserView.setVisible(true) webTabWindow.contentView.addChildView(browserView) - webTabView.push({ + + // 确定插入位置 + let insertIndex = webTabView.length + if (args.afterId) { + const afterIndex = webTabView.findIndex(item => item.id === args.afterId) + if (afterIndex > -1) { + insertIndex = afterIndex + 1 + } + } + + // 插入到指定位置 + webTabView.splice(insertIndex, 0, { id: browserView.webContents.id, view: browserView }) @@ -993,6 +1002,7 @@ function createWebTabWindow(args) { event: 'create', id: browserView.webContents.id, url: args.url, + afterId: args.afterId, }).then(_ => { }) activateWebTab(browserView.webContents.id) } @@ -1350,6 +1360,24 @@ ipcMain.on('webTabActivate', (event, id) => { event.returnValue = "ok" }) +/** + * 内置浏览器 - 重排标签顺序 + * @param newOrder 新的标签ID顺序数组 + */ +ipcMain.on('webTabReorder', (event, newOrder) => { + if (!Array.isArray(newOrder) || newOrder.length === 0) { + event.returnValue = "ok" + return + } + // 根据新顺序重排 webTabView 数组 + webTabView.sort((a, b) => { + const indexA = newOrder.indexOf(a.id) + const indexB = newOrder.indexOf(b.id) + return indexA - indexB + }) + event.returnValue = "ok" +}) + /** * 内置浏览器 - 关闭标签 * @param id @@ -1367,7 +1395,7 @@ ipcMain.on('webTabExternal', (event) => { if (!item) { return } - openExternal(item.view.webContents.getURL()).catch(() => {}) + renderer.openExternal(item.view.webContents.getURL()).catch(() => {}) event.returnValue = "ok" }) diff --git a/electron/render/tabs/assets/css/style.css b/electron/render/tabs/assets/css/style.css index d93bc9b74..cf88de748 100644 --- a/electron/render/tabs/assets/css/style.css +++ b/electron/render/tabs/assets/css/style.css @@ -34,9 +34,11 @@ body { font-feature-settings: 'clig', 'kern'; flex: 1; width: 0; + height: 40px; display: flex; - cursor: default; + align-items: center; background-color: var(--tab-background); + cursor: default; -webkit-app-region: drag; } @@ -77,8 +79,6 @@ body { flex: 1; display: flex; gap: 8px; - height: 35px; - margin-top: 5px; user-select: none; overflow-x: auto; overflow-y: hidden; @@ -89,15 +89,17 @@ body { } .nav-tabs li { - display: inline-flex; + flex: 1; + display: flex; position: relative; box-sizing: border-box; align-items: center; height: calc(100% - 5px); padding: 7px 8px; - min-width: 100px; - max-width: 240px; + min-width: 56px; + max-width: 220px; scroll-margin: 12px; + border-radius: 4px; font-size: var(--tab-font-size); color: var(--tab-color); cursor: var(--tab-cursor); @@ -113,7 +115,6 @@ body { .nav-tabs li.active { color: var(--tab-active-color); background: var(--tab-active-background); - border-radius: 4px; } .nav-tabs li.active .tab-icon.background { @@ -254,6 +255,89 @@ body.darwin.full-screen .nav { padding-left: 8px; } +/* Sortable 拖拽样式 */ +.nav-tabs li.sortable-ghost { + opacity: 0.4; + background: var(--tab-active-background); + border-radius: 4px; +} + +.nav-tabs li.sortable-chosen { + background: var(--tab-active-background); + border-radius: 4px; + box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15); +} + +.nav-tabs li.sortable-drag { + opacity: 1; +} + +/* fallback 模式下克隆元素会被添加到 body,需要全局样式 */ +.sortable-fallback { + font-family: var(--tab-font-family); + font-size: var(--tab-font-size); + display: inline-flex !important; + align-items: center; + height: 30px; + padding: 7px 8px; + min-width: 100px; + max-width: 240px; + color: var(--tab-active-color); + background: var(--tab-active-background) !important; + border-radius: 4px; + box-shadow: 0 4px 12px rgba(0, 0, 0, 0.25); + opacity: 0.95 !important; + cursor: grabbing; + z-index: 9999; +} + +.sortable-fallback .tab-icon { + display: inline-block; + flex-shrink: 0; + width: 16px; + height: 16px; + background-size: cover; +} + +.sortable-fallback .tab-icon.background { + background-image: url(../image/link_normal_selected_icon.png); +} + +.sortable-fallback .tab-title { + display: inline-block; + flex: 1; + margin: 0 8px; + overflow: hidden; + line-height: 150%; + text-overflow: ellipsis; + white-space: nowrap; +} + +.sortable-fallback .tab-close { + display: inline-block; + width: 14px; + height: 14px; + margin-right: 2px; + position: relative; +} + +.sortable-fallback .tab-close::after, +.sortable-fallback .tab-close::before { + position: absolute; + top: 50%; + right: 50%; + transform: translate(50%, -50%) scale(0.9) rotate(45deg); + content: ""; + width: 2px; + height: 11px; + border-radius: 3px; + background-color: var(--tab-close-color); +} + +.sortable-fallback .tab-close::before { + transform: translate(50%, -50%) scale(0.9) rotate(-45deg); +} + /* 暗黑模式 */ @media (prefers-color-scheme: dark) { :root { @@ -275,4 +359,13 @@ body.darwin.full-screen .nav { .tab-icon.background { background-image: url(../image/dark/link_normal_icon.png); } + + /* 暗黑模式下 fallback 样式 */ + .sortable-fallback { + box-shadow: 0 4px 12px rgba(0, 0, 0, 0.5); + } + + .sortable-fallback .tab-icon.background { + background-image: url(../image/dark/link_normal_selected_icon.png); + } } diff --git a/electron/render/tabs/assets/js/Sortable.min.js b/electron/render/tabs/assets/js/Sortable.min.js new file mode 100644 index 000000000..95423a649 --- /dev/null +++ b/electron/render/tabs/assets/js/Sortable.min.js @@ -0,0 +1,2 @@ +/*! Sortable 1.15.6 - MIT | git://github.com/SortableJS/Sortable.git */ +!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t=t||self).Sortable=e()}(this,function(){"use strict";function e(e,t){var n,o=Object.keys(e);return Object.getOwnPropertySymbols&&(n=Object.getOwnPropertySymbols(e),t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),o.push.apply(o,n)),o}function I(o){for(var t=1;tt.length)&&(e=t.length);for(var n=0,o=new Array(e);n"===e[0]&&(e=e.substring(1)),t))try{if(t.matches)return t.matches(e);if(t.msMatchesSelector)return t.msMatchesSelector(e);if(t.webkitMatchesSelector)return t.webkitMatchesSelector(e)}catch(t){return}}function g(t){return t.host&&t!==document&&t.host.nodeType?t.host:t.parentNode}function P(t,e,n,o){if(t){n=n||document;do{if(null!=e&&(">"!==e[0]||t.parentNode===n)&&f(t,e)||o&&t===n)return t}while(t!==n&&(t=g(t)))}return null}var m,v=/\s+/g;function k(t,e,n){var o;t&&e&&(t.classList?t.classList[n?"add":"remove"](e):(o=(" "+t.className+" ").replace(v," ").replace(" "+e+" "," "),t.className=(o+(n?" "+e:"")).replace(v," ")))}function R(t,e,n){var o=t&&t.style;if(o){if(void 0===n)return document.defaultView&&document.defaultView.getComputedStyle?n=document.defaultView.getComputedStyle(t,""):t.currentStyle&&(n=t.currentStyle),void 0===e?n:n[e];o[e=!(e in o||-1!==e.indexOf("webkit"))?"-webkit-"+e:e]=n+("string"==typeof n?"":"px")}}function b(t,e){var n="";if("string"==typeof t)n=t;else do{var o=R(t,"transform")}while(o&&"none"!==o&&(n=o+" "+n),!e&&(t=t.parentNode));var i=window.DOMMatrix||window.WebKitCSSMatrix||window.CSSMatrix||window.MSCSSMatrix;return i&&new i(n)}function D(t,e,n){if(t){var o=t.getElementsByTagName(e),i=0,r=o.length;if(n)for(;i=n.left-e&&i<=n.right+e,e=r>=n.top-e&&r<=n.bottom+e;return o&&e?a=t:void 0}}),a);if(e){var n,o={};for(n in t)t.hasOwnProperty(n)&&(o[n]=t[n]);o.target=o.rootEl=e,o.preventDefault=void 0,o.stopPropagation=void 0,e[K]._onDragOver(o)}}var i,r,a}function Ft(t){Z&&Z.parentNode[K]._isOutsideThisEl(t.target)}function jt(t,e){if(!t||!t.nodeType||1!==t.nodeType)throw"Sortable: `el` must be an HTMLElement, not ".concat({}.toString.call(t));this.el=t,this.options=e=a({},e),t[K]=this;var n,o,i={group:null,sort:!0,disabled:!1,store:null,handle:null,draggable:/^[uo]l$/i.test(t.nodeName)?">li":">*",swapThreshold:1,invertSwap:!1,invertedSwapThreshold:null,removeCloneOnHide:!0,direction:function(){return kt(t,this.options)},ghostClass:"sortable-ghost",chosenClass:"sortable-chosen",dragClass:"sortable-drag",ignore:"a, img",filter:null,preventOnFilter:!0,animation:0,easing:null,setData:function(t,e){t.setData("Text",e.textContent)},dropBubble:!1,dragoverBubble:!1,dataIdAttr:"data-id",delay:0,delayOnTouchOnly:!1,touchStartThreshold:(Number.parseInt?Number:window).parseInt(window.devicePixelRatio,10)||1,forceFallback:!1,fallbackClass:"sortable-fallback",fallbackOnBody:!1,fallbackTolerance:0,fallbackOffset:{x:0,y:0},supportPointer:!1!==jt.supportPointer&&"PointerEvent"in window&&(!u||c),emptyInsertThreshold:5};for(n in z.initializePlugins(this,t,i),i)n in e||(e[n]=i[n]);for(o in Rt(e),this)"_"===o.charAt(0)&&"function"==typeof this[o]&&(this[o]=this[o].bind(this));this.nativeDraggable=!e.forceFallback&&It,this.nativeDraggable&&(this.options.touchStartThreshold=1),e.supportPointer?h(t,"pointerdown",this._onTapStart):(h(t,"mousedown",this._onTapStart),h(t,"touchstart",this._onTapStart)),this.nativeDraggable&&(h(t,"dragover",this),h(t,"dragenter",this)),St.push(this.el),e.store&&e.store.get&&this.sort(e.store.get(this)||[]),a(this,A())}function Ht(t,e,n,o,i,r,a,l){var s,c,u=t[K],d=u.options.onMove;return!window.CustomEvent||y||w?(s=document.createEvent("Event")).initEvent("move",!0,!0):s=new CustomEvent("move",{bubbles:!0,cancelable:!0}),s.to=e,s.from=t,s.dragged=n,s.draggedRect=o,s.related=i||e,s.relatedRect=r||X(e),s.willInsertAfter=l,s.originalEvent=a,t.dispatchEvent(s),c=d?d.call(u,s,a):c}function Lt(t){t.draggable=!1}function Kt(){xt=!1}function Wt(t){return setTimeout(t,0)}function zt(t){return clearTimeout(t)}jt.prototype={constructor:jt,_isOutsideThisEl:function(t){this.el.contains(t)||t===this.el||(vt=null)},_getDirection:function(t,e){return"function"==typeof this.options.direction?this.options.direction.call(this,t,e,Z):this.options.direction},_onTapStart:function(e){if(e.cancelable){var n=this,o=this.el,t=this.options,i=t.preventOnFilter,r=e.type,a=e.touches&&e.touches[0]||e.pointerType&&"touch"===e.pointerType&&e,l=(a||e).target,s=e.target.shadowRoot&&(e.path&&e.path[0]||e.composedPath&&e.composedPath()[0])||l,c=t.filter;if(!function(t){Ot.length=0;var e=t.getElementsByTagName("input"),n=e.length;for(;n--;){var o=e[n];o.checked&&Ot.push(o)}}(o),!Z&&!(/mousedown|pointerdown/.test(r)&&0!==e.button||t.disabled)&&!s.isContentEditable&&(this.nativeDraggable||!u||!l||"SELECT"!==l.tagName.toUpperCase())&&!((l=P(l,t.draggable,o,!1))&&l.animated||et===l)){if(it=j(l),at=j(l,t.draggable),"function"==typeof c){if(c.call(this,e,l,this))return V({sortable:n,rootEl:s,name:"filter",targetEl:l,toEl:o,fromEl:o}),U("filter",n,{evt:e}),void(i&&e.preventDefault())}else if(c=c&&c.split(",").some(function(t){if(t=P(s,t.trim(),o,!1))return V({sortable:n,rootEl:t,name:"filter",targetEl:l,fromEl:o,toEl:o}),U("filter",n,{evt:e}),!0}))return void(i&&e.preventDefault());t.handle&&!P(s,t.handle,o,!1)||this._prepareDragStart(e,a,l)}}},_prepareDragStart:function(t,e,n){var o,i=this,r=i.el,a=i.options,l=r.ownerDocument;n&&!Z&&n.parentNode===r&&(o=X(n),J=r,$=(Z=n).parentNode,tt=Z.nextSibling,et=n,st=a.group,ut={target:jt.dragged=Z,clientX:(e||t).clientX,clientY:(e||t).clientY},ft=ut.clientX-o.left,gt=ut.clientY-o.top,this._lastX=(e||t).clientX,this._lastY=(e||t).clientY,Z.style["will-change"]="all",o=function(){U("delayEnded",i,{evt:t}),jt.eventCanceled?i._onDrop():(i._disableDelayedDragEvents(),!s&&i.nativeDraggable&&(Z.draggable=!0),i._triggerDragStart(t,e),V({sortable:i,name:"choose",originalEvent:t}),k(Z,a.chosenClass,!0))},a.ignore.split(",").forEach(function(t){D(Z,t.trim(),Lt)}),h(l,"dragover",Bt),h(l,"mousemove",Bt),h(l,"touchmove",Bt),a.supportPointer?(h(l,"pointerup",i._onDrop),this.nativeDraggable||h(l,"pointercancel",i._onDrop)):(h(l,"mouseup",i._onDrop),h(l,"touchend",i._onDrop),h(l,"touchcancel",i._onDrop)),s&&this.nativeDraggable&&(this.options.touchStartThreshold=4,Z.draggable=!0),U("delayStart",this,{evt:t}),!a.delay||a.delayOnTouchOnly&&!e||this.nativeDraggable&&(w||y)?o():jt.eventCanceled?this._onDrop():(a.supportPointer?(h(l,"pointerup",i._disableDelayedDrag),h(l,"pointercancel",i._disableDelayedDrag)):(h(l,"mouseup",i._disableDelayedDrag),h(l,"touchend",i._disableDelayedDrag),h(l,"touchcancel",i._disableDelayedDrag)),h(l,"mousemove",i._delayedDragTouchMoveHandler),h(l,"touchmove",i._delayedDragTouchMoveHandler),a.supportPointer&&h(l,"pointermove",i._delayedDragTouchMoveHandler),i._dragStartTimer=setTimeout(o,a.delay)))},_delayedDragTouchMoveHandler:function(t){t=t.touches?t.touches[0]:t;Math.max(Math.abs(t.clientX-this._lastX),Math.abs(t.clientY-this._lastY))>=Math.floor(this.options.touchStartThreshold/(this.nativeDraggable&&window.devicePixelRatio||1))&&this._disableDelayedDrag()},_disableDelayedDrag:function(){Z&&Lt(Z),clearTimeout(this._dragStartTimer),this._disableDelayedDragEvents()},_disableDelayedDragEvents:function(){var t=this.el.ownerDocument;p(t,"mouseup",this._disableDelayedDrag),p(t,"touchend",this._disableDelayedDrag),p(t,"touchcancel",this._disableDelayedDrag),p(t,"pointerup",this._disableDelayedDrag),p(t,"pointercancel",this._disableDelayedDrag),p(t,"mousemove",this._delayedDragTouchMoveHandler),p(t,"touchmove",this._delayedDragTouchMoveHandler),p(t,"pointermove",this._delayedDragTouchMoveHandler)},_triggerDragStart:function(t,e){e=e||"touch"==t.pointerType&&t,!this.nativeDraggable||e?this.options.supportPointer?h(document,"pointermove",this._onTouchMove):h(document,e?"touchmove":"mousemove",this._onTouchMove):(h(Z,"dragend",this),h(J,"dragstart",this._onDragStart));try{document.selection?Wt(function(){document.selection.empty()}):window.getSelection().removeAllRanges()}catch(t){}},_dragStarted:function(t,e){var n;Dt=!1,J&&Z?(U("dragStarted",this,{evt:e}),this.nativeDraggable&&h(document,"dragover",Ft),n=this.options,t||k(Z,n.dragClass,!1),k(Z,n.ghostClass,!0),jt.active=this,t&&this._appendGhost(),V({sortable:this,name:"start",originalEvent:e})):this._nulling()},_emulateDragOver:function(){if(dt){this._lastX=dt.clientX,this._lastY=dt.clientY,Xt();for(var t=document.elementFromPoint(dt.clientX,dt.clientY),e=t;t&&t.shadowRoot&&(t=t.shadowRoot.elementFromPoint(dt.clientX,dt.clientY))!==e;)e=t;if(Z.parentNode[K]._isOutsideThisEl(t),e)do{if(e[K])if(e[K]._onDragOver({clientX:dt.clientX,clientY:dt.clientY,target:t,rootEl:e})&&!this.options.dragoverBubble)break}while(e=g(t=e));Yt()}},_onTouchMove:function(t){if(ut){var e=this.options,n=e.fallbackTolerance,o=e.fallbackOffset,i=t.touches?t.touches[0]:t,r=Q&&b(Q,!0),a=Q&&r&&r.a,l=Q&&r&&r.d,e=At&&wt&&E(wt),a=(i.clientX-ut.clientX+o.x)/(a||1)+(e?e[0]-Tt[0]:0)/(a||1),l=(i.clientY-ut.clientY+o.y)/(l||1)+(e?e[1]-Tt[1]:0)/(l||1);if(!jt.active&&!Dt){if(n&&Math.max(Math.abs(i.clientX-this._lastX),Math.abs(i.clientY-this._lastY))E.right+10||S.clientY>x.bottom&&S.clientX>x.left:S.clientY>E.bottom+10||S.clientX>x.right&&S.clientY>x.top)||m.animated)){if(m&&(t=n,e=r,C=X(B((_=this).el,0,_.options,!0)),_=L(_.el,_.options,Q),e?t.clientX<_.left-10||t.clientYUntitled +
@@ -22,7 +23,7 @@