-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcli.js
142 lines (125 loc) · 3.97 KB
/
cli.js
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
import { Command } from "commander"
import { Service } from "node-mac"
import path from "path"
import os from "os"
import { fileURLToPath } from 'url'
import { getRandomColor, getRandomColorFromPalette } from "./colorUtils.js"
import { genconfig } from "./configUtils.js"
import { transitionToColor } from "./wallpaperUtils.js"
const __filename = fileURLToPath(import.meta.url)
const __dirname = path.dirname(__filename)
const program = new Command()
const scriptPath = "./schedule.js"
const homeDir = os.homedir()
const userLaunchAgentsDir = path.join(homeDir, "Library/LaunchAgents")
const pinwheelSvc = new Service({
name: "wallslapper-pinwheel",
description: "runs the pinwheel in the background",
script: "./pinwheelService.js",
runAtLoad: true,
logpath: path.join(homeDir, "Library/Logs/wallslapper-pinwheel"),
plist: {
KeepAlive: true,
RunAtLoad: true,
Label: "wallslapper-pinwheel",
ProgramArguments: [process.execPath, path.join(__dirname, "pinwheelService.js")],
StandardOutPath: path.join(homeDir, "Library/Logs/wallslapper-pinwheel/out.log"),
StandardErrorPath: path.join(homeDir, "Library/Logs/wallslapper-pinwheel/err.log"),
},
installPath: userLaunchAgentsDir,
})
const wallslapperSvc = new Service({
name: "wallslapper",
description: "changes wallpaper throughout the day",
script: scriptPath,
runAtLoad: true,
logpath: path.join(homeDir, "Library/Logs/wallslapper"),
plist: {
KeepAlive: true,
RunAtLoad: true,
Label: "wallslapper",
ProgramArguments: [process.execPath, path.join(__dirname, scriptPath)],
StandardOutPath: path.join(homeDir, "Library/Logs/wallslapper/out.log"),
StandardErrorPath: path.join(homeDir, "Library/Logs/wallslapper/err.log"),
},
installPath: userLaunchAgentsDir,
})
// program
// .command("start")
// .description("Start the wallslapper service")
// .action(() => {
// wallslapperSvc.on("install", () => {
// wallslapperSvc.start()
// console.log("wallslapper started")
// })
// pinwheelSvc.install()
// })
const pinwheelCommand = program.command("pinwheel").description("Pinwheel commands")
pinwheelCommand
.command("start <palette> [duration]")
.description("Start the pinwheel in the background")
.action((palette, duration) => {
pinwheelSvc.env = {
PALETTE: palette,
DURATION: duration || "",
}
pinwheelSvc.on("install", () => {
pinwheelSvc.start()
console.log("Pinwheel started in the background")
})
pinwheelSvc.install()
})
pinwheelCommand
.command("stop")
.description("Stop the pinwheel service")
.action(() => {
pinwheelSvc.on("uninstall", () => {
console.log("Pinwheel stopped")
})
pinwheelSvc.stop()
pinwheelSvc.uninstall()
})
// program
// .command("stop")
// .description("Stop the wallslapper service")
// .action(() => {
// pinwheelSvc.on("uninstall", () => {
// console.log("wallslapper stopped")
// })
// pinwheelSvc.stop()
// pinwheelSvc.uninstall()
// })
program
.command("change <hexcode> [duration]")
.description("Change wallpaper to a specific color")
.action(async (hexcode, duration) => {
await transitionToColor(hexcode, duration)
})
program
.command("random [duration]")
.description("Change wallpaper to a random color")
.action(async (duration) => {
const hexcode = getRandomColor()
await transitionToColor(hexcode, duration)
})
program
.command("shuffle <palette> [duration]")
.description("change wallpaper to a random color from the default palette")
.action(async (palette, duration) => {
const hexcode = await getRandomColorFromPalette(palette)
await transitionToColor(hexcode, duration)
})
// program
// .command("pinwheel <palette> [duration]")
// .description("cycle wallpaper through the default palette")
// .option("--forever", "Run the pinwheel forever in a loop")
// .action(async (palette, duration, cmdObj) => {
// runPinwheel(palette, duration, cmdObj.forever)
// })
program
.command("genconfig")
.description("Generate configuration file")
.action(async () => {
await genconfig()
})
program.parse(process.argv)