Skip to content
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
29 changes: 24 additions & 5 deletions BLEUnlock/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSMenuDelegate, NSMenuItemVa
var unlockedAt = 0.0
var inScreensaver = false
var lastRSSI: Int? = nil
var didRunEventScriptSinceLock = false

func menuWillOpen(_ menu: NSMenu) {
if menu == deviceMenu {
Expand Down Expand Up @@ -234,11 +235,17 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSMenuDelegate, NSMenuItemVa
tryUnlockScreen()
}
} else {
if (!isScreenLocked() && ble.lockRSSI != ble.LOCK_DISABLED) {
pauseNowPlaying()
lockOrSaveScreen()
notifyUser(reason)
runScript(reason)
if ble.lockRSSI != ble.LOCK_DISABLED {
let locked = isScreenLocked()
if !locked {
pauseNowPlaying()
lockOrSaveScreen()
notifyUser(reason)
}
if (!locked || prefs.bool(forKey: "runEventScriptWhileLocked")) && !didRunEventScriptSinceLock {
runScript(reason)
didRunEventScriptSinceLock = true
}
}
manualLock = false
}
Expand Down Expand Up @@ -340,6 +347,7 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSMenuDelegate, NSMenuItemVa
}

@objc func onUnlock() {
didRunEventScriptSinceLock = false
Timer.scheduledTimer(withTimeInterval: 2, repeats: false, block: { _ in
print("onUnlock")
if Date().timeIntervalSince1970 >= self.unlockedAt + 10 {
Expand Down Expand Up @@ -526,6 +534,12 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSMenuDelegate, NSMenuItemVa
prefs.set(pauseNowPlaying, forKey: "pauseItunes")
menuItem.state = pauseNowPlaying ? .on : .off
}

@objc func toggleRunEventScriptWhileLocked(_ menuItem: NSMenuItem) {
let value = !prefs.bool(forKey: "runEventScriptWhileLocked")
prefs.set(value, forKey: "runEventScriptWhileLocked")
menuItem.state = value ? .on : .off
}

@objc func toggleUseScreensaver(_ menuItem: NSMenuItem) {
let value = !prefs.bool(forKey: "screensaver")
Expand Down Expand Up @@ -633,6 +647,11 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSMenuDelegate, NSMenuItemVa
item.state = .on
}

item = mainMenu.addItem(withTitle: t("run_event_script_while_locked"), action: #selector(toggleRunEventScriptWhileLocked), keyEquivalent: "")
if prefs.bool(forKey: "runEventScriptWhileLocked") {
item.state = .on
}

item = mainMenu.addItem(withTitle: t("use_screensaver_to_lock"), action: #selector(toggleUseScreensaver), keyEquivalent: "")
if prefs.bool(forKey: "screensaver") {
item.state = .on
Expand Down
1 change: 1 addition & 0 deletions BLEUnlock/Base.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"password_info" = "Your password will be securely stored in Keychain.";
"password_not_set" = "Password is not set.";
"pause_now_playing" = "Pause \"Now Playing\" while Locked";
"run_event_script_while_locked" = "Run \"event\" Script while Locked";
"quit" = "Quit BLEUnlock";
"scanning" = "Scanning…";
"seconds" = "seconds";
Expand Down
1 change: 1 addition & 0 deletions BLEUnlock/da.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"password_info" = "Din adgangskode vil blive gemt sikkert i nøglering.";
"password_not_set" = "Der er ikke indstillet et kodeord.";
"pause_now_playing" = "Pause \"Afspilning nu\", mens den er låst";
"run_event_script_while_locked" = "Kør \"event\"-scriptet, mens den er låst";
"quit" = "Afslut BLEUnlock";
"scanning" = "Scanning…";
"seconds" = "seconder";
Expand Down
1 change: 1 addition & 0 deletions BLEUnlock/de.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"password_info" = "Das Passwort wurde sicher am Schlüsselbund gespeichert.";
"password_not_set" = "Kein Passwort gesetzt.";
"pause_now_playing" = "Pause \"Spielt jetzt\" während der Sperre";
"run_event_script_while_locked" = "\"event\"-Skript während der Sperre ausführen";
"quit" = "BLEUnlock beenden";
"scanning" = "Scanning";
"seconds" = "seconds";
Expand Down
1 change: 1 addition & 0 deletions BLEUnlock/ja.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"password_info" = "パスワードはキーチェーンに安全に保存されます。";
"password_not_set" = "パスワードが設定されていません。";
"pause_now_playing" = "ロック中 \"再生中\" を一時停止";
"run_event_script_while_locked" = "ロック中に \"event\" スクリプトを実行";
"quit" = "BLEUnlock を終了";
"scanning" = "スキャン中…";
"seconds" = "秒";
Expand Down
1 change: 1 addition & 0 deletions BLEUnlock/nb.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"password_info" = "Passordet lagres sikkert i nøkkelringen.";
"password_not_set" = "Passord er ikke angitt.";
"pause_now_playing" = "Stans \"Avspilling nå\" mens den er låst";
"run_event_script_while_locked" = "Kjør \"event\"-skriptet mens den er låst";
"quit" = "Slutte BLEUnlock";
"scanning" = "kcanning…";
"seconds" = "seconder";
Expand Down
1 change: 1 addition & 0 deletions BLEUnlock/sv.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"password_info" = "Ditt lösenord lagras säkert i nyckelringen.";
"password_not_set" = "Inget lösenordet har angetts.";
"pause_now_playing" = "Pausa \"Spela nu\" när låst";
"run_event_script_while_locked" = "Kör \"event\"-skript när låst";
"quit" = "Avsluta BLEUnlock";
"scanning" = "Skannar…";
"seconds" = "sekunder";
Expand Down
1 change: 1 addition & 0 deletions BLEUnlock/tr.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"password_info" = "Şifreniz güvenli bir şekilde anahtar zincirinde saklanacaktır.";
"password_not_set" = "Şifre belirlenmedi.";
"pause_now_playing" = "Kilitliyken \"Now Playing\" beklet";
"run_event_script_while_locked" = "Kilitliyken \"event\" betiğini çalıştır";
"quit" = "BLEUnlock'tan çıkış";
"scanning" = "Taranıyor…";
"seconds" = "saniye";
Expand Down
1 change: 1 addition & 0 deletions BLEUnlock/zh-Hans.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"password_info" = "您的密码将安全地存储在钥匙串中。";
"password_not_set" = "密码未设置。";
"pause_now_playing" = "锁定时暂停\"播放中\"";
"run_event_script_while_locked" = "锁定时运行 \"event\" 脚本";
"quit" = "退出BLEUnlock";
"scanning" = "扫描中…";
"seconds" = "秒钟";
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ No-Signal Timeout | Time between last signal reception and locking. If you exper
Wake on Proximity | Wakes up the display from sleep when the BLE device approaches while locking.
Wake without Unlocking | BLEUnlock will not unlock the Mac when the display wakes up from sleep, whether automatically via "Wake on Proximity" or manually. This allows for compatibility with the macOS built-in unlock with Apple Watch feature (which can operate immediately after BLEUnlock wakes the screen), or if you just prefer the lock screen to appear more quickly but don't want it to auto-unlock.
Pause "Now Playing" while Locked | On lock/unlock, BLEUnlock pauses/unpauses playback of music or video (including Apple Music, QuickTime Player and Spotify) that is controlled by *Now Playing* widget or the ⏯ key on the keyboard.
Run "event" Script while Locked | If the screen is already locked (for example, the user locks it manually and then walks away), the event script still runs. When this option is disabled, the event script runs only when BLEUnlock itself locks the screen (default behavior).
Use Screensaver to Lock | If this option is set, BLEUnlock launches screensaver instead of locking. For this option to work properly, you need to set *Require password **immediately** after sleep or screen saver begins* option in *Security & Privacy* preference pane.
Turn Off Screen on Lock | Turn off the display immediately when locking.
Set Password... | If you changed your login password, use this.
Expand Down