dsh-builtin-browser 1.0.4 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +16 -1
- package/desktop-bridge/desktop-identity.json +10 -2
- package/desktop-bridge/install.mjs +28 -2
- package/docs/issue-replies-2026-11-28.md +141 -0
- package/dsh-host-patch/apply.mjs +1 -1
- package/dsh-host-patch/rc3.json +4 -4
- package/dsh-host-patch/rc5.json +4 -4
- package/dsh-host-patch/v023-alpha2.json +2 -2
- package/lib/browser-electron/bridge-status.js +24 -1
- package/lib/browser-electron/desktop-identity.js +47 -8
- package/lib/client.js +2 -1
- package/native-host/install.mjs +5 -0
- package/package.json +1 -1
- package/src/browser-electron/bridge-status.ts +28 -2
- package/src/browser-electron/desktop-identity.ts +55 -8
- package/src/client/definition.tsx +36 -36
- package/src/client/index.ts +323 -323
- package/src/client/settings/panel.ts +2773 -2768
- package/src/tool-browser/tools-observation.ts +474 -474
package/src/client/index.ts
CHANGED
|
@@ -1,333 +1,333 @@
|
|
|
1
|
-
import { CLIENT_VERSION_ROUTE } from '../../assets/browser-policy.mjs'
|
|
2
|
-
/** Register the HTTP(S) Browser tab type in the right Sidebar. */
|
|
3
|
-
import type { ShortcutCommandId } from '@deepseek-ai/dsh-client-shortcuts/client'
|
|
4
|
-
import type { Context } from '@deepseek-ai/cordis'
|
|
5
|
-
import type {} from '@deepseek-ai/dsh-client-locale/client'
|
|
6
|
-
import type {} from '@deepseek-ai/dsh-client-ui-renderer/client'
|
|
7
|
-
import type {} from '@deepseek-ai/dsh-client-ui-session/client'
|
|
8
|
-
import type {} from '@deepseek-ai/dsh-client-ui-sidebar-right/client'
|
|
9
|
-
import type {} from '@deepseek-ai/dsh-client-ui-context-menu/client'
|
|
10
|
-
import type {} from '@deepseek-ai/dsh-api-workspace-controller/client'
|
|
11
|
-
import type {} from '@deepseek-ai/dsh-client-ui-settings/client'
|
|
12
|
-
import type { TabId } from '@deepseek-ai/dsh-client-ui-dockkit'
|
|
13
|
-
import { apply as applyReference } from './reference/client/plugin.ts'
|
|
14
|
-
import { applySettingsSection } from './settings/index.ts'
|
|
15
|
-
import { BrowserBody, type BrowserBodyProps } from './view/BrowserBody.tsx'
|
|
16
|
-
import { BrowserTitle } from './view/BrowserTitle.tsx'
|
|
17
|
-
import { createBrowserControllers } from './browser/BrowserController.ts'
|
|
18
|
-
import type { BrowserInjected } from './browser/BrowserController.ts'
|
|
19
|
-
import { createBrowserInitializationReader } from './browser/initialization.ts'
|
|
20
|
-
import type { BrowserInitializationReader } from './browser/initialization.ts'
|
|
21
|
-
import { createIframePage } from './pages.ts'
|
|
22
|
-
import { createReferenceCapture, type ReferenceCaptureContext } from './reference-capture-owner.ts'
|
|
23
|
-
import { createElectronPage } from './electron/pages.ts'
|
|
24
|
-
import { createNativePage } from './electron/NativeViewPage.ts'
|
|
25
|
-
import { NativeChildPresentation } from './electron/NativeChildPresentation.ts'
|
|
26
|
-
import type { DesktopBrowserBridge, SidebarNativeSlot } from '../types.ts'
|
|
27
|
-
import { browserWorkspace } from './electron/workspace.ts'
|
|
28
|
-
import { desktopBrowserBridge, nativeChildTabs, nativeViews } from '../compat/host-features.ts'
|
|
29
|
-
import type { BrowserPageFactory } from './browser/BrowserPage.ts'
|
|
30
|
-
import { BROWSER_ID, BROWSER_KIND, browserDefinition } from './definition.tsx'
|
|
31
|
-
import { en, ja, es, fr, de, ru, pt, zh, SIDEBAR_BROWSER_LOCALE_NS } from './locales.ts'
|
|
32
|
-
import { createBrowserStore } from './browser/store.ts'
|
|
33
|
-
import { StartPageBinding } from './startpage/binding.ts'
|
|
34
|
-
import { openShortcutTarget } from './shortcut-open.ts'
|
|
35
|
-
import { StartPageController } from './startpage/controller.ts'
|
|
36
|
-
import { BROWSER_STARTPAGE_NAMESPACE } from '../startpage-settings.ts'
|
|
37
|
-
import type { BrowserStartPagePreferences } from '../startpage-settings.ts'
|
|
38
|
-
|
|
39
|
-
export type { BrowserBodyProps } from './view/BrowserBody.tsx'
|
|
40
|
-
export type { BrowserControllerState, BrowserInjected, BrowserMountRequest } from './browser/BrowserController.ts'
|
|
41
|
-
export type { BrowserFrame, BrowserFrameState, BrowserLoadError, BrowserSandboxControl } from './browser/BrowserFrame.ts'
|
|
42
|
-
export type { BrowserPage, BrowserPageFactory, BrowserPageOptions } from './browser/BrowserPage.ts'
|
|
43
|
-
export type { BrowserPresentation } from './view/BrowserPresentation.ts'
|
|
44
|
-
export type { BrowserFailure, BrowserHistoryEntry, BrowserNavigationStatus, BrowserTabState } from './browser/BrowserPersistence.ts'
|
|
45
|
-
export type { SidebarBrowserKey } from './locales.ts'
|
|
46
|
-
export type { BrowserState } from './browser/store.ts'
|
|
47
|
-
export type { BrowserAddressFailure, BrowserAddressResult, BrowserTarget } from './browser/url.ts'
|
|
48
|
-
|
|
49
|
-
declare module '@deepseek-ai/cordis' {
|
|
50
|
-
interface Context {
|
|
51
|
-
/** Read initialization receipts for one exact Session/tab/document request. */
|
|
52
|
-
sidebarBrowserInitialization: BrowserInitializationReader
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
declare module '@deepseek-ai/dsh-client-ui-sidebar-right/client' {
|
|
57
|
-
interface SidebarRightTabParamsMap {
|
|
58
|
-
/** Optional initial Browser URL. */
|
|
59
|
-
browser: { readonly url?: string }
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
declare module '@deepseek-ai/dsh-client-ui-context-menu/client' {
|
|
64
|
-
interface ContextMenuTargetMap {
|
|
65
|
-
/** One start-page shortcut card; the originating tab owns the menu. */
|
|
66
|
-
shortcut: {
|
|
67
|
-
readonly sessionId: BrowserBodyProps['sessionId']
|
|
68
|
-
readonly tabId: TabId
|
|
69
|
-
readonly title: string
|
|
70
|
-
readonly url: string
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
/** Required Browser services. */
|
|
1
|
+
import { CLIENT_VERSION_ROUTE } from '../../assets/browser-policy.mjs'
|
|
2
|
+
/** Register the HTTP(S) Browser tab type in the right Sidebar. */
|
|
3
|
+
import type { ShortcutCommandId } from '@deepseek-ai/dsh-client-shortcuts/client'
|
|
4
|
+
import type { Context } from '@deepseek-ai/cordis'
|
|
5
|
+
import type {} from '@deepseek-ai/dsh-client-locale/client'
|
|
6
|
+
import type {} from '@deepseek-ai/dsh-client-ui-renderer/client'
|
|
7
|
+
import type {} from '@deepseek-ai/dsh-client-ui-session/client'
|
|
8
|
+
import type {} from '@deepseek-ai/dsh-client-ui-sidebar-right/client'
|
|
9
|
+
import type {} from '@deepseek-ai/dsh-client-ui-context-menu/client'
|
|
10
|
+
import type {} from '@deepseek-ai/dsh-api-workspace-controller/client'
|
|
11
|
+
import type {} from '@deepseek-ai/dsh-client-ui-settings/client'
|
|
12
|
+
import type { TabId } from '@deepseek-ai/dsh-client-ui-dockkit'
|
|
13
|
+
import { apply as applyReference } from './reference/client/plugin.ts'
|
|
14
|
+
import { applySettingsSection } from './settings/index.ts'
|
|
15
|
+
import { BrowserBody, type BrowserBodyProps } from './view/BrowserBody.tsx'
|
|
16
|
+
import { BrowserTitle } from './view/BrowserTitle.tsx'
|
|
17
|
+
import { createBrowserControllers } from './browser/BrowserController.ts'
|
|
18
|
+
import type { BrowserInjected } from './browser/BrowserController.ts'
|
|
19
|
+
import { createBrowserInitializationReader } from './browser/initialization.ts'
|
|
20
|
+
import type { BrowserInitializationReader } from './browser/initialization.ts'
|
|
21
|
+
import { createIframePage } from './pages.ts'
|
|
22
|
+
import { createReferenceCapture, type ReferenceCaptureContext } from './reference-capture-owner.ts'
|
|
23
|
+
import { createElectronPage } from './electron/pages.ts'
|
|
24
|
+
import { createNativePage } from './electron/NativeViewPage.ts'
|
|
25
|
+
import { NativeChildPresentation } from './electron/NativeChildPresentation.ts'
|
|
26
|
+
import type { DesktopBrowserBridge, SidebarNativeSlot } from '../types.ts'
|
|
27
|
+
import { browserWorkspace } from './electron/workspace.ts'
|
|
28
|
+
import { desktopBrowserBridge, nativeChildTabs, nativeViews } from '../compat/host-features.ts'
|
|
29
|
+
import type { BrowserPageFactory } from './browser/BrowserPage.ts'
|
|
30
|
+
import { BROWSER_ID, BROWSER_KIND, browserDefinition } from './definition.tsx'
|
|
31
|
+
import { en, ja, es, fr, de, ru, pt, zh, SIDEBAR_BROWSER_LOCALE_NS } from './locales.ts'
|
|
32
|
+
import { createBrowserStore } from './browser/store.ts'
|
|
33
|
+
import { StartPageBinding } from './startpage/binding.ts'
|
|
34
|
+
import { openShortcutTarget } from './shortcut-open.ts'
|
|
35
|
+
import { StartPageController } from './startpage/controller.ts'
|
|
36
|
+
import { BROWSER_STARTPAGE_NAMESPACE } from '../startpage-settings.ts'
|
|
37
|
+
import type { BrowserStartPagePreferences } from '../startpage-settings.ts'
|
|
38
|
+
|
|
39
|
+
export type { BrowserBodyProps } from './view/BrowserBody.tsx'
|
|
40
|
+
export type { BrowserControllerState, BrowserInjected, BrowserMountRequest } from './browser/BrowserController.ts'
|
|
41
|
+
export type { BrowserFrame, BrowserFrameState, BrowserLoadError, BrowserSandboxControl } from './browser/BrowserFrame.ts'
|
|
42
|
+
export type { BrowserPage, BrowserPageFactory, BrowserPageOptions } from './browser/BrowserPage.ts'
|
|
43
|
+
export type { BrowserPresentation } from './view/BrowserPresentation.ts'
|
|
44
|
+
export type { BrowserFailure, BrowserHistoryEntry, BrowserNavigationStatus, BrowserTabState } from './browser/BrowserPersistence.ts'
|
|
45
|
+
export type { SidebarBrowserKey } from './locales.ts'
|
|
46
|
+
export type { BrowserState } from './browser/store.ts'
|
|
47
|
+
export type { BrowserAddressFailure, BrowserAddressResult, BrowserTarget } from './browser/url.ts'
|
|
48
|
+
|
|
49
|
+
declare module '@deepseek-ai/cordis' {
|
|
50
|
+
interface Context {
|
|
51
|
+
/** Read initialization receipts for one exact Session/tab/document request. */
|
|
52
|
+
sidebarBrowserInitialization: BrowserInitializationReader
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
declare module '@deepseek-ai/dsh-client-ui-sidebar-right/client' {
|
|
57
|
+
interface SidebarRightTabParamsMap {
|
|
58
|
+
/** Optional initial Browser URL. */
|
|
59
|
+
browser: { readonly url?: string }
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
declare module '@deepseek-ai/dsh-client-ui-context-menu/client' {
|
|
64
|
+
interface ContextMenuTargetMap {
|
|
65
|
+
/** One start-page shortcut card; the originating tab owns the menu. */
|
|
66
|
+
shortcut: {
|
|
67
|
+
readonly sessionId: BrowserBodyProps['sessionId']
|
|
68
|
+
readonly tabId: TabId
|
|
69
|
+
readonly title: string
|
|
70
|
+
readonly url: string
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/** Required Browser services. */
|
|
76
76
|
// 寮曠敤鍧烇紙鍒掗€夆啋娴潯鈫掕緭鍏ユ爮鑳跺泭锛変笌渚ф爮鏍囩鍚屽睘杩欎竴涓寘锛屽鎴风鍏ュ彛鎶婁袱鑰呬竴璧锋敞鍐屻€?
|
|
77
77
|
// uiConversation 鏄紩鐢ㄥ潪闇€瑕佺殑浼氳瘽闈㈡湇鍔°€?
|
|
78
|
-
export const inject = ['slots', 'locale', 'sidebarRight', 'sidebarRightTabs', 'uiConversation']
|
|
79
|
-
|
|
80
|
-
/** Register the Browser type, localized guide entry, body, and title. */
|
|
81
|
-
/** sessionStorage 閿細鏈〉鍔犺浇鏃剁湅鍒扮殑瀹㈡埛绔骇鐗╃増鏈€?*/
|
|
82
|
-
const CLIENT_VERSION_WATCH = 'dsh-builtin-browser:client-version'
|
|
83
|
-
|
|
84
|
-
type SidebarHostExtensions = {
|
|
85
|
-
navigateTabIn?: (session: BrowserBodyProps['sessionId'], tab: TabId, options: { params: { url: string } }) => boolean
|
|
86
|
-
openReservedTab?: (session: BrowserBodyProps['sessionId'], kind: string, tab: TabId) => boolean
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
function registerShortcutIfAbsent(
|
|
90
|
-
register: () => () => void,
|
|
91
|
-
): () => void {
|
|
92
|
-
try {
|
|
93
|
-
return register()
|
|
94
|
-
} catch (error) {
|
|
95
|
-
// When DSH's built-in ui-sidebar-browser is also enabled (issue #107), it already registers
|
|
96
|
-
// built-in shortcut commands; skip cleanly rather than aborting plugin apply.
|
|
97
|
-
if (/Duplicate shortcut command|Conflicting shortcut defaults/i.test(String(error))) return () => {}
|
|
98
|
-
throw error
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
/**
|
|
78
|
+
export const inject = ['slots', 'locale', 'sidebarRight', 'sidebarRightTabs', 'uiConversation']
|
|
79
|
+
|
|
80
|
+
/** Register the Browser type, localized guide entry, body, and title. */
|
|
81
|
+
/** sessionStorage 閿細鏈〉鍔犺浇鏃剁湅鍒扮殑瀹㈡埛绔骇鐗╃増鏈€?*/
|
|
82
|
+
const CLIENT_VERSION_WATCH = 'dsh-builtin-browser:client-version'
|
|
83
|
+
|
|
84
|
+
type SidebarHostExtensions = {
|
|
85
|
+
navigateTabIn?: (session: BrowserBodyProps['sessionId'], tab: TabId, options: { params: { url: string } }) => boolean
|
|
86
|
+
openReservedTab?: (session: BrowserBodyProps['sessionId'], kind: string, tab: TabId) => boolean
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
function registerShortcutIfAbsent(
|
|
90
|
+
register: () => () => void,
|
|
91
|
+
): () => void {
|
|
92
|
+
try {
|
|
93
|
+
return register()
|
|
94
|
+
} catch (error) {
|
|
95
|
+
// When DSH's built-in ui-sidebar-browser is also enabled (issue #107), it already registers
|
|
96
|
+
// built-in shortcut commands; skip cleanly rather than aborting plugin apply.
|
|
97
|
+
if (/Duplicate shortcut command|Conflicting shortcut defaults/i.test(String(error))) return () => {}
|
|
98
|
+
throw error
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
103
|
* 瀹㈡埛绔骇鐗╂槸瀹夸富鍚姩鏃跺悎鎴愮殑鏁村寘鑴氭湰锛孶RL 閲岀殑 rev 鍦ㄥ惎鍔ㄩ偅涓€鍒诲浐瀹氾細浜х墿鏇存柊鍚庢祻瑙堝櫒浠嶆寜鏃?
|
|
104
|
-
* URL 鍛戒腑缂撳瓨锛屼簬鏄€屾敼浜嗕唬鐮佺晫闈笉鍙樸€嶃€傝繖閲岃疆璇㈠涓绘毚闇茬殑浜х墿鎸囩汗锛屼竴鏃﹀彉鍖栧氨甯︽柊鍙傛暟閲嶈浇鏈〉
|
|
104
|
+
* URL 鍛戒腑缂撳瓨锛屼簬鏄€屾敼浜嗕唬鐮佺晫闈笉鍙樸€嶃€傝繖閲岃疆璇㈠涓绘毚闇茬殑浜х墿鎸囩汗锛屼竴鏃﹀彉鍖栧氨甯︽柊鍙傛暟閲嶈浇鏈〉
|
|
105
105
|
* 鈥斺€斿鎴风鏀瑰姩涓嶅啀闇€瑕侀噸鍚涓绘垨鎵嬪姩鐮寸紦瀛樸€?
|
|
106
106
|
* @param ctx - 鎻掍欢瀹瑰櫒锛堢敤浜庨殢鎻掍欢鍗歌浇鍋滀笅杞锛夈€?
|
|
107
|
-
*/
|
|
108
|
-
function watchClientVersion(ctx: Context): void {
|
|
109
|
-
const check = async (): Promise<void> => {
|
|
110
|
-
try {
|
|
111
|
-
const response = await fetch(CLIENT_VERSION_ROUTE, { credentials: 'same-origin', cache: 'no-store' })
|
|
112
|
-
if (!response.ok) return
|
|
113
|
-
const body = await response.json() as { readonly version?: string }
|
|
114
|
-
const version = body.version
|
|
115
|
-
if (typeof version !== 'string' || version === '' || version === 'unknown') return
|
|
116
|
-
const reload = (token: string): void => {
|
|
117
|
-
const url = new URL(location.href)
|
|
118
|
-
url.searchParams.set('v', token)
|
|
119
|
-
location.replace(url.toString())
|
|
120
|
-
}
|
|
121
|
-
const seen = sessionStorage.getItem(CLIENT_VERSION_WATCH)
|
|
122
|
-
// The first check of a page that was opened BEFORE a deploy must not adopt the deployed token
|
|
123
|
-
// as "seen": the page is still running the old bundle. The deployed token is kept in
|
|
124
|
-
// localStorage precisely so the next tab (or the next load) notices it and reloads once.
|
|
125
|
-
if (seen === null) {
|
|
126
|
-
const deployed = localStorage.getItem(CLIENT_VERSION_WATCH)
|
|
127
|
-
sessionStorage.setItem(CLIENT_VERSION_WATCH, version)
|
|
128
|
-
localStorage.setItem(CLIENT_VERSION_WATCH, version)
|
|
129
|
-
if (deployed !== null && deployed !== version) { reload(version); return }
|
|
130
|
-
return
|
|
131
|
-
}
|
|
132
|
-
if (seen === version) return
|
|
133
|
-
sessionStorage.setItem(CLIENT_VERSION_WATCH, version)
|
|
134
|
-
localStorage.setItem(CLIENT_VERSION_WATCH, version)
|
|
135
|
-
reload(version)
|
|
136
|
-
location.replace(url.toString())
|
|
137
|
-
} catch {
|
|
107
|
+
*/
|
|
108
|
+
function watchClientVersion(ctx: Context): void {
|
|
109
|
+
const check = async (): Promise<void> => {
|
|
110
|
+
try {
|
|
111
|
+
const response = await fetch(CLIENT_VERSION_ROUTE, { credentials: 'same-origin', cache: 'no-store' })
|
|
112
|
+
if (!response.ok) return
|
|
113
|
+
const body = await response.json() as { readonly version?: string }
|
|
114
|
+
const version = body.version
|
|
115
|
+
if (typeof version !== 'string' || version === '' || version === 'unknown') return
|
|
116
|
+
const reload = (token: string): void => {
|
|
117
|
+
const url = new URL(location.href)
|
|
118
|
+
url.searchParams.set('v', token)
|
|
119
|
+
location.replace(url.toString())
|
|
120
|
+
}
|
|
121
|
+
const seen = sessionStorage.getItem(CLIENT_VERSION_WATCH)
|
|
122
|
+
// The first check of a page that was opened BEFORE a deploy must not adopt the deployed token
|
|
123
|
+
// as "seen": the page is still running the old bundle. The deployed token is kept in
|
|
124
|
+
// localStorage precisely so the next tab (or the next load) notices it and reloads once.
|
|
125
|
+
if (seen === null) {
|
|
126
|
+
const deployed = localStorage.getItem(CLIENT_VERSION_WATCH)
|
|
127
|
+
sessionStorage.setItem(CLIENT_VERSION_WATCH, version)
|
|
128
|
+
localStorage.setItem(CLIENT_VERSION_WATCH, version)
|
|
129
|
+
if (deployed !== null && deployed !== version) { reload(version); return }
|
|
130
|
+
return
|
|
131
|
+
}
|
|
132
|
+
if (seen === version) return
|
|
133
|
+
sessionStorage.setItem(CLIENT_VERSION_WATCH, version)
|
|
134
|
+
localStorage.setItem(CLIENT_VERSION_WATCH, version)
|
|
135
|
+
reload(version)
|
|
136
|
+
location.replace(url.toString())
|
|
137
|
+
} catch {
|
|
138
138
|
// 涓嬩竴娆¤疆璇㈠啀璇曪細杩欐潯閫氶亾澶辫触涓嶈褰卞搷鐣岄潰銆?
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
void check()
|
|
142
|
-
// A deploy replaces lib/client.js, so the served token (mtime-size) changes. Checking only
|
|
143
|
-
// every minute left a deploy unseen until a poll happened to land; re-checking on focus and on
|
|
144
|
-
// the tab becoming visible is what makes it feel like a dev server's hot reload.
|
|
145
|
-
const timer = setInterval(() => { if (typeof document === 'undefined' || document.visibilityState === 'visible') void check() }, 15_000)
|
|
146
|
-
const onVisible = (): void => { if (typeof document === 'undefined' || document.visibilityState === 'visible') void check() }
|
|
147
|
-
if (typeof document !== 'undefined') document.addEventListener('visibilitychange', onVisible)
|
|
148
|
-
if (typeof window !== 'undefined') window.addEventListener('focus', onVisible)
|
|
149
|
-
ctx.effect(() => () => {
|
|
150
|
-
clearInterval(timer)
|
|
151
|
-
if (typeof document !== 'undefined') document.removeEventListener('visibilitychange', onVisible)
|
|
152
|
-
if (typeof window !== 'undefined') window.removeEventListener('focus', onVisible)
|
|
153
|
-
}, 'dsh-builtin-browser: client version watch')
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
/** Register the Browser tab type. */
|
|
158
|
-
export function apply(ctx: Context): void {
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
void check()
|
|
142
|
+
// A deploy replaces lib/client.js, so the served token (mtime-size) changes. Checking only
|
|
143
|
+
// every minute left a deploy unseen until a poll happened to land; re-checking on focus and on
|
|
144
|
+
// the tab becoming visible is what makes it feel like a dev server's hot reload.
|
|
145
|
+
const timer = setInterval(() => { if (typeof document === 'undefined' || document.visibilityState === 'visible') void check() }, 15_000)
|
|
146
|
+
const onVisible = (): void => { if (typeof document === 'undefined' || document.visibilityState === 'visible') void check() }
|
|
147
|
+
if (typeof document !== 'undefined') document.addEventListener('visibilitychange', onVisible)
|
|
148
|
+
if (typeof window !== 'undefined') window.addEventListener('focus', onVisible)
|
|
149
|
+
ctx.effect(() => () => {
|
|
150
|
+
clearInterval(timer)
|
|
151
|
+
if (typeof document !== 'undefined') document.removeEventListener('visibilitychange', onVisible)
|
|
152
|
+
if (typeof window !== 'undefined') window.removeEventListener('focus', onVisible)
|
|
153
|
+
}, 'dsh-builtin-browser: client version watch')
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
|
|
157
|
+
/** Register the Browser tab type. */
|
|
158
|
+
export function apply(ctx: Context): void {
|
|
159
159
|
// 鍏堟寕瀹㈡埛绔嚜鏇存柊锛氫骇鐗╀竴鍙橈紝鏈〉鑷繁鎹㈠埌鏂?bundle锛堝惁鍒欎細涓€鐩寸敤缂撳瓨閲岀殑鏃ц剼鏈級銆?
|
|
160
|
-
// Isolated like the reference dock: an update watcher that cannot start must not take the whole
|
|
161
|
-
// client registration with it (issue #132: one failing registration left the settings section
|
|
162
|
-
// missing altogether).
|
|
163
|
-
try { watchClientVersion(ctx) } catch (error) { console.warn('[dsh-builtin-browser] client version watch failed to start', error) }
|
|
160
|
+
// Isolated like the reference dock: an update watcher that cannot start must not take the whole
|
|
161
|
+
// client registration with it (issue #132: one failing registration left the settings section
|
|
162
|
+
// missing altogether).
|
|
163
|
+
try { watchClientVersion(ctx) } catch (error) { console.warn('[dsh-builtin-browser] client version watch failed to start', error) }
|
|
164
164
|
// 鍏堣寮曠敤鍧烇細瀹冩槸杈撳叆鏍忛偅涓€渚х殑娉ㄥ唽锛屼笌渚ф爮鏍囩浜掍笉渚濊禆銆?
|
|
165
165
|
// 姣忎釜娉ㄥ唽鍚勮嚜闅旂锛氫竴涓け璐ュ彧涓竴鍧楄兘鍔涳紝涓嶈兘鎶婂悓涓€ apply 閲岀殑鍏朵綑娉ㄥ唽涓€璧锋帎鏂€?
|
|
166
|
-
try { applyReference(ctx as never) } catch (error) { console.warn('[dsh-builtin-browser] reference dock failed to mount', error) }
|
|
166
|
+
try { applyReference(ctx as never) } catch (error) { console.warn('[dsh-builtin-browser] reference dock failed to mount', error) }
|
|
167
167
|
// 鍐嶈璁剧疆椤靛垎鑺傦細鏃ф彃浠剁殑璁剧疆闈㈡澘锛堝涓?/dsh-builtin-browser/settings 鐨?UI锛夈€?
|
|
168
|
-
try { applySettingsSection(ctx) } catch (error) { console.warn('[dsh-builtin-browser] settings section failed to mount', error) }
|
|
169
|
-
|
|
170
|
-
const namespace = SIDEBAR_BROWSER_LOCALE_NS
|
|
171
|
-
const t = ctx.locale.bind(namespace)
|
|
172
|
-
ctx.inject(['shortcuts'], (ctx) => {
|
|
173
|
-
ctx.effect(() => registerShortcutIfAbsent(() => ctx.shortcuts.register({
|
|
174
|
-
id: 'browser.new' as ShortcutCommandId, label: () => t('guide.title'), aliases: ['browser', 'new browser tab'],
|
|
175
|
-
defaults: {
|
|
176
|
-
'desktop:macos': { code: 'KeyT', modifiers: ['primary'] },
|
|
177
|
-
'desktop:windows': { code: 'KeyT', modifiers: ['primary'] },
|
|
178
|
-
'desktop:linux': { code: 'KeyT', modifiers: ['primary'] },
|
|
179
|
-
'web:macos': { code: 'KeyT', modifiers: ['primary', 'alt'] },
|
|
180
|
-
'web:windows': { code: 'KeyT', modifiers: ['primary', 'alt'] },
|
|
181
|
-
},
|
|
182
|
-
// Each tab plugin owns its command's availability, localized refusal, and tab kind.
|
|
183
|
-
/* jscpd:ignore-start */
|
|
184
|
-
regions: ['page', 'editable', 'terminal'], modals: [],
|
|
185
|
-
resolve: ({ target: element }) => {
|
|
186
|
-
const target = ctx.sidebarRight.commandTarget(element)
|
|
187
|
-
if (target === undefined) return { status: 'blocked', reason: t('shortcut.noSession') }
|
|
188
|
-
return { status: 'handled', run: () => { ctx.sidebarRight.openTabFromTarget('browser', target) } }
|
|
189
|
-
},
|
|
190
|
-
/* jscpd:ignore-end */
|
|
191
|
-
})), 'ui-sidebar-browser: shortcut')
|
|
192
|
-
})
|
|
193
|
-
const store = createBrowserStore()
|
|
194
|
-
const startPage = new StartPageBinding()
|
|
195
|
-
const controllers = new Map<BrowserBodyProps['sessionId'], BrowserInjected>()
|
|
196
|
-
const initializationListeners = new Set<() => void>()
|
|
197
|
-
ctx.provide('sidebarBrowserInitialization')
|
|
198
|
-
ctx.set('sidebarBrowserInitialization', createBrowserInitializationReader((sessionId, tabId) => {
|
|
199
|
-
return controllers.get(sessionId as BrowserBodyProps['sessionId'])?.initialization(tabId)
|
|
200
|
-
}, listener => {
|
|
201
|
-
initializationListeners.add(listener)
|
|
202
|
-
return () => { initializationListeners.delete(listener) }
|
|
203
|
-
}, (sessionId, tabId) => controllers.get(sessionId as BrowserBodyProps['sessionId'])?.currentPage(tabId),
|
|
204
|
-
(sessionId, tabId, url) => controllers.get(sessionId as BrowserBodyProps['sessionId'])?.loadUrl(tabId, url).ok === true))
|
|
205
|
-
ctx.inject(['shortcuts'], (scope) => {
|
|
206
|
-
scope.effect(() => registerShortcutIfAbsent(() => scope.shortcuts.register({
|
|
207
|
-
id: 'browser.address' as ShortcutCommandId, label: () => t('address.focus'), aliases: ['address bar', 'focus address'],
|
|
208
|
-
defaults: {
|
|
209
|
-
'desktop:macos': { code: 'KeyL', modifiers: ['primary'] },
|
|
210
|
-
'desktop:windows': { code: 'KeyL', modifiers: ['primary'] },
|
|
211
|
-
'desktop:linux': { code: 'KeyL', modifiers: ['primary'] },
|
|
212
|
-
'web:macos': { code: 'KeyL', modifiers: ['primary', 'alt'] },
|
|
213
|
-
'web:windows': { code: 'KeyL', modifiers: ['primary', 'alt'] },
|
|
214
|
-
},
|
|
215
|
-
regions: ['page', 'editable', 'terminal'], modals: [],
|
|
216
|
-
resolve: ({ target: element }) => {
|
|
217
|
-
const target = ctx.sidebarRight.commandTarget(element)
|
|
218
|
-
const face = target === undefined || target.tabId === undefined ? undefined : controllers.get(target.sessionId)
|
|
219
|
-
if (target === undefined || target.tabId === undefined || face === undefined || !face.canFocusAddress(target.tabId)) {
|
|
220
|
-
return { status: 'blocked', reason: t('address.focus.blocked') }
|
|
221
|
-
}
|
|
222
|
-
return { status: 'handled', run: () => { face.focusAddress(target.tabId!) } }
|
|
223
|
-
},
|
|
224
|
-
})), 'ui-sidebar-browser: address shortcut')
|
|
225
|
-
})
|
|
226
|
-
ctx.inject(['contextMenus'], (scope) => {
|
|
227
|
-
scope.effect(() => scope.contextMenus.register({
|
|
228
|
-
id: 'dsh-builtin-browser.shortcut', target: 'shortcut', order: 20,
|
|
229
|
-
resolve: ({ sessionId, tabId, url }) => [
|
|
230
|
-
{
|
|
231
|
-
id: 'open', label: t('startpage.open'),
|
|
232
|
-
run: () => {
|
|
233
|
-
openShortcutTarget(
|
|
234
|
-
u => (scope.sidebarRight as typeof scope.sidebarRight & SidebarHostExtensions).navigateTabIn?.(sessionId, tabId, { params: { url: u } }) === true,
|
|
235
|
-
u => { scope.sidebarRight.openTabIn<'browser'>(sessionId, BROWSER_KIND, { params: { url: u }, revealIfOpened: false }) },
|
|
236
|
-
url,
|
|
237
|
-
)
|
|
238
|
-
},
|
|
239
|
-
},
|
|
240
|
-
{
|
|
241
|
-
id: 'open-new-tab', label: t('startpage.openNewTab'),
|
|
242
|
-
run: () => { scope.sidebarRight.openTabIn<'browser'>(sessionId, BROWSER_KIND, { params: { url }, revealIfOpened: false }) },
|
|
243
|
-
},
|
|
244
|
-
],
|
|
245
|
-
}), 'ui-sidebar-browser: shortcut menu')
|
|
246
|
-
scope.effect(() => scope.contextMenus.register({
|
|
247
|
-
id: 'dsh-builtin-browser.tab.shortcut', target: 'tab', order: 90,
|
|
248
|
-
resolve: (target) => {
|
|
249
|
-
if (target.tab.kind !== BROWSER_KIND) return []
|
|
250
|
-
const face = controllers.get(target.sessionId)
|
|
251
|
-
const info = face?.pageInfo(target.tab.id)
|
|
252
|
-
if (face === undefined || info === undefined) return []
|
|
253
|
-
const title = target.tab.title.trim()
|
|
254
|
-
return [{
|
|
255
|
-
id: 'add-shortcut', label: t('startpage.addFromPage'), separatorBefore: true,
|
|
256
|
-
run: () => {
|
|
257
|
-
face.requestShortcut(target.tab.id, { url: info.url, title: title === '' ? info.title : title })
|
|
258
|
-
// The form lives in the tab's body; reveal it before asking for input.
|
|
259
|
-
scope.sidebarRight.focus(target.tab.id)
|
|
260
|
-
},
|
|
261
|
-
}]
|
|
262
|
-
},
|
|
263
|
-
}), 'ui-sidebar-browser: tab shortcut menu')
|
|
264
|
-
})
|
|
265
|
-
ctx.inject(['configForms'], (scope) => {
|
|
266
|
-
scope.effect(() => {
|
|
267
|
-
const controller = new StartPageController(
|
|
268
|
-
scope.configForms.get<BrowserStartPagePreferences>(BROWSER_STARTPAGE_NAMESPACE),
|
|
269
|
-
{ applicationOrigin: window.location.origin },
|
|
270
|
-
)
|
|
271
|
-
const detach = startPage.attach(controller)
|
|
272
|
-
return () => { detach(); controller.dispose() }
|
|
273
|
-
}, 'ui-sidebar-browser: start-page preferences')
|
|
274
|
-
})
|
|
275
|
-
const openTabs = ctx.sidebarRight.openTabs
|
|
276
|
-
const desktop = desktopBrowserBridge()
|
|
277
|
-
ctx.effect(() => ctx.locale.register(namespace, { zh, en, ja, es, fr, de, ru, pt }), 'ui-sidebar-browser.copy')
|
|
278
|
-
ctx.effect(() => ctx.sidebarRightTabs.register({ ...browserDefinition(t), keepMounted: desktop !== undefined }), 'ui-sidebar-browser.type')
|
|
279
|
-
const installFrames = (scope: Context, factory: (sessionId: BrowserBodyProps['sessionId']) => BrowserPageFactory): void => {
|
|
280
|
-
scope.effect(() => async () => {
|
|
281
|
-
const pending = [...controllers.values()].map(controller => controller.dispose())
|
|
282
|
-
controllers.clear()
|
|
283
|
-
await Promise.all(pending)
|
|
284
|
-
}, 'ui-sidebar-browser.frames')
|
|
285
|
-
scope.effect(() => scope.slots.inject('sidebar.right.pane.tab', () => scope.slots.register({
|
|
286
|
-
name: 'sidebar.right.pane.tab', key: BROWSER_ID, locale: namespace, store,
|
|
287
|
-
inject: (sessionId, actions) => {
|
|
288
|
-
const existing = controllers.get(sessionId)
|
|
289
|
-
if (existing !== undefined) {
|
|
290
|
-
existing.rebind(actions)
|
|
291
|
-
return existing
|
|
292
|
-
}
|
|
293
|
-
const controller = createBrowserControllers(actions, factory(sessionId), tabId =>
|
|
294
|
-
openTabs.getSnapshot().some(tab => tab.sessionId === sessionId && tab.tabId === tabId), startPage,
|
|
295
|
-
{ sessionId, onInitializationChange: () => { for (const listener of initializationListeners) listener() } })
|
|
296
|
-
controllers.set(sessionId, controller)
|
|
297
|
-
return controller
|
|
298
|
-
},
|
|
299
|
-
}, BrowserBody)), 'ui-sidebar-browser.body')
|
|
300
|
-
}
|
|
301
|
-
const lifetime = new AbortController()
|
|
302
|
-
ctx.effect(() => () => { lifetime.abort() }, 'dsh-builtin-browser: reference capture')
|
|
303
|
-
const capture = createReferenceCapture(ctx as unknown as ReferenceCaptureContext, lifetime.signal)
|
|
304
|
-
if (desktop === undefined) {
|
|
305
|
-
installFrames(ctx, sessionId => options => createIframePage(options, sessionId, capture))
|
|
306
|
-
}
|
|
307
|
-
else ctx.inject(['workspaces'], (scope) => {
|
|
308
|
-
installFrames(scope, sessionId => {
|
|
309
|
-
const childApi = nativeChildTabs(desktop)
|
|
310
|
-
const sidebar = scope.sidebarRight as typeof scope.sidebarRight & SidebarHostExtensions
|
|
311
|
-
const children = childApi !== undefined && sidebar.openReservedTab !== undefined ? new NativeChildPresentation(childApi, sessionId,
|
|
312
|
-
tab => sidebar.openReservedTab?.(sessionId, BROWSER_KIND, tab) === true,
|
|
313
|
-
tab => { sidebar.closeIn(sessionId, tab) }) : undefined
|
|
314
|
-
return options => {
|
|
315
|
-
const native = nativeViews(desktop)
|
|
316
|
-
const workspace = (signal: AbortSignal): Promise<string> => browserWorkspace(scope.workspaces.list, sessionId, signal)
|
|
317
|
-
if (native !== undefined) {
|
|
318
|
-
const sidebar = scope.sidebarRight as typeof scope.sidebarRight & {
|
|
319
|
-
nativeSlot?: (session: typeof sessionId, tab: TabId, address: string, viewport: string, signal: AbortSignal) => Promise<SidebarNativeSlot>
|
|
320
|
-
}
|
|
321
|
-
return createNativePage(options, native, async (tab, address, viewport, signal) => {
|
|
322
|
-
if (sidebar.nativeSlot === undefined) throw Object.assign(new Error('BROWSER_NATIVE_SURFACE_UNAVAILABLE'), { code: 'BROWSER_NATIVE_SURFACE_UNAVAILABLE' })
|
|
323
|
-
return sidebar.nativeSlot(sessionId, tab, address, viewport, signal)
|
|
324
|
-
}, workspace, sessionId, capture, children)
|
|
325
|
-
}
|
|
326
|
-
return createElectronPage(options, desktop, workspace, sessionId, capture)
|
|
327
|
-
}
|
|
328
|
-
})
|
|
329
|
-
})
|
|
330
|
-
ctx.effect(() => ctx.slots.inject('sidebar.right.pane.tab.title', () => ctx.slots.register({
|
|
331
|
-
name: 'sidebar.right.pane.tab.title', key: BROWSER_ID, store,
|
|
332
|
-
}, BrowserTitle)), 'ui-sidebar-browser.title')
|
|
333
|
-
}
|
|
168
|
+
try { applySettingsSection(ctx) } catch (error) { console.warn('[dsh-builtin-browser] settings section failed to mount', error) }
|
|
169
|
+
|
|
170
|
+
const namespace = SIDEBAR_BROWSER_LOCALE_NS
|
|
171
|
+
const t = ctx.locale.bind(namespace)
|
|
172
|
+
ctx.inject(['shortcuts'], (ctx) => {
|
|
173
|
+
ctx.effect(() => registerShortcutIfAbsent(() => ctx.shortcuts.register({
|
|
174
|
+
id: 'browser.new' as ShortcutCommandId, label: () => t('guide.title'), aliases: ['browser', 'new browser tab'],
|
|
175
|
+
defaults: {
|
|
176
|
+
'desktop:macos': { code: 'KeyT', modifiers: ['primary'] },
|
|
177
|
+
'desktop:windows': { code: 'KeyT', modifiers: ['primary'] },
|
|
178
|
+
'desktop:linux': { code: 'KeyT', modifiers: ['primary'] },
|
|
179
|
+
'web:macos': { code: 'KeyT', modifiers: ['primary', 'alt'] },
|
|
180
|
+
'web:windows': { code: 'KeyT', modifiers: ['primary', 'alt'] },
|
|
181
|
+
},
|
|
182
|
+
// Each tab plugin owns its command's availability, localized refusal, and tab kind.
|
|
183
|
+
/* jscpd:ignore-start */
|
|
184
|
+
regions: ['page', 'editable', 'terminal'], modals: [],
|
|
185
|
+
resolve: ({ target: element }) => {
|
|
186
|
+
const target = ctx.sidebarRight.commandTarget(element)
|
|
187
|
+
if (target === undefined) return { status: 'blocked', reason: t('shortcut.noSession') }
|
|
188
|
+
return { status: 'handled', run: () => { ctx.sidebarRight.openTabFromTarget('browser', target) } }
|
|
189
|
+
},
|
|
190
|
+
/* jscpd:ignore-end */
|
|
191
|
+
})), 'ui-sidebar-browser: shortcut')
|
|
192
|
+
})
|
|
193
|
+
const store = createBrowserStore()
|
|
194
|
+
const startPage = new StartPageBinding()
|
|
195
|
+
const controllers = new Map<BrowserBodyProps['sessionId'], BrowserInjected>()
|
|
196
|
+
const initializationListeners = new Set<() => void>()
|
|
197
|
+
ctx.provide('sidebarBrowserInitialization')
|
|
198
|
+
ctx.set('sidebarBrowserInitialization', createBrowserInitializationReader((sessionId, tabId) => {
|
|
199
|
+
return controllers.get(sessionId as BrowserBodyProps['sessionId'])?.initialization(tabId)
|
|
200
|
+
}, listener => {
|
|
201
|
+
initializationListeners.add(listener)
|
|
202
|
+
return () => { initializationListeners.delete(listener) }
|
|
203
|
+
}, (sessionId, tabId) => controllers.get(sessionId as BrowserBodyProps['sessionId'])?.currentPage(tabId),
|
|
204
|
+
(sessionId, tabId, url) => controllers.get(sessionId as BrowserBodyProps['sessionId'])?.loadUrl(tabId, url).ok === true))
|
|
205
|
+
ctx.inject(['shortcuts'], (scope) => {
|
|
206
|
+
scope.effect(() => registerShortcutIfAbsent(() => scope.shortcuts.register({
|
|
207
|
+
id: 'browser.address' as ShortcutCommandId, label: () => t('address.focus'), aliases: ['address bar', 'focus address'],
|
|
208
|
+
defaults: {
|
|
209
|
+
'desktop:macos': { code: 'KeyL', modifiers: ['primary'] },
|
|
210
|
+
'desktop:windows': { code: 'KeyL', modifiers: ['primary'] },
|
|
211
|
+
'desktop:linux': { code: 'KeyL', modifiers: ['primary'] },
|
|
212
|
+
'web:macos': { code: 'KeyL', modifiers: ['primary', 'alt'] },
|
|
213
|
+
'web:windows': { code: 'KeyL', modifiers: ['primary', 'alt'] },
|
|
214
|
+
},
|
|
215
|
+
regions: ['page', 'editable', 'terminal'], modals: [],
|
|
216
|
+
resolve: ({ target: element }) => {
|
|
217
|
+
const target = ctx.sidebarRight.commandTarget(element)
|
|
218
|
+
const face = target === undefined || target.tabId === undefined ? undefined : controllers.get(target.sessionId)
|
|
219
|
+
if (target === undefined || target.tabId === undefined || face === undefined || !face.canFocusAddress(target.tabId)) {
|
|
220
|
+
return { status: 'blocked', reason: t('address.focus.blocked') }
|
|
221
|
+
}
|
|
222
|
+
return { status: 'handled', run: () => { face.focusAddress(target.tabId!) } }
|
|
223
|
+
},
|
|
224
|
+
})), 'ui-sidebar-browser: address shortcut')
|
|
225
|
+
})
|
|
226
|
+
ctx.inject(['contextMenus'], (scope) => {
|
|
227
|
+
scope.effect(() => scope.contextMenus.register({
|
|
228
|
+
id: 'dsh-builtin-browser.shortcut', target: 'shortcut', order: 20,
|
|
229
|
+
resolve: ({ sessionId, tabId, url }) => [
|
|
230
|
+
{
|
|
231
|
+
id: 'open', label: t('startpage.open'),
|
|
232
|
+
run: () => {
|
|
233
|
+
openShortcutTarget(
|
|
234
|
+
u => (scope.sidebarRight as typeof scope.sidebarRight & SidebarHostExtensions).navigateTabIn?.(sessionId, tabId, { params: { url: u } }) === true,
|
|
235
|
+
u => { scope.sidebarRight.openTabIn<'browser'>(sessionId, BROWSER_KIND, { params: { url: u }, revealIfOpened: false }) },
|
|
236
|
+
url,
|
|
237
|
+
)
|
|
238
|
+
},
|
|
239
|
+
},
|
|
240
|
+
{
|
|
241
|
+
id: 'open-new-tab', label: t('startpage.openNewTab'),
|
|
242
|
+
run: () => { scope.sidebarRight.openTabIn<'browser'>(sessionId, BROWSER_KIND, { params: { url }, revealIfOpened: false }) },
|
|
243
|
+
},
|
|
244
|
+
],
|
|
245
|
+
}), 'ui-sidebar-browser: shortcut menu')
|
|
246
|
+
scope.effect(() => scope.contextMenus.register({
|
|
247
|
+
id: 'dsh-builtin-browser.tab.shortcut', target: 'tab', order: 90,
|
|
248
|
+
resolve: (target) => {
|
|
249
|
+
if (target.tab.kind !== BROWSER_KIND) return []
|
|
250
|
+
const face = controllers.get(target.sessionId)
|
|
251
|
+
const info = face?.pageInfo(target.tab.id)
|
|
252
|
+
if (face === undefined || info === undefined) return []
|
|
253
|
+
const title = target.tab.title.trim()
|
|
254
|
+
return [{
|
|
255
|
+
id: 'add-shortcut', label: t('startpage.addFromPage'), separatorBefore: true,
|
|
256
|
+
run: () => {
|
|
257
|
+
face.requestShortcut(target.tab.id, { url: info.url, title: title === '' ? info.title : title })
|
|
258
|
+
// The form lives in the tab's body; reveal it before asking for input.
|
|
259
|
+
scope.sidebarRight.focus(target.tab.id)
|
|
260
|
+
},
|
|
261
|
+
}]
|
|
262
|
+
},
|
|
263
|
+
}), 'ui-sidebar-browser: tab shortcut menu')
|
|
264
|
+
})
|
|
265
|
+
ctx.inject(['configForms'], (scope) => {
|
|
266
|
+
scope.effect(() => {
|
|
267
|
+
const controller = new StartPageController(
|
|
268
|
+
scope.configForms.get<BrowserStartPagePreferences>(BROWSER_STARTPAGE_NAMESPACE),
|
|
269
|
+
{ applicationOrigin: window.location.origin },
|
|
270
|
+
)
|
|
271
|
+
const detach = startPage.attach(controller)
|
|
272
|
+
return () => { detach(); controller.dispose() }
|
|
273
|
+
}, 'ui-sidebar-browser: start-page preferences')
|
|
274
|
+
})
|
|
275
|
+
const openTabs = ctx.sidebarRight.openTabs
|
|
276
|
+
const desktop = desktopBrowserBridge()
|
|
277
|
+
ctx.effect(() => ctx.locale.register(namespace, { zh, en, ja, es, fr, de, ru, pt }), 'ui-sidebar-browser.copy')
|
|
278
|
+
ctx.effect(() => ctx.sidebarRightTabs.register({ ...browserDefinition(t), keepMounted: desktop !== undefined }), 'ui-sidebar-browser.type')
|
|
279
|
+
const installFrames = (scope: Context, factory: (sessionId: BrowserBodyProps['sessionId']) => BrowserPageFactory): void => {
|
|
280
|
+
scope.effect(() => async () => {
|
|
281
|
+
const pending = [...controllers.values()].map(controller => controller.dispose())
|
|
282
|
+
controllers.clear()
|
|
283
|
+
await Promise.all(pending)
|
|
284
|
+
}, 'ui-sidebar-browser.frames')
|
|
285
|
+
scope.effect(() => scope.slots.inject('sidebar.right.pane.tab', () => scope.slots.register({
|
|
286
|
+
name: 'sidebar.right.pane.tab', key: BROWSER_ID, locale: namespace, store,
|
|
287
|
+
inject: (sessionId, actions) => {
|
|
288
|
+
const existing = controllers.get(sessionId)
|
|
289
|
+
if (existing !== undefined) {
|
|
290
|
+
existing.rebind(actions)
|
|
291
|
+
return existing
|
|
292
|
+
}
|
|
293
|
+
const controller = createBrowserControllers(actions, factory(sessionId), tabId =>
|
|
294
|
+
openTabs.getSnapshot().some(tab => tab.sessionId === sessionId && tab.tabId === tabId), startPage,
|
|
295
|
+
{ sessionId, onInitializationChange: () => { for (const listener of initializationListeners) listener() } })
|
|
296
|
+
controllers.set(sessionId, controller)
|
|
297
|
+
return controller
|
|
298
|
+
},
|
|
299
|
+
}, BrowserBody)), 'ui-sidebar-browser.body')
|
|
300
|
+
}
|
|
301
|
+
const lifetime = new AbortController()
|
|
302
|
+
ctx.effect(() => () => { lifetime.abort() }, 'dsh-builtin-browser: reference capture')
|
|
303
|
+
const capture = createReferenceCapture(ctx as unknown as ReferenceCaptureContext, lifetime.signal)
|
|
304
|
+
if (desktop === undefined) {
|
|
305
|
+
installFrames(ctx, sessionId => options => createIframePage(options, sessionId, capture))
|
|
306
|
+
}
|
|
307
|
+
else ctx.inject(['workspaces'], (scope) => {
|
|
308
|
+
installFrames(scope, sessionId => {
|
|
309
|
+
const childApi = nativeChildTabs(desktop)
|
|
310
|
+
const sidebar = scope.sidebarRight as typeof scope.sidebarRight & SidebarHostExtensions
|
|
311
|
+
const children = childApi !== undefined && sidebar.openReservedTab !== undefined ? new NativeChildPresentation(childApi, sessionId,
|
|
312
|
+
tab => sidebar.openReservedTab?.(sessionId, BROWSER_KIND, tab) === true,
|
|
313
|
+
tab => { sidebar.closeIn(sessionId, tab) }) : undefined
|
|
314
|
+
return options => {
|
|
315
|
+
const native = nativeViews(desktop)
|
|
316
|
+
const workspace = (signal: AbortSignal): Promise<string> => browserWorkspace(scope.workspaces.list, sessionId, signal)
|
|
317
|
+
if (native !== undefined) {
|
|
318
|
+
const sidebar = scope.sidebarRight as typeof scope.sidebarRight & {
|
|
319
|
+
nativeSlot?: (session: typeof sessionId, tab: TabId, address: string, viewport: string, signal: AbortSignal) => Promise<SidebarNativeSlot>
|
|
320
|
+
}
|
|
321
|
+
return createNativePage(options, native, async (tab, address, viewport, signal) => {
|
|
322
|
+
if (sidebar.nativeSlot === undefined) throw Object.assign(new Error('BROWSER_NATIVE_SURFACE_UNAVAILABLE'), { code: 'BROWSER_NATIVE_SURFACE_UNAVAILABLE' })
|
|
323
|
+
return sidebar.nativeSlot(sessionId, tab, address, viewport, signal)
|
|
324
|
+
}, workspace, sessionId, capture, children)
|
|
325
|
+
}
|
|
326
|
+
return createElectronPage(options, desktop, workspace, sessionId, capture)
|
|
327
|
+
}
|
|
328
|
+
})
|
|
329
|
+
})
|
|
330
|
+
ctx.effect(() => ctx.slots.inject('sidebar.right.pane.tab.title', () => ctx.slots.register({
|
|
331
|
+
name: 'sidebar.right.pane.tab.title', key: BROWSER_ID, store,
|
|
332
|
+
}, BrowserTitle)), 'ui-sidebar-browser.title')
|
|
333
|
+
}
|