@@ -12,7 +12,7 @@ import PermissionVerify, { PermissionVerifyApiGet } from "./permission_verify";
1212import { cacheInstance } from "@App/app/cache" ;
1313import EventEmitter from "eventemitter3" ;
1414import { type RuntimeService } from "./runtime" ;
15- import { getIcon , isFirefox , getCurrentTab , openInCurrentTab , cleanFileName } from "@App/pkg/utils/utils" ;
15+ import { getIcon , isFirefox , openInCurrentTab , cleanFileName } from "@App/pkg/utils/utils" ;
1616import { type SystemConfig } from "@App/pkg/config/config" ;
1717import i18next , { i18nName } from "@App/locales/locales" ;
1818import FileSystemFactory from "@Packages/filesystem/factory" ;
@@ -852,61 +852,47 @@ export default class GMApi {
852852 const url = request . params [ 0 ] ;
853853 const options = request . params [ 1 ] ;
854854 const getNewTabId = async ( ) => {
855- if ( options . useOpen === true ) {
856- // 发送给offscreen页面处理 (使用window.open)
857- const ok = await sendMessage ( this . msgSender , "offscreen/gmApi/openInTab" , { url } ) ;
858- if ( ok ) {
859- // 由于window.open强制在前台打开标签,因此获取状态为{ active:true }的标签即为新标签
860- const tab = await getCurrentTab ( ) ;
861- return tab . id ;
862- } else {
863- // 当新tab被浏览器阻止时window.open()会返回null 视为已经关闭
864- // 似乎在Firefox中禁止在background页面使用window.open(),强制返回null
865- return false ;
866- }
867- } else {
868- const { tabId, windowId } = sender . getExtMessageSender ( ) ;
869- const active = options . active ;
870- const currentTab = await chrome . tabs . get ( tabId ) ;
871- let newTabIndex = - 1 ;
872- if ( options . incognito && ! currentTab . incognito ) {
873- // incognito: "split" 在 normal 里不会看到 incognito
874- // 只能创建新 incognito window
875- // pinned 无效
876- // insert 不重要
877- await chrome . windows . create ( {
878- url,
879- incognito : true ,
880- focused : active ,
881- } ) ;
882- return 0 ;
883- }
884- if ( ( typeof options . insert === "number" || options . insert === true ) && currentTab && currentTab . index >= 0 ) {
885- // insert 为 boolean 时,插入至当前Tab下一格 (TM行为)
886- // insert 为 number 时,插入至相对位置 (SC独自)
887- const insert = + options . insert ;
888- newTabIndex = currentTab . index + insert ;
889- if ( newTabIndex < 0 ) newTabIndex = 0 ;
890- }
891- const createProperties = {
855+ const { tabId, windowId } = sender . getExtMessageSender ( ) ;
856+ const active = options . active ;
857+ const currentTab = await chrome . tabs . get ( tabId ) ;
858+ let newTabIndex = - 1 ;
859+ if ( options . incognito && ! currentTab . incognito ) {
860+ // incognito: "split" 在 normal 里不会看到 incognito
861+ // 只能创建新 incognito window
862+ // pinned 无效
863+ // insert 不重要
864+ await chrome . windows . create ( {
892865 url,
893- active : active ,
894- } as chrome . tabs . CreateProperties ;
895- if ( options . setParent ) {
896- // SC 预设 setParent: true 以避免不可预计的问题
897- createProperties . openerTabId = tabId === - 1 ? undefined : tabId ;
898- createProperties . windowId = windowId === - 1 ? undefined : windowId ;
899- }
900- if ( options . pinned ) {
901- // VM/FM行为
902- createProperties . pinned = true ;
903- } else if ( newTabIndex >= 0 ) {
904- // insert option; pinned 情况下无效
905- createProperties . index = newTabIndex ;
906- }
907- const tab = await chrome . tabs . create ( createProperties ) ;
908- return tab . id ;
866+ incognito : true ,
867+ focused : active ,
868+ } ) ;
869+ return 0 ;
870+ }
871+ if ( ( typeof options . insert === "number" || options . insert === true ) && currentTab && currentTab . index >= 0 ) {
872+ // insert 为 boolean 时,插入至当前Tab下一格 (TM行为)
873+ // insert 为 number 时,插入至相对位置 (SC独自)
874+ const insert = + options . insert ;
875+ newTabIndex = currentTab . index + insert ;
876+ if ( newTabIndex < 0 ) newTabIndex = 0 ;
877+ }
878+ const createProperties = {
879+ url,
880+ active : active ,
881+ } as chrome . tabs . CreateProperties ;
882+ if ( options . setParent ) {
883+ // SC 预设 setParent: true 以避免不可预计的问题
884+ createProperties . openerTabId = tabId === - 1 ? undefined : tabId ;
885+ createProperties . windowId = windowId === - 1 ? undefined : windowId ;
886+ }
887+ if ( options . pinned ) {
888+ // VM/FM行为
889+ createProperties . pinned = true ;
890+ } else if ( newTabIndex >= 0 ) {
891+ // insert option; pinned 情况下无效
892+ createProperties . index = newTabIndex ;
909893 }
894+ const tab = await chrome . tabs . create ( createProperties ) ;
895+ return tab . id ;
910896 } ;
911897 const tabId = await getNewTabId ( ) ;
912898 if ( tabId ) {
0 commit comments