-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFloatingPanelController.swift
More file actions
46 lines (38 loc) · 1.1 KB
/
FloatingPanelController.swift
File metadata and controls
46 lines (38 loc) · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import Cocoa
import SwiftUI
final class FloatingPanelController {
private let panel: NSPanel
private let contentView: FloatingBrowserView
init() {
self.contentView = FloatingBrowserView()
let hosting = NSHostingView(rootView: contentView)
hosting.frame = NSRect(x: 0, y: 0, width: 520, height: 720)
panel = NSPanel(
contentRect: hosting.frame,
styleMask: [.titled, .closable, .resizable],
backing: .buffered,
defer: false
)
panel.title = "Floating Browser"
panel.isFloatingPanel = true
panel.level = .floating
panel.collectionBehavior = [.canJoinAllSpaces, .fullScreenAuxiliary]
panel.center()
panel.contentView = hosting
panel.makeKeyAndOrderFront(nil)
}
func show() {
panel.orderFrontRegardless()
panel.makeKey()
}
func toggleVisibility() {
if panel.isVisible {
panel.orderOut(nil)
} else {
show()
}
}
func takeScreenshot() {
contentView.screenshotRequested()
}
}