From 6511f2270e77fbf9c926ea89a5b9727151e025f7 Mon Sep 17 00:00:00 2001 From: Shx Guo Date: Wed, 18 Sep 2024 17:30:33 +0800 Subject: [PATCH 1/4] Fix building in Xcode 16 --- .../Services/GitHubCopilotChatService.swift | 28 ++++++++++--------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/Tool/Sources/GitHubCopilotService/Services/GitHubCopilotChatService.swift b/Tool/Sources/GitHubCopilotService/Services/GitHubCopilotChatService.swift index 0247dfafa..9f4062ae0 100644 --- a/Tool/Sources/GitHubCopilotService/Services/GitHubCopilotChatService.swift +++ b/Tool/Sources/GitHubCopilotService/Services/GitHubCopilotChatService.swift @@ -26,21 +26,23 @@ public final class GitHubCopilotChatService: BuiltinExtensionChatServiceType { let editorContent = await XcodeInspector.shared.getFocusedEditorContent() let workDoneToken = UUID().uuidString let turns = convertHistory(history: history, message: message) + let doc = GitHubCopilotDoc( + source: editorContent?.editorContent?.content ?? "", + tabSize: 1, + indentSize: 4, + insertSpaces: true, + path: editorContent?.documentURL.path ?? "", + uri: editorContent?.documentURL.path ?? "", + relativePath: editorContent?.relativePath ?? "", + languageId: editorContent?.language ?? .plaintext, + position: editorContent?.editorContent?.cursorPosition ?? .zero + ) + let request = GitHubCopilotRequest.ConversationCreate(requestBody: .init( workDoneToken: workDoneToken, turns: turns, capabilities: .init(allSkills: true, skills: []), - doc: .init( - source: editorContent?.editorContent?.content ?? "", - tabSize: 1, - indentSize: 4, - insertSpaces: true, - path: editorContent?.documentURL.path ?? "", - uri: editorContent?.documentURL.path ?? "", - relativePath: editorContent?.relativePath ?? "", - languageId: editorContent?.language ?? .plaintext, - position: editorContent?.editorContent?.cursorPosition ?? .zero - ), + doc: doc, source: .panel, workspaceFolder: workspace.projectURL.path )) @@ -132,11 +134,11 @@ extension GitHubCopilotChatService { let systemPrompt = history .filter { $0.role == .system }.compactMap(\.content) .joined(separator: "\n\n") - + if !systemPrompt.isEmpty { turns.append(.init(request: "[System Prompt]\n\(systemPrompt)", response: "OK!")) } - + for i in firstIndexOfUserMessage.. Date: Thu, 19 Sep 2024 00:15:16 +0800 Subject: [PATCH 2/4] Fix widget location for macOS 15 --- .../SuggestionWidget/ChatPanelWindow.swift | 27 ++------ .../WidgetWindowsController.swift | 65 ++++++++----------- 2 files changed, 35 insertions(+), 57 deletions(-) diff --git a/Core/Sources/SuggestionWidget/ChatPanelWindow.swift b/Core/Sources/SuggestionWidget/ChatPanelWindow.swift index 462fc1f4f..65c99c592 100644 --- a/Core/Sources/SuggestionWidget/ChatPanelWindow.swift +++ b/Core/Sources/SuggestionWidget/ChatPanelWindow.swift @@ -9,34 +9,20 @@ final class ChatPanelWindow: WidgetWindow { override var canBecomeMain: Bool { true } private let storeObserver = NSObject() + private let store: StoreOf var minimizeWindow: () -> Void = {} - - override var defaultCollectionBehavior: NSWindow.CollectionBehavior { - [ - .fullScreenAuxiliary, - .transient, - .fullScreenPrimary, - .fullScreenAllowsTiling, - ] + + var isDetached: Bool { + store.withState({$0.isDetached}) } - override var switchingSpaceCollectionBehavior: NSWindow.CollectionBehavior { - [ - .fullScreenAuxiliary, - .transient, - .fullScreenPrimary, - .fullScreenAllowsTiling, - ] - } - - override var fullscreenCollectionBehavior: NSWindow.CollectionBehavior { + override var defaultCollectionBehavior: NSWindow.CollectionBehavior { [ .fullScreenAuxiliary, .transient, .fullScreenPrimary, .fullScreenAllowsTiling, - .canJoinAllSpaces, ] } @@ -45,6 +31,7 @@ final class ChatPanelWindow: WidgetWindow { chatTabPool: ChatTabPool, minimizeWindow: @escaping () -> Void ) { + self.store = store self.minimizeWindow = minimizeWindow super.init( contentRect: .init(x: 0, y: 0, width: 300, height: 400), @@ -97,7 +84,7 @@ final class ChatPanelWindow: WidgetWindow { } } } - + func centerInActiveSpaceIfNeeded() { guard !isOnActiveSpace else { return } center() diff --git a/Core/Sources/SuggestionWidget/WidgetWindowsController.swift b/Core/Sources/SuggestionWidget/WidgetWindowsController.swift index 304f6d762..e9d04f098 100644 --- a/Core/Sources/SuggestionWidget/WidgetWindowsController.swift +++ b/Core/Sources/SuggestionWidget/WidgetWindowsController.swift @@ -82,7 +82,7 @@ actor WidgetWindowsController: NSObject { } updateWindowStateTask = Task { [weak self] in - if let self { await handleXcodeFullscreenChange() } + if let self { await handleSpaceChange() } await withThrowingTaskGroup(of: Void.self) { [weak self] group in // active space did change @@ -92,7 +92,7 @@ actor WidgetWindowsController: NSObject { for await _ in sequence { guard let self else { return } try Task.checkCancellation() - await handleXcodeFullscreenChange() + await handleSpaceChange() } } } @@ -160,7 +160,7 @@ private extension WidgetWindowsController { switch notification.kind { case .focusedWindowChanged: - await handleXcodeFullscreenChange() + await handleSpaceChange() await hideWidgetForTransitions() await updateWidgetsAndNotifyChangeOfEditor(immediately: true) case .focusedUIElementChanged: @@ -402,7 +402,7 @@ extension WidgetWindowsController { windows.toastWindow.alphaValue = noFocus ? 0 : 1 if isChatPanelDetached { - windows.chatPanelWindow.isWindowHidden = !hasChat + windows.chatPanelWindow.isWindowHidden = false } else { windows.chatPanelWindow.isWindowHidden = noFocus } @@ -436,7 +436,7 @@ extension WidgetWindowsController { } windows.toastWindow.alphaValue = noFocus ? 0 : 1 if isChatPanelDetached { - windows.chatPanelWindow.isWindowHidden = !hasChat + windows.chatPanelWindow.isWindowHidden = false } else { windows.chatPanelWindow.isWindowHidden = noFocus && !windows .chatPanelWindow.isKeyWindow @@ -584,7 +584,7 @@ extension WidgetWindowsController { } @MainActor - func handleXcodeFullscreenChange() async { + func handleSpaceChange() async { let activeXcode = await XcodeInspector.shared.safe.activeXcode let xcode = activeXcode?.appElement @@ -593,19 +593,26 @@ extension WidgetWindowsController { } else { false } + + let isXcodeActive = xcode?.isFrontmost ?? false - [ - windows.chatPanelWindow, + await [ windows.sharedPanelWindow, windows.suggestionPanelWindow, windows.widgetWindow, windows.toastWindow, ].forEach { - $0.send(.didChangeActiveSpace(fullscreen: isFullscreen)) + if isXcodeActive { + $0.moveToActiveSpace() + } + } + + if isXcodeActive, !windows.chatPanelWindow.isDetached { + await windows.chatPanelWindow.moveToActiveSpace() } - if windows.fullscreenDetector.isOnActiveSpace, xcode?.focusedWindow != nil { - windows.orderFront() + if await windows.fullscreenDetector.isOnActiveSpace, xcode?.focusedWindow != nil { + await windows.orderFront() } } } @@ -845,26 +852,10 @@ class WidgetWindow: CanBecomeKeyWindow { case switchingSpace } - enum Action { - case didChangeActiveSpace(fullscreen: Bool) - } - var defaultCollectionBehavior: NSWindow.CollectionBehavior { [.fullScreenAuxiliary, .transient] } - var fullscreenCollectionBehavior: NSWindow.CollectionBehavior { - // .canJoinAllSpaces is required for macOS 15 (beta?) to display widgets in fullscreen mode. - // But adding this behavior will create another issue that the widgets will display - // whenever user switch spaces, so we are setting it only when the window is in fullscreen - // mode. - [.fullScreenAuxiliary, .transient, .canJoinAllSpaces] - } - - var switchingSpaceCollectionBehavior: NSWindow.CollectionBehavior { - [.fullScreenAuxiliary, .transient] - } - var isFullscreen: Bool { styleMask.contains(.fullScreen) } @@ -876,19 +867,19 @@ class WidgetWindow: CanBecomeKeyWindow { case .none: collectionBehavior = defaultCollectionBehavior case .switchingSpace: - collectionBehavior = switchingSpaceCollectionBehavior - case let .normal(fullscreen): - collectionBehavior = fullscreen - ? fullscreenCollectionBehavior - : defaultCollectionBehavior + collectionBehavior = defaultCollectionBehavior.union(.moveToActiveSpace) + case .normal: + collectionBehavior = defaultCollectionBehavior } } } - - func send(_ action: Action) { - switch action { - case let .didChangeActiveSpace(fullscreen): - state = .normal(fullscreen: fullscreen) + + func moveToActiveSpace() { + let previousState = state + state = .switchingSpace + Task { @MainActor in + try await Task.sleep(nanoseconds: 50_000_000) + self.state = previousState } } } From 04b68bace8e4d9e85a35c846f03bd71bad75d15a Mon Sep 17 00:00:00 2001 From: Shx Guo Date: Thu, 19 Sep 2024 00:15:31 +0800 Subject: [PATCH 3/4] Bump version --- Version.xcconfig | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Version.xcconfig b/Version.xcconfig index 6b4ae4b3b..32d3ed1c5 100644 --- a/Version.xcconfig +++ b/Version.xcconfig @@ -1,3 +1,3 @@ -APP_VERSION = 0.34.0 -APP_BUILD = 412 +APP_VERSION = 0.34.1 +APP_BUILD = 413 From b4b9a35e27900c82fe0ebbfc6b7992c6b7de2753 Mon Sep 17 00:00:00 2001 From: Shx Guo Date: Thu, 19 Sep 2024 00:44:59 +0800 Subject: [PATCH 4/4] Give toast window higher level --- Core/Sources/SuggestionWidget/WidgetWindowsController.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Core/Sources/SuggestionWidget/WidgetWindowsController.swift b/Core/Sources/SuggestionWidget/WidgetWindowsController.swift index e9d04f098..6d0bb0e28 100644 --- a/Core/Sources/SuggestionWidget/WidgetWindowsController.swift +++ b/Core/Sources/SuggestionWidget/WidgetWindowsController.swift @@ -803,7 +803,7 @@ public final class WidgetWindows { it.isReleasedWhenClosed = false it.isOpaque = false it.backgroundColor = .clear - it.level = widgetLevel(0) + it.level = widgetLevel(2) it.hasShadow = false it.contentView = NSHostingView( rootView: ToastPanelView(store: store.scope(