Repository navigation
Expand file tree
/
Copy pathswiftbar.10s.js
More file actions
executable file
·70 lines (59 loc) · 2.12 KB
/
Copy pathswiftbar.10s.js
File metadata and controls
executable file
·70 lines (59 loc) · 2.12 KB
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
#!/usr/bin/env node
//
// <xbar.title>Studio</xbar.title>
// <xbar.author>Tomas Malbran</xbar.author>
// <xbar.desc>Start and stop the local stack and the apps and servers of each project.</xbar.desc>
//
// Drop SwiftBar's own menu items, so the menu holds only what this prints.
// Preferences go with them: `open swiftbar://preferences` reaches them.
// <swiftbar.hideAbout>true</swiftbar.hideAbout>
// <swiftbar.hideRunInTerminal>true</swiftbar.hideRunInTerminal>
// <swiftbar.hideLastUpdated>true</swiftbar.hideLastUpdated>
// <swiftbar.hideDisablePlugin>true</swiftbar.hideDisablePlugin>
// <swiftbar.hideSwiftBar>true</swiftbar.hideSwiftBar>
//
// With no arguments it prints the menu, every 10s (from the file name). With
// one it runs that action: the menu items call this same file back.
//
// The projects and servers come from config/config.json (or STUDIO_CONFIG);
// config/config.example.json shows its shape.
//
// Keep these:
//
// 1. The shebang is `env node`: SwiftBar's PATH has /usr/local/bin, where
// node is linked (see the README).
// 2. Apache and MariaDB start with `brew services run`, never `start`, so
// nothing comes up at login.
// 3. Links use a bash= action, never href=, so a browser built on Chrome
// can reuse a tab already on the page instead of opening a new one.
import { readState } from "./swiftbar/state.js";
import {
renderTitle, renderServices, renderProjects, renderAppsFooter, renderFooter
} from "./swiftbar/menu.js";
import { runAction } from "./swiftbar/actions.js";
main();
// ------------------------------------------------------------------- entry ---
/**
* Runs the clicked action, or prints the menu when there is no argument.
* @returns {void}
*/
function main() {
const [ , , action, argument ] = process.argv;
if (action) {
runAction(action, argument);
return;
}
renderMenu();
}
/**
* The whole menu, in the order it appears.
* @returns {void}
*/
function renderMenu() {
const state = readState();
renderTitle(state);
renderServices(state);
renderProjects(state);
renderAppsFooter(state);
renderFooter();
}