pi-notify 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +0 -2
- package/extensions/notify/index.ts +55 -28
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -17,6 +17,7 @@
|
|
|
17
17
|
* - Status indicator in footer (♫ sound, ↥ popup, ⚡︎ pushover)
|
|
18
18
|
*
|
|
19
19
|
* Configuration file: ~/.pi/agent/extensions/notify/notify.json
|
|
20
|
+
* - If missing, the extension will create it on first run with safe defaults
|
|
20
21
|
*
|
|
21
22
|
* Volume modes:
|
|
22
23
|
* - "constant": Always plays at volume.max
|
|
@@ -89,39 +90,65 @@ function getConfigPath(): string {
|
|
|
89
90
|
return join(homedir(), ".pi", "agent", "extensions", "notify", "notify.json");
|
|
90
91
|
}
|
|
91
92
|
|
|
93
|
+
const DEFAULT_CONFIG: NotifyConfig = {
|
|
94
|
+
enabled: false,
|
|
95
|
+
minDurationSeconds: 10,
|
|
96
|
+
sound: "silent",
|
|
97
|
+
showPopup: false,
|
|
98
|
+
sounds: [
|
|
99
|
+
{ alias: "silent" },
|
|
100
|
+
{ alias: "random" },
|
|
101
|
+
{ alias: "Funk", path: "/System/Library/Sounds/Funk.aiff" },
|
|
102
|
+
{ alias: "Glass", path: "/System/Library/Sounds/Glass.aiff" },
|
|
103
|
+
{ alias: "Hero", path: "/System/Library/Sounds/Hero.aiff" },
|
|
104
|
+
{ alias: "Submarine", path: "/System/Library/Sounds/Submarine.aiff" },
|
|
105
|
+
],
|
|
106
|
+
volume: {
|
|
107
|
+
mode: "timeScaled",
|
|
108
|
+
max: 1.0,
|
|
109
|
+
min: 0.1,
|
|
110
|
+
},
|
|
111
|
+
pushover: {
|
|
112
|
+
enabled: false,
|
|
113
|
+
userKey: "",
|
|
114
|
+
apiToken: "",
|
|
115
|
+
},
|
|
116
|
+
};
|
|
117
|
+
|
|
92
118
|
function loadConfig(): NotifyConfig {
|
|
93
119
|
const configPath = getConfigPath();
|
|
94
120
|
|
|
95
|
-
if (existsSync(configPath)) {
|
|
121
|
+
if (!existsSync(configPath)) {
|
|
122
|
+
// First-run UX: create a usable default config so pi doesn't error on startup
|
|
96
123
|
try {
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
// Apply defaults for optional sections
|
|
101
|
-
return {
|
|
102
|
-
...parsed,
|
|
103
|
-
volume: {
|
|
104
|
-
mode: "constant",
|
|
105
|
-
max: 1.0,
|
|
106
|
-
min: 0.25,
|
|
107
|
-
...parsed.volume,
|
|
108
|
-
},
|
|
109
|
-
pushover: {
|
|
110
|
-
enabled: false,
|
|
111
|
-
userKey: "",
|
|
112
|
-
apiToken: "",
|
|
113
|
-
...parsed.pushover,
|
|
114
|
-
},
|
|
115
|
-
} as NotifyConfig;
|
|
116
|
-
} catch {
|
|
117
|
-
// Fall through to error
|
|
124
|
+
saveConfig(DEFAULT_CONFIG);
|
|
125
|
+
} catch (err) {
|
|
126
|
+
console.error(`Notify extension: failed to write default config to ${configPath}: ${err}`);
|
|
118
127
|
}
|
|
128
|
+
return DEFAULT_CONFIG;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
let parsed: Partial<NotifyConfig> | undefined;
|
|
132
|
+
try {
|
|
133
|
+
const content = readFileSync(configPath, "utf-8");
|
|
134
|
+
parsed = JSON.parse(content) as Partial<NotifyConfig>;
|
|
135
|
+
} catch (err) {
|
|
136
|
+
console.error(`Notify extension: failed to parse ${configPath}: ${err}`);
|
|
137
|
+
return DEFAULT_CONFIG;
|
|
119
138
|
}
|
|
120
139
|
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
140
|
+
return {
|
|
141
|
+
...DEFAULT_CONFIG,
|
|
142
|
+
...parsed,
|
|
143
|
+
volume: {
|
|
144
|
+
...DEFAULT_CONFIG.volume,
|
|
145
|
+
...(parsed.volume ?? {}),
|
|
146
|
+
},
|
|
147
|
+
pushover: {
|
|
148
|
+
...DEFAULT_CONFIG.pushover,
|
|
149
|
+
...(parsed.pushover ?? {}),
|
|
150
|
+
},
|
|
151
|
+
} as NotifyConfig;
|
|
125
152
|
}
|
|
126
153
|
|
|
127
154
|
function saveConfig(config: NotifyConfig): void {
|
|
@@ -544,7 +571,7 @@ export default function notifyExtension(pi: ExtensionAPI) {
|
|
|
544
571
|
const testIndex = config.volume.mode === "timeScaled" ? 8 : 7;
|
|
545
572
|
if (choice === menuItems[testIndex]) {
|
|
546
573
|
// Test at 4x threshold to demonstrate max volume
|
|
547
|
-
notify("
|
|
574
|
+
notify("𝞹", "⟳", config, config.minDurationSeconds * 4);
|
|
548
575
|
return;
|
|
549
576
|
}
|
|
550
577
|
},
|
|
@@ -568,7 +595,7 @@ export default function notifyExtension(pi: ExtensionAPI) {
|
|
|
568
595
|
agentStartTime = null;
|
|
569
596
|
|
|
570
597
|
if (elapsedSeconds >= config.minDurationSeconds) {
|
|
571
|
-
notify("
|
|
598
|
+
notify("𝞹", "⟳", config, elapsedSeconds);
|
|
572
599
|
}
|
|
573
600
|
});
|
|
574
601
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pi-notify",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"description": "Highly configurable desktop/sound/Pushover notifications when Pi agent turn finishes and took longer than a definable threshold",
|
|
5
5
|
"keywords": ["pi-package", "pi", "pi-coding-agent"],
|
|
6
6
|
"license": "MIT",
|