@mohak34/opencode-notifier 0.1.5 → 0.1.7

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.
Files changed (3) hide show
  1. package/README.md +12 -1
  2. package/dist/index.js +39 -7
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -8,12 +8,23 @@ Add the plugin to your `opencode.json` or `opencode.jsonc`:
8
8
 
9
9
  ```json
10
10
  {
11
- "plugin": ["@mohak34/opencode-notifier"]
11
+ "plugin": ["@mohak34/opencode-notifier@latest"]
12
12
  }
13
13
  ```
14
14
 
15
15
  Restart OpenCode. The plugin will be automatically installed and loaded.
16
16
 
17
+ ## Updating
18
+
19
+ OpenCode caches plugins in `~/.cache/opencode`. To update to the latest version:
20
+
21
+ 1. **Clear the plugin from cache:**
22
+ ```rm -rf ~/.cache/opencode/node_modules/@mohak34/opencode-notifier```
23
+ 2. Restart OpenCode - it will download the latest version.
24
+
25
+ To check your installed version:
26
+ ```cat ~/.cache/opencode/node_modules/@mohak34/opencode-notifier/package.json | grep version```
27
+
17
28
  ## Platform Notes
18
29
 
19
30
  The plugin works out of the box on all platforms. For best results:
package/dist/index.js CHANGED
@@ -3825,28 +3825,55 @@ function getSoundPath(config, event) {
3825
3825
 
3826
3826
  // src/notify.ts
3827
3827
  var import_node_notifier = __toESM(require_node_notifier(), 1);
3828
+ import os from "os";
3828
3829
  var NOTIFICATION_TITLE = "OpenCode";
3830
+ var DEBOUNCE_MS = 1000;
3831
+ var platform = os.type();
3832
+ var platformNotifier;
3833
+ if (platform === "Linux" || platform.match(/BSD$/)) {
3834
+ const { NotifySend } = import_node_notifier.default;
3835
+ platformNotifier = new NotifySend({ withFallback: false });
3836
+ } else if (platform === "Darwin") {
3837
+ const { NotificationCenter } = import_node_notifier.default;
3838
+ platformNotifier = new NotificationCenter({ withFallback: false });
3839
+ } else if (platform === "Windows_NT") {
3840
+ const { WindowsToaster } = import_node_notifier.default;
3841
+ platformNotifier = new WindowsToaster({ withFallback: false });
3842
+ } else {
3843
+ platformNotifier = import_node_notifier.default;
3844
+ }
3845
+ var lastNotificationTime = {};
3829
3846
  async function sendNotification(message, timeout) {
3847
+ const now = Date.now();
3848
+ if (lastNotificationTime[message] && now - lastNotificationTime[message] < DEBOUNCE_MS) {
3849
+ return;
3850
+ }
3851
+ lastNotificationTime[message] = now;
3830
3852
  return new Promise((resolve) => {
3831
- import_node_notifier.default.notify({
3853
+ const notificationOptions = {
3832
3854
  title: NOTIFICATION_TITLE,
3833
3855
  message,
3834
- sound: false,
3835
3856
  timeout,
3836
3857
  icon: undefined
3837
- }, () => {
3858
+ };
3859
+ if (platform === "Darwin") {
3860
+ notificationOptions.sound = false;
3861
+ }
3862
+ platformNotifier.notify(notificationOptions, () => {
3838
3863
  resolve();
3839
3864
  });
3840
3865
  });
3841
3866
  }
3842
3867
 
3843
3868
  // src/sound.ts
3844
- import { platform } from "os";
3869
+ import { platform as platform2 } from "os";
3845
3870
  import { join as join2, dirname } from "path";
3846
3871
  import { fileURLToPath } from "url";
3847
3872
  import { existsSync as existsSync2 } from "fs";
3848
3873
  import { spawn } from "child_process";
3849
3874
  var __dirname2 = dirname(fileURLToPath(import.meta.url));
3875
+ var DEBOUNCE_MS2 = 1000;
3876
+ var lastSoundTime = {};
3850
3877
  function getBundledSoundPath(event) {
3851
3878
  return join2(__dirname2, "..", "sounds", `${event}.wav`);
3852
3879
  }
@@ -3898,17 +3925,22 @@ async function playOnMac(soundPath) {
3898
3925
  await runCommand("afplay", [soundPath]);
3899
3926
  }
3900
3927
  async function playOnWindows(soundPath) {
3901
- const script = `(New-Object Media.SoundPlayer $args[0]).PlaySync()`;
3928
+ const script = `& { (New-Object Media.SoundPlayer $args[0]).PlaySync() }`;
3902
3929
  await runCommand("powershell", ["-c", script, soundPath]);
3903
3930
  }
3904
3931
  async function playSound(event, customPath) {
3932
+ const now = Date.now();
3933
+ if (lastSoundTime[event] && now - lastSoundTime[event] < DEBOUNCE_MS2) {
3934
+ return;
3935
+ }
3936
+ lastSoundTime[event] = now;
3905
3937
  const soundPath = getSoundFilePath(event, customPath);
3906
3938
  if (!soundPath) {
3907
3939
  return;
3908
3940
  }
3909
- const os = platform();
3941
+ const os2 = platform2();
3910
3942
  try {
3911
- switch (os) {
3943
+ switch (os2) {
3912
3944
  case "darwin":
3913
3945
  await playOnMac(soundPath);
3914
3946
  break;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mohak34/opencode-notifier",
3
- "version": "0.1.5",
3
+ "version": "0.1.7",
4
4
  "description": "OpenCode plugin that sends system notifications and plays sounds when permission is needed, generation completes, or errors occur",
5
5
  "author": "mohak34",
6
6
  "license": "MIT",