Skip to content

Commit f65c859

Browse files
committed
Fix QR WiFi window position
1 parent 1402f5c commit f65c859

File tree

3 files changed

+21
-14
lines changed

3 files changed

+21
-14
lines changed

macos/sol-macOS/AppDelegate.swift

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -174,9 +174,9 @@ class AppDelegate: NSObject, NSApplicationDelegate,
174174
let txt = $0.string(forType: .string)
175175
let bundle = $1?.bundle
176176
guard let txt else { return }
177-
177+
178178
SolEmitter.sharedInstance.textCopied(txt, bundle)
179-
179+
180180
// let url = $0.string(forType: .URL)
181181
// if url != nil {
182182
// handlePastedText(url!, fileExtension: "url")
@@ -577,27 +577,34 @@ class AppDelegate: NSObject, NSApplicationDelegate,
577577
else {
578578
return
579579
}
580-
581-
let variantEnum: ToastVariant = switch variant {
582-
case "error": .error
583-
case "success": .success
584-
default: .none
585-
}
580+
581+
let variantEnum: ToastVariant =
582+
switch variant {
583+
case "error": .error
584+
case "success": .success
585+
default: .none
586+
}
586587

587588
let toastView = ToastView(text: text, variant: variantEnum, image: image)
588589
let rootView = NSHostingView(rootView: toastView)
590+
// Force the NSHostingView to size itself based on the SwiftUI view
591+
rootView.setFrameSize(rootView.fittingSize)
592+
593+
// Create the window
589594
toastWindow.contentView = rootView
595+
toastWindow.setContentSize(rootView.fittingSize) // Adjust window size to match the content
590596

591597
let deadline = timeout != nil ? DispatchTime.now() + timeout!.doubleValue : .now() + 2
598+
let x = mainScreen.frame.size.width / 2 - toastWindow.frame.width / 2
592599
var y = mainScreen.frame.origin.y + mainScreen.frame.size.height * 0.1
593600

594601
if image != nil {
595-
y += 420
602+
y = mainScreen.frame.origin.y + toastWindow.frame.height
596603
}
597604

598605
toastWindow.setFrameOrigin(
599606
NSPoint(
600-
x: mainScreen.frame.size.width / 2 - toastWindow.frame.width / 2,
607+
x: x,
601608
y: y
602609
))
603610
toastWindow.makeKeyAndOrderFront(nil)

macos/sol-macOS/views/Toast.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import Foundation
22
import Cocoa
33

4-
final class Toast: NSWindow, NSWindowDelegate {
4+
final class Toast: NSPanel, NSWindowDelegate {
55
init(contentRect: NSRect) {
66
super.init(
77
contentRect: contentRect,
@@ -26,10 +26,10 @@ final class Toast: NSWindow, NSWindowDelegate {
2626
}
2727

2828
override var canBecomeKey: Bool {
29-
return true
29+
return false
3030
}
3131

3232
override var canBecomeMain: Bool {
33-
return true
33+
return false
3434
}
3535
}

macos/sol-macOS/views/ToastView.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ struct ToastView: View {
6464
}
6565
.padding(EdgeInsets(top: 10, leading: 15, bottom: 10, trailing: 15))
6666
.background(
67-
VisualEffectBlur(tintColor: variant == .error ? .red : .green)
67+
VisualEffectBlur()
6868
.cornerRadius(10)
6969
)
7070
.edgesIgnoringSafeArea(.all)

0 commit comments

Comments
 (0)