This repository has been archived by the owner on Apr 2, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
lightswitch
executable file
·108 lines (98 loc) · 3.1 KB
/
lightswitch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#!/usr/bin/env node
const fs = require('fs');
const JSONC = require('jsonc-simple-parser');
// const colors = require('/home/reese/.cache/wal/colors.json');
// Get or set object elements by dot-notation strings
let index = (obj, path, value) => {
if (typeof path == 'string')
return index(obj, path.split('.'), value);
else if (path.length == 1 && value !== undefined)
return obj[path[0]] = value;
else if (path.length == 0)
return obj;
else
return index(obj[path[0]], path.slice(1), value);
}
let updateConfig = ({file, path, themes, mode, name, notation=JSONC, replacer}) => {
fs.readFile(file, 'utf8', (err, data) => {
if (err) console.error(`${name} error: ${err}`);
let conf = notation.parse(data);
index(conf, path, themes[mode]);
fs.writeFile(file, notation.stringify(conf, replacer, '\t'), err => {
if (!err){
console.log(`modified ${name}.`);
} else {
console.error(`${name} error: ${err}`);
}
});
});
}
let toggle = {
// Requirements:
// - Have Powercord installed (https://powercord.dev)
// - Have my Lightswitch plugin installed (https://github.com/katacarbix/discord-stuff#lightswitch)
// - Start Discord with the command line argument '--remote-debugging-port=1666'.
discord: async mode => {
const CDP = require('chrome-remote-interface');
CDP({host: '127.0.0.1', port: 1666}, async (client) => {
await client.Runtime.evaluate({expression: `Lightswitch.set('${mode}')`});
client.close();
console.log('changed discord appearance');
}).on('error', (err) => {
console.error(`discord console error: ${err}`);
process.exit(1);
});
},
// Update micro's configuration
// micro: async mode => {
// let themes = {
// 'dark': 'monokai',
// 'light': 'simple'
// }
// let file = '/home/reese/.config/micro/settings.json';
// updateConfig({file, path:'colorscheme', name:'micro settings', themes, mode});
// },
// Update Sublime Text's configuration
sublime: async mode => {
let themes = {
'dark': 'Packages/User/Letty-tmTheme/Letty Aurora.tmTheme',
'light': 'Packages/User/Letty-tmTheme/Letty Snow.tmTheme'
}
let prefs = '/home/reese/.config/sublime-text-3/Packages/User/Preferences.sublime-settings';
updateConfig({file:prefs, path:'color_scheme', name:'sublime preferences', themes, mode});
}
}
let main = (mode, apps) => {
apps = apps || Object.keys(toggle);
for (var a of apps){
if (toggle.hasOwnProperty(a)) toggle[a](mode);
else console.warn(`unknown app: ${a}`)
}
}
if (require.main === module){
(() => {
let argv = require('yargs/yargs')(process.argv.slice(2))
.usage('$0 [args]')
.options({
'light': {
alias: 'l',
type: 'boolean',
default: false,
description: 'Switches to light mode if set, otherwise dark.'
},
'toggles': {
alias: 't',
type: 'array',
default: Object.keys(toggle),
requiresArg: true,
description: `(optional) Specify which programs to toggle.\n(available options are: ${Object.keys(toggle).join(', ')})`
}
})
.hide('version')
.help()
.argv;
let mode = argv.light ? 'light' : 'dark';
main(mode, argv.toggles);
})()
}
module.exports = main;