Skip to content

Commit

Permalink
Merge branch 'hotfix/0.34.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
intitni committed Sep 18, 2024
2 parents d89df81 + b4b9a35 commit 4191361
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 73 deletions.
27 changes: 7 additions & 20 deletions Core/Sources/SuggestionWidget/ChatPanelWindow.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,34 +9,20 @@ final class ChatPanelWindow: WidgetWindow {
override var canBecomeMain: Bool { true }

private let storeObserver = NSObject()
private let store: StoreOf<ChatPanel>

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,
]
}

Expand All @@ -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),
Expand Down Expand Up @@ -97,7 +84,7 @@ final class ChatPanelWindow: WidgetWindow {
}
}
}

func centerInActiveSpaceIfNeeded() {
guard !isOnActiveSpace else { return }
center()
Expand Down
67 changes: 29 additions & 38 deletions Core/Sources/SuggestionWidget/WidgetWindowsController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -92,7 +92,7 @@ actor WidgetWindowsController: NSObject {
for await _ in sequence {
guard let self else { return }
try Task.checkCancellation()
await handleXcodeFullscreenChange()
await handleSpaceChange()
}
}
}
Expand Down Expand Up @@ -160,7 +160,7 @@ private extension WidgetWindowsController {
switch notification.kind {
case .focusedWindowChanged:
await handleXcodeFullscreenChange()
await handleSpaceChange()
await hideWidgetForTransitions()
await updateWidgetsAndNotifyChangeOfEditor(immediately: true)
case .focusedUIElementChanged:
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -584,7 +584,7 @@ extension WidgetWindowsController {
}

@MainActor
func handleXcodeFullscreenChange() async {
func handleSpaceChange() async {
let activeXcode = await XcodeInspector.shared.safe.activeXcode

let xcode = activeXcode?.appElement
Expand All @@ -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()
}
}
}
Expand Down Expand Up @@ -796,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(
Expand Down Expand Up @@ -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)
}
Expand All @@ -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
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
))
Expand Down Expand Up @@ -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..<history.endIndex {
let message = history[i]
let text = message.content ?? ""
Expand Down
4 changes: 2 additions & 2 deletions Version.xcconfig
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
APP_VERSION = 0.34.0
APP_BUILD = 412
APP_VERSION = 0.34.1
APP_BUILD = 413

0 comments on commit 4191361

Please sign in to comment.