Skip to content
Merged
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
2 changes: 2 additions & 0 deletions autoload/lumen/platforms.vim
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
let s:platform = ''
if has('linux')
let s:platform = 'linux'
elseif has('osx')
let s:platform = 'macos'
endif

func lumen#platforms#call(func, ...)
Expand Down
17 changes: 17 additions & 0 deletions autoload/lumen/platforms/macos.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
func lumen#platforms#macos#watch_cmd()
let path = fnamemodify(resolve(expand('<sfile>:p')), ':h')
return [path . "/autoload/lumen/platforms/macos/watcher.swift"]
endfunc

func lumen#platforms#macos#parse_line(line)
if a:line == "Dark"
call lumen#dark_hook()
else
call lumen#light_hook()
endif
endfunc

func lumen#platforms#macos#oneshot()
let out = system(join(lumen#platforms#macos#watch_cmd() + ["get"]))
call lumen#platforms#macos#parse_line(out)
endfunc
35 changes: 35 additions & 0 deletions autoload/lumen/platforms/macos/watcher.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/usr/bin/env swift

// Based on https://github.com/bouk/dark-mode-notify/blob/main/dark-mode-notify.swift (MIT license)
// Which itself is based on https://github.com/mnewt/dotemacs/blob/master/bin/dark-mode-notifier.swift (Unlicense license)

import Cocoa
import Darwin

var isAppearanceDark: Bool {
if #available(macOS 11.0, *) {
return NSAppearance.currentDrawing().bestMatch(from: [.darkAqua, .aqua]) == .darkAqua
} else {
return NSAppearance.current.bestMatch(from: [.darkAqua, .aqua]) == .darkAqua
}
}

func printAppearance() {
let string = isAppearanceDark ? "Dark" : "Light"
try! FileHandle.standardOutput.write(contentsOf: Data((string + "\n").utf8))
// print(string) // doesn't work for some strange reason?!
}

if CommandLine.arguments.dropFirst(1).first == "get" {
printAppearance()
exit(0)
}

DistributedNotificationCenter.default.addObserver(
forName: Notification.Name("AppleInterfaceThemeChangedNotification"),
object: nil,
queue: nil) { _ in
printAppearance()
}

NSApplication.shared.run()