Created
October 17, 2024 11:28
-
-
Save 343max/7d83e1f6bbd401edc430cbc16f7988f3 to your computer and use it in GitHub Desktop.
hammerspoon spoon to toggle dark/light mode in the Android Emulator using Cmd-Shift-A like in the iOS simulator
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- === androidEmulator === | |
--- | |
--- Helpful tools for the Android Emulator | |
--- | |
local obj = {} | |
obj.__index = obj | |
-- Metadata | |
obj.name = "androidEmulator" | |
obj.version = "0.1.0" | |
obj.author = "<[email protected]>" | |
obj.homepage = "" | |
obj.license = "MIT - https://opensource.org/licenses/MIT" | |
local appHotkeys = {} | |
local function createAppSpecificHotkey(app, mods, key, pressedfn) | |
local hotkey = hs.hotkey.new(mods, key, pressedfn) | |
if not appHotkeys[app] then | |
appHotkeys[app] = {} | |
end | |
table.insert(appHotkeys[app], hotkey) | |
local watcher = hs.application.watcher.new(function(appName, eventType) | |
if appName ~= app then return end | |
if eventType == hs.application.watcher.activated then | |
for _, hk in ipairs(appHotkeys[app]) do | |
hk:enable() | |
end | |
else | |
for _, hk in ipairs(appHotkeys[app]) do | |
hk:disable() | |
end | |
end | |
end) | |
-- Start watching | |
watcher:start() | |
return watcher | |
end | |
local function toggleDarkMode() | |
local adb = "~/Library/Android/sdk/platform-tools/adb" | |
local output = hs.execute(adb .. ' shell "cmd uimode night"') | |
local dark_mode = output:find("yes") and "no" or "yes" | |
local command = adb .. ' shell "cmd uimode night ' .. dark_mode .. '"' | |
hs.execute(command) | |
end | |
createAppSpecificHotkey("qemu-system-aarch64", {"cmd", "shift"}, "a", toggleDarkMode) | |
return obj |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment