Skip to content

Commit

Permalink
Dark mode
Browse files Browse the repository at this point in the history
  • Loading branch information
alin23 committed Aug 10, 2021
1 parent 7aa0edd commit a0e238d
Show file tree
Hide file tree
Showing 57 changed files with 495 additions and 250 deletions.
2 changes: 1 addition & 1 deletion .gitsecret/paths/mapping.cfg
Expand Up @@ -4,4 +4,4 @@ bin/.env.sh:4dd6f279599d779f48d342e0bfefe8fc98a9a35ffedb6d7971bf10c590c86378
Lunar/Modes/SensorMode.swift:e0429ccc0cae179ae700ef3a71bdd15b0dc87532e3f77518c4c2df64bd9406b8
Lunar/Modes/SyncMode.swift:a3ece7c30629fd8c17241a998bb2203e24b312ea343639f6c2608bbd2ad40ad0
Lunar/Modes/LocationMode.swift:ea065494e7f65ff5f282eb77e150f61991bb105e7d002c428619cd97f52a5722
Lunar/Data/Pro.swift:a00fd10086b35a0caffc9191d054b0316694bf533f33030b69e6834192d94ac8
Lunar/Data/Pro.swift:07076ce009f6ed91df92509a7115b55111479a2713f30148dae1a33d1973517c
Binary file modified Images/clear-off@1x.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Images/clear-off@2x.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Images/clear-on@1x.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Images/clear-on@2x.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
66 changes: 53 additions & 13 deletions Lunar/AppDelegate.swift
Expand Up @@ -156,6 +156,8 @@ class AppDelegate: NSObject, NSApplicationDelegate, CLLocationManagerDelegate, N
set { _windowControllerLock.around { _windowController = newValue } }
}

var darkMode: Bool { (UserDefaults.standard.string(forKey: "AppleInterfaceStyle") ?? "Light") == "Dark" }

func menuWillOpen(_: NSMenu) {
let version = Bundle.main.infoDictionary?["CFBundleShortVersionString"] as? String ?? "4"

Expand Down Expand Up @@ -537,22 +539,10 @@ class AppDelegate: NSObject, NSApplicationDelegate, CLLocationManagerDelegate, N
}
DistributedNotificationCenter.default()
.publisher(for: NSNotification.Name(rawValue: kAppleInterfaceThemeChangedNotification), object: nil)
.removeDuplicates()
.sink { _ in self.adaptAppearance() }
.sink { _ in self.recreateWindow() }
.store(in: &observers)
}

func adaptAppearance() {
mainThread {
guard let menuPopover = POPOVERS["menu"]! else { return }
menuPopover.appearance = NSAppearance(named: .vibrantLight)
let appearanceDescription = NSApplication.shared.effectiveAppearance.debugDescription.lowercased()
if appearanceDescription.contains("dark") {
menuPopover.appearance = NSAppearance(named: .vibrantDark)
}
}
}

func listenForScreenConfigurationChanged() {
NSWorkspace.shared.notificationCenter
.publisher(for: NSWorkspace.activeSpaceDidChangeNotification, object: nil)
Expand Down Expand Up @@ -650,6 +640,56 @@ class AppDelegate: NSObject, NSApplicationDelegate, CLLocationManagerDelegate, N
}.store(in: &observers)
}

func initPopover<T: NSViewController>(
_ popoverKey: String,
identifier: String,
controllerType _: T.Type,
appearance: NSAppearance.Name = .vibrantLight
) {
if !POPOVERS.keys.contains(popoverKey) || POPOVERS[popoverKey]! == nil {
POPOVERS[popoverKey] = NSPopover()
}

guard let popover = POPOVERS[popoverKey]! else { return }

if popover.contentViewController == nil, let stb = NSStoryboard.main,
let controller = stb.instantiateController(
withIdentifier: NSStoryboard.SceneIdentifier(identifier)
) as? T
{
popover.contentViewController = controller
popover.contentViewController!.loadView()
popover.appearance = NSAppearance(named: appearance)
}
}

func initPopovers() {
initPopover(
"help",
identifier: "HelpPopoverController",
controllerType: HelpPopoverController.self,
appearance: appDelegate.darkMode ? .vibrantDark : .vibrantLight
)
initPopover(
"settings",
identifier: "SettingsPopoverController",
controllerType: SettingsPopoverController.self,
appearance: appDelegate.darkMode ? .vibrantDark : .vibrantLight
)
}

func recreateWindow() {
if windowController?.window != nil {
let shouldShow = windowController!.window!.isVisible
windowController?.close()
windowController?.window = nil
windowController = nil
if shouldShow {
showWindow()
}
}
}

func updateDataPointObserver() {
NotificationCenter.default.removeObserver(
self,
Expand Down
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Lunar/Assets.xcassets/AppIcon.appiconset/Icon Artwork Small@32.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Lunar/Assets.xcassets/AppIcon.appiconset/Icon Artwork@256.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Lunar/Assets.xcassets/AppIcon.appiconset/Icon Artwork@512.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
38 changes: 38 additions & 0 deletions Lunar/Assets.xcassets/Caption.colorset/Contents.json
@@ -0,0 +1,38 @@
{
"colors" : [
{
"color" : {
"color-space" : "srgb",
"components" : {
"alpha" : "1.000",
"blue" : "0.200",
"green" : "0.012",
"red" : "0.063"
}
},
"idiom" : "universal"
},
{
"appearances" : [
{
"appearance" : "luminosity",
"value" : "dark"
}
],
"color" : {
"color-space" : "srgb",
"components" : {
"alpha" : "1.000",
"blue" : "1.000",
"green" : "1.000",
"red" : "1.000"
}
},
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
41 changes: 37 additions & 4 deletions Lunar/Assets.xcassets/Display.imageset/Contents.json
@@ -1,23 +1,56 @@
{
"images" : [
{
"idiom" : "universal",
"filename" : "monitor@1x.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"appearances" : [
{
"appearance" : "luminosity",
"value" : "dark"
}
],
"filename" : "monitor@1x-1.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "monitor@2x.png",
"idiom" : "universal",
"scale" : "2x"
},
{
"appearances" : [
{
"appearance" : "luminosity",
"value" : "dark"
}
],
"filename" : "monitor@2x-1.png",
"idiom" : "universal",
"scale" : "2x"
},
{
"filename" : "monitor@3x.png",
"idiom" : "universal",
"scale" : "3x"
},
{
"appearances" : [
{
"appearance" : "luminosity",
"value" : "dark"
}
],
"filename" : "monitor@3x-1.png",
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
"author" : "xcode",
"version" : 1
}
}
}
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Lunar/Assets.xcassets/Display.imageset/monitor@1x.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
38 changes: 38 additions & 0 deletions Lunar/Assets.xcassets/Gray.colorset/Contents.json
@@ -0,0 +1,38 @@
{
"colors" : [
{
"color" : {
"color-space" : "srgb",
"components" : {
"alpha" : "1.000",
"blue" : "0.494",
"green" : "0.466",
"red" : "0.494"
}
},
"idiom" : "universal"
},
{
"appearances" : [
{
"appearance" : "luminosity",
"value" : "dark"
}
],
"color" : {
"color-space" : "srgb",
"components" : {
"alpha" : "1.000",
"blue" : "0.712",
"green" : "0.696",
"red" : "0.702"
}
},
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
38 changes: 38 additions & 0 deletions Lunar/Assets.xcassets/Inverted.colorset/Contents.json
@@ -0,0 +1,38 @@
{
"colors" : [
{
"color" : {
"color-space" : "srgb",
"components" : {
"alpha" : "1.000",
"blue" : "1.000",
"green" : "1.000",
"red" : "1.000"
}
},
"idiom" : "universal"
},
{
"appearances" : [
{
"appearance" : "luminosity",
"value" : "dark"
}
],
"color" : {
"color-space" : "srgb",
"components" : {
"alpha" : "1.000",
"blue" : "0.000",
"green" : "0.102",
"red" : "0.129"
}
},
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
33 changes: 33 additions & 0 deletions Lunar/Assets.xcassets/Moon.imageset/Contents.json
Expand Up @@ -5,15 +5,48 @@
"idiom" : "universal",
"scale" : "1x"
},
{
"appearances" : [
{
"appearance" : "luminosity",
"value" : "dark"
}
],
"filename" : "Moon Dark Mode@1x.pdf",
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "Moon@2x.pdf",
"idiom" : "universal",
"scale" : "2x"
},
{
"appearances" : [
{
"appearance" : "luminosity",
"value" : "dark"
}
],
"filename" : "Moon Dark Mode@2x.pdf",
"idiom" : "universal",
"scale" : "2x"
},
{
"filename" : "Moon@3x.pdf",
"idiom" : "universal",
"scale" : "3x"
},
{
"appearances" : [
{
"appearance" : "luminosity",
"value" : "dark"
}
],
"filename" : "Moon Dark Mode@3x.pdf",
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Lunar/Assets.xcassets/clear-off.imageset/clear-off@1x.png
Binary file modified Lunar/Assets.xcassets/clear-off.imageset/clear-off@2x.png
Binary file modified Lunar/Assets.xcassets/clear-on.imageset/clear-on@1x.png
Binary file modified Lunar/Assets.xcassets/clear-on.imageset/clear-on@2x.png

0 comments on commit a0e238d

Please sign in to comment.