@@ -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 )
0 commit comments