Skip to content

Using system appearance settings to choose between dark and light UI #8

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 0 additions & 7 deletions Shared/BezelMessage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,6 @@ extension BezelMessage {
static let clipboard = BezelMessage(imageName: "copy", title: "Link Copied")
static let installed = BezelMessage(imageName: "message", title: "Xgist is Installed")

private var dict: [String: String] {
return [
"imageName": imageName,
"title": title
]
}

var urlEncoded: URL? {
var components = URLComponents(string: "XgistMessage://message")

Expand Down
4 changes: 0 additions & 4 deletions Xgist/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,5 @@ class AppDelegate: NSObject, NSApplicationDelegate {
}
}

@objc private func killAgent() {
NSApp.terminate(nil)
}

}

19 changes: 17 additions & 2 deletions Xgist/BezelMessageWindowController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,25 @@ final class BezelMessageWindowController: NSWindowController {
window.setFrame(adjustedRect, display: false)
}

private var backgroundMaterial: NSVisualEffectMaterial {
guard let systemTheme = UserDefaults.standard.object(forKey: "AppleInterfaceStyle") as? String else { return .mediumLight }

return (systemTheme == "Dark") ? .dark : .mediumLight
}

private var appearance: NSAppearance? {
let name = backgroundMaterial == .dark ? NSAppearanceNameVibrantDark : NSAppearanceNameAqua

return NSAppearance(named: name)
}

private lazy var vfxView: NSVisualEffectView = {
let v = NSVisualEffectView(frame: .zero)

v.state = .active
v.blendingMode = .behindWindow
v.material = .dark
v.appearance = NSAppearance(named: NSAppearanceNameVibrantDark)
v.material = self.backgroundMaterial
v.appearance = self.appearance
v.maskImage = self.maskImage(with: Metrics.cornerRadius)

return v
Expand Down Expand Up @@ -159,6 +171,9 @@ final class BezelMessageWindowController: NSWindowController {
}

func show(for duration: TimeInterval, completion: (() -> Void)? = nil) {
vfxView.material = backgroundMaterial
vfxView.appearance = appearance

guard let window = window else { return }

window.alphaValue = 0
Expand Down