1+ import Client
12import Preferences
23import SharedUIComponents
34import SwiftUI
5+ import XPCShared
46
57#if canImport(ProHostApp)
68import ProHostApp
@@ -33,7 +35,51 @@ struct ChatSettingsGeneralSectionView: View {
3335 @AppStorage ( \. openChatInBrowserURL) var openChatInBrowserURL
3436 @AppStorage ( \. openChatInBrowserInInAppBrowser) var openChatInBrowserInInAppBrowser
3537
36- init ( ) { }
38+ var refreshExtensionExtensionOpenChatHandlerTask : Task < Void , Never > ?
39+
40+ @MainActor
41+ @Published
42+ var openChatOptions = [ OpenChatMode] ( )
43+
44+ init ( ) {
45+ Task { @MainActor in
46+ refreshExtensionOpenChatHandlers ( )
47+ }
48+ refreshExtensionExtensionOpenChatHandlerTask = Task { [ weak self] in
49+ let sequence = NotificationCenter . default
50+ . notifications ( named: NSApplication . didBecomeActiveNotification)
51+ for await _ in sequence {
52+ guard let self else { return }
53+ await MainActor . run {
54+ self . refreshExtensionOpenChatHandlers ( )
55+ }
56+ }
57+ }
58+ }
59+
60+ @MainActor
61+ func refreshExtensionOpenChatHandlers( ) {
62+ guard let service = try ? getService ( ) else { return }
63+ Task { @MainActor in
64+ let handlers = try await service
65+ . send ( requestBody: ExtensionServiceRequests . GetExtensionOpenChatHandlers ( ) )
66+ openChatOptions = handlers. map {
67+ if $0. isBuiltIn {
68+ return . builtinExtension(
69+ extensionIdentifier: $0. bundleIdentifier,
70+ id: $0. id,
71+ tabName: $0. tabName
72+ )
73+ } else {
74+ return . externalExtension(
75+ extensionIdentifier: $0. bundleIdentifier,
76+ id: $0. id,
77+ tabName: $0. tabName
78+ )
79+ }
80+ }
81+ }
82+ }
3783 }
3884
3985 @Environment ( \. openURL) var openURL
@@ -58,21 +104,27 @@ struct ChatSettingsGeneralSectionView: View {
58104 Form {
59105 Picker (
60106 " Open Chat Mode " ,
61- selection: $settings. openChatMode
107+ selection: . init( get: {
108+ settings. openChatMode. value
109+ } , set: {
110+ settings. openChatMode = . init( $0)
111+ } )
62112 ) {
63- ForEach ( OpenChatMode . allCases, id: \. rawValue) { mode in
113+ Text ( " Open chat panel " ) . tag ( OpenChatMode . chatPanel)
114+ Text ( " Open web page in browser " ) . tag ( OpenChatMode . browser)
115+ ForEach ( settings. openChatOptions) { mode in
64116 switch mode {
65- case . chatPanel :
66- Text ( " Open chat panel " ) . tag ( mode)
67- case . browser :
68- Text ( " Open web page in browser " ) . tag ( mode)
69- case . codeiumChat :
70- Text ( " Open Codeium chat tab " ) . tag ( mode )
117+ case let . builtinExtension ( _ , _ , name ) :
118+ Text ( " Open \( name ) tab " ) . tag ( mode)
119+ case let . externalExtension ( _ , _ , name ) :
120+ Text ( " Open \( name ) tab " ) . tag ( mode)
121+ default :
122+ EmptyView ( )
71123 }
72124 }
73125 }
74126
75- if settings. openChatMode == . browser {
127+ if settings. openChatMode. value == . browser {
76128 TextField (
77129 " Chat web page URL " ,
78130 text: $settings. openChatInBrowserURL,
0 commit comments