Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Require Node.js 12.20 and move to ESM
- Loading branch information
1 parent
e870356
commit 82a4726
Showing
7 changed files
with
59 additions
and
48 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1 @@ | ||
* text=auto | ||
*.js text eol=lf | ||
dark-mode binary | ||
* text=auto eol=lf |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,32 @@ | ||
'use strict'; | ||
const runJxa = require('run-jxa'); | ||
import {runJxa} from 'run-jxa'; | ||
|
||
const prop = `Application('System Events').appearancePreferences.darkMode`; | ||
const property = 'Application(\'System Events\').appearancePreferences.darkMode'; | ||
|
||
exports.enable = () => runJxa(`${prop} = true`); | ||
exports.disable = () => runJxa(`${prop} = false`); | ||
const darkMode = {}; | ||
|
||
exports.toggle = force => { | ||
darkMode.enable = async () => { | ||
await runJxa(`${property} = true`); | ||
}; | ||
|
||
darkMode.disable = async () => { | ||
await runJxa(`${property} = false`); | ||
}; | ||
|
||
darkMode.toggle = async force => { | ||
if (typeof force === 'boolean') { | ||
return force ? exports.enable() : exports.disable(); | ||
// eslint-disable-next-line unicorn/prefer-ternary | ||
if (force) { | ||
await darkMode.enable(); | ||
} else { | ||
await darkMode.disable(); | ||
} | ||
|
||
return; | ||
} | ||
|
||
return runJxa(`${prop} = !${prop}()`); | ||
await runJxa(`${property} = !${property}()`); | ||
}; | ||
|
||
exports.isDark = () => runJxa(`return ${prop}()`); | ||
darkMode.isDark = async () => runJxa(`return ${property}()`); | ||
|
||
export default darkMode; |
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,27 @@ | ||
import test from 'ava'; | ||
import m from '.'; | ||
import darkMode from './index.js'; | ||
|
||
let isDarkInitially; | ||
|
||
test.before(async () => { | ||
isDarkInitially = await m.isDark(); | ||
isDarkInitially = await darkMode.isDark(); | ||
}); | ||
|
||
test.after(async () => { | ||
await m.toggle(isDarkInitially); | ||
await darkMode.toggle(isDarkInitially); | ||
}); | ||
|
||
test(async t => { | ||
const dark = await m.isDark(); | ||
await m.toggle(); | ||
t.not(dark, await m.isDark()); | ||
test('main', async t => { | ||
const dark = await darkMode.isDark(); | ||
await darkMode.toggle(); | ||
t.not(dark, await darkMode.isDark()); | ||
|
||
await m.disable(); | ||
t.false(await m.isDark()); | ||
await darkMode.disable(); | ||
t.false(await darkMode.isDark()); | ||
|
||
await m.enable(); | ||
t.true(await m.isDark()); | ||
await darkMode.enable(); | ||
t.true(await darkMode.isDark()); | ||
|
||
await m.toggle(false); | ||
t.false(await m.isDark()); | ||
await darkMode.toggle(false); | ||
t.false(await darkMode.isDark()); | ||
}); |