@mohak34/opencode-notifier 0.1.5 → 0.1.6

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 (2) hide show
  1. package/dist/index.js +38 -6
  2. package/package.json +1 -1
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
  }
@@ -3902,13 +3929,18 @@ async function playOnWindows(soundPath) {
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.6",
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",