@mywallpaper/addon-sdk 2.11.1 → 2.13.0

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 CHANGED
@@ -48,7 +48,7 @@ my-addon/
48
48
  {
49
49
  "name": "My Awesome Addon",
50
50
  "version": "1.0.0",
51
- "sdkVersion": "2.7.0",
51
+ "sdkVersion": "2.13.0",
52
52
  "description": "A cool widget for your desktop",
53
53
  "author": "Your Name",
54
54
  "capabilities": {
@@ -226,6 +226,34 @@ api.onSettingsChange((settings, changedKeys) => {
226
226
  })
227
227
  ```
228
228
 
229
+ ##### `onButtonClick(settingKey, callback)` / `offButtonClick(settingKey)`
230
+
231
+ Handle button setting clicks.
232
+
233
+ ```typescript
234
+ // Register a handler for a button setting
235
+ api.onButtonClick('resetButton', () => {
236
+ resetToDefaults()
237
+ console.log('Reset clicked!')
238
+ })
239
+
240
+ // Remove the handler when no longer needed
241
+ api.offButtonClick('resetButton')
242
+ ```
243
+
244
+ With manifest:
245
+
246
+ ```json
247
+ {
248
+ "settings": {
249
+ "resetButton": {
250
+ "type": "button",
251
+ "buttonLabel": "Reset to Defaults"
252
+ }
253
+ }
254
+ }
255
+ ```
256
+
229
257
  ##### `onEvent(event, callback)` / `offEvent(event, callback)`
230
258
 
231
259
  Subscribe/unsubscribe to system events.
package/dist/index.d.mts CHANGED
@@ -476,6 +476,30 @@ interface MyWallpaperAPI {
476
476
  * @param callback - Function called with new settings and changed keys
477
477
  */
478
478
  onSettingsChange(callback: SettingsCallback): void;
479
+ /**
480
+ * Register a callback for when a button setting is clicked.
481
+ * Buttons are defined in manifest.json with `type: "button"`.
482
+ *
483
+ * @param settingKey - The button's setting key from manifest
484
+ * @param callback - Function called when the button is clicked
485
+ *
486
+ * @example
487
+ * ```typescript
488
+ * // manifest.json:
489
+ * // "refreshButton": { "type": "button", "label": "Refresh", "buttonLabel": "Refresh Now" }
490
+ *
491
+ * api.onButtonClick('refreshButton', () => {
492
+ * console.log('Refresh button clicked!')
493
+ * fetchLatestData()
494
+ * })
495
+ * ```
496
+ */
497
+ onButtonClick(settingKey: string, callback: () => void): void;
498
+ /**
499
+ * Unregister a button click callback.
500
+ * @param settingKey - The button's setting key
501
+ */
502
+ offButtonClick(settingKey: string): void;
479
503
  /**
480
504
  * Subscribe to a system event.
481
505
  * @param event - Event type to subscribe to
@@ -931,6 +955,37 @@ interface SettingOption {
931
955
  * ```
932
956
  */
933
957
  interface SettingsAPI {
958
+ /**
959
+ * Update a single setting value from the addon.
960
+ * This syncs the value back to the host UI and persists it.
961
+ *
962
+ * @param settingKey - The setting key to update
963
+ * @param value - The new value
964
+ *
965
+ * @example
966
+ * ```typescript
967
+ * // Update a color setting after randomization
968
+ * api.settings.setValue('primaryColor', '#ff0000')
969
+ * ```
970
+ */
971
+ setValue(settingKey: string, value: unknown): void;
972
+ /**
973
+ * Update multiple setting values at once.
974
+ * This syncs all values back to the host UI and persists them.
975
+ *
976
+ * @param values - Object with settingKey -> value pairs
977
+ *
978
+ * @example
979
+ * ```typescript
980
+ * // Update multiple colors after randomization
981
+ * api.settings.setValues({
982
+ * primaryColor: '#ff0000',
983
+ * secondaryColor: '#00ff00',
984
+ * backgroundColor: '#0000ff'
985
+ * })
986
+ * ```
987
+ */
988
+ setValues(values: Record<string, unknown>): void;
934
989
  /**
935
990
  * Update the options for a select-type setting.
936
991
  * The new options replace existing ones from the manifest.
package/dist/index.d.ts CHANGED
@@ -476,6 +476,30 @@ interface MyWallpaperAPI {
476
476
  * @param callback - Function called with new settings and changed keys
477
477
  */
478
478
  onSettingsChange(callback: SettingsCallback): void;
479
+ /**
480
+ * Register a callback for when a button setting is clicked.
481
+ * Buttons are defined in manifest.json with `type: "button"`.
482
+ *
483
+ * @param settingKey - The button's setting key from manifest
484
+ * @param callback - Function called when the button is clicked
485
+ *
486
+ * @example
487
+ * ```typescript
488
+ * // manifest.json:
489
+ * // "refreshButton": { "type": "button", "label": "Refresh", "buttonLabel": "Refresh Now" }
490
+ *
491
+ * api.onButtonClick('refreshButton', () => {
492
+ * console.log('Refresh button clicked!')
493
+ * fetchLatestData()
494
+ * })
495
+ * ```
496
+ */
497
+ onButtonClick(settingKey: string, callback: () => void): void;
498
+ /**
499
+ * Unregister a button click callback.
500
+ * @param settingKey - The button's setting key
501
+ */
502
+ offButtonClick(settingKey: string): void;
479
503
  /**
480
504
  * Subscribe to a system event.
481
505
  * @param event - Event type to subscribe to
@@ -931,6 +955,37 @@ interface SettingOption {
931
955
  * ```
932
956
  */
933
957
  interface SettingsAPI {
958
+ /**
959
+ * Update a single setting value from the addon.
960
+ * This syncs the value back to the host UI and persists it.
961
+ *
962
+ * @param settingKey - The setting key to update
963
+ * @param value - The new value
964
+ *
965
+ * @example
966
+ * ```typescript
967
+ * // Update a color setting after randomization
968
+ * api.settings.setValue('primaryColor', '#ff0000')
969
+ * ```
970
+ */
971
+ setValue(settingKey: string, value: unknown): void;
972
+ /**
973
+ * Update multiple setting values at once.
974
+ * This syncs all values back to the host UI and persists them.
975
+ *
976
+ * @param values - Object with settingKey -> value pairs
977
+ *
978
+ * @example
979
+ * ```typescript
980
+ * // Update multiple colors after randomization
981
+ * api.settings.setValues({
982
+ * primaryColor: '#ff0000',
983
+ * secondaryColor: '#00ff00',
984
+ * backgroundColor: '#0000ff'
985
+ * })
986
+ * ```
987
+ */
988
+ setValues(values: Record<string, unknown>): void;
934
989
  /**
935
990
  * Update the options for a select-type setting.
936
991
  * The new options replace existing ones from the manifest.
@@ -461,6 +461,30 @@ interface MyWallpaperAPI {
461
461
  * @param callback - Function called with new settings and changed keys
462
462
  */
463
463
  onSettingsChange(callback: SettingsCallback): void;
464
+ /**
465
+ * Register a callback for when a button setting is clicked.
466
+ * Buttons are defined in manifest.json with `type: "button"`.
467
+ *
468
+ * @param settingKey - The button's setting key from manifest
469
+ * @param callback - Function called when the button is clicked
470
+ *
471
+ * @example
472
+ * ```typescript
473
+ * // manifest.json:
474
+ * // "refreshButton": { "type": "button", "label": "Refresh", "buttonLabel": "Refresh Now" }
475
+ *
476
+ * api.onButtonClick('refreshButton', () => {
477
+ * console.log('Refresh button clicked!')
478
+ * fetchLatestData()
479
+ * })
480
+ * ```
481
+ */
482
+ onButtonClick(settingKey: string, callback: () => void): void;
483
+ /**
484
+ * Unregister a button click callback.
485
+ * @param settingKey - The button's setting key
486
+ */
487
+ offButtonClick(settingKey: string): void;
464
488
  /**
465
489
  * Subscribe to a system event.
466
490
  * @param event - Event type to subscribe to
@@ -912,6 +936,37 @@ interface SettingOption {
912
936
  * ```
913
937
  */
914
938
  interface SettingsAPI {
939
+ /**
940
+ * Update a single setting value from the addon.
941
+ * This syncs the value back to the host UI and persists it.
942
+ *
943
+ * @param settingKey - The setting key to update
944
+ * @param value - The new value
945
+ *
946
+ * @example
947
+ * ```typescript
948
+ * // Update a color setting after randomization
949
+ * api.settings.setValue('primaryColor', '#ff0000')
950
+ * ```
951
+ */
952
+ setValue(settingKey: string, value: unknown): void;
953
+ /**
954
+ * Update multiple setting values at once.
955
+ * This syncs all values back to the host UI and persists them.
956
+ *
957
+ * @param values - Object with settingKey -> value pairs
958
+ *
959
+ * @example
960
+ * ```typescript
961
+ * // Update multiple colors after randomization
962
+ * api.settings.setValues({
963
+ * primaryColor: '#ff0000',
964
+ * secondaryColor: '#00ff00',
965
+ * backgroundColor: '#0000ff'
966
+ * })
967
+ * ```
968
+ */
969
+ setValues(values: Record<string, unknown>): void;
915
970
  /**
916
971
  * Update the options for a select-type setting.
917
972
  * The new options replace existing ones from the manifest.
@@ -461,6 +461,30 @@ interface MyWallpaperAPI {
461
461
  * @param callback - Function called with new settings and changed keys
462
462
  */
463
463
  onSettingsChange(callback: SettingsCallback): void;
464
+ /**
465
+ * Register a callback for when a button setting is clicked.
466
+ * Buttons are defined in manifest.json with `type: "button"`.
467
+ *
468
+ * @param settingKey - The button's setting key from manifest
469
+ * @param callback - Function called when the button is clicked
470
+ *
471
+ * @example
472
+ * ```typescript
473
+ * // manifest.json:
474
+ * // "refreshButton": { "type": "button", "label": "Refresh", "buttonLabel": "Refresh Now" }
475
+ *
476
+ * api.onButtonClick('refreshButton', () => {
477
+ * console.log('Refresh button clicked!')
478
+ * fetchLatestData()
479
+ * })
480
+ * ```
481
+ */
482
+ onButtonClick(settingKey: string, callback: () => void): void;
483
+ /**
484
+ * Unregister a button click callback.
485
+ * @param settingKey - The button's setting key
486
+ */
487
+ offButtonClick(settingKey: string): void;
464
488
  /**
465
489
  * Subscribe to a system event.
466
490
  * @param event - Event type to subscribe to
@@ -912,6 +936,37 @@ interface SettingOption {
912
936
  * ```
913
937
  */
914
938
  interface SettingsAPI {
939
+ /**
940
+ * Update a single setting value from the addon.
941
+ * This syncs the value back to the host UI and persists it.
942
+ *
943
+ * @param settingKey - The setting key to update
944
+ * @param value - The new value
945
+ *
946
+ * @example
947
+ * ```typescript
948
+ * // Update a color setting after randomization
949
+ * api.settings.setValue('primaryColor', '#ff0000')
950
+ * ```
951
+ */
952
+ setValue(settingKey: string, value: unknown): void;
953
+ /**
954
+ * Update multiple setting values at once.
955
+ * This syncs all values back to the host UI and persists them.
956
+ *
957
+ * @param values - Object with settingKey -> value pairs
958
+ *
959
+ * @example
960
+ * ```typescript
961
+ * // Update multiple colors after randomization
962
+ * api.settings.setValues({
963
+ * primaryColor: '#ff0000',
964
+ * secondaryColor: '#00ff00',
965
+ * backgroundColor: '#0000ff'
966
+ * })
967
+ * ```
968
+ */
969
+ setValues(values: Record<string, unknown>): void;
915
970
  /**
916
971
  * Update the options for a select-type setting.
917
972
  * The new options replace existing ones from the manifest.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mywallpaper/addon-sdk",
3
- "version": "2.11.1",
3
+ "version": "2.13.0",
4
4
  "description": "SDK for building MyWallpaper addons - TypeScript types, manifest validation, and utilities",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
@@ -32,6 +32,7 @@
32
32
  var pendingNetworkAccess = new Map() // For on-demand domain permission requests
33
33
  var grantedBlobUrls = new Map() // settingKey -> blobUrl
34
34
  var dynamicSettingsOptions = new Map() // settingKey -> options[] (dynamic options from widget)
35
+ var buttonCallbacks = new Map() // settingKey -> callback function for button clicks
35
36
 
36
37
  // Audio state (synced from host)
37
38
  var audioState = {
@@ -250,6 +251,15 @@
250
251
  try { cb(audioState) } catch (err) { console.error('[MyWallpaper] Audio callback error:', err) }
251
252
  })
252
253
  break
254
+
255
+ case 'BUTTON_CLICK':
256
+ // Handle button click from settings panel
257
+ var btnKey = d.payload.settingKey
258
+ var btnCb = buttonCallbacks.get(btnKey)
259
+ if (btnCb) {
260
+ try { btnCb() } catch (err) { console.error('[MyWallpaper] Button callback error:', err) }
261
+ }
262
+ break
253
263
  }
254
264
  }
255
265
 
@@ -416,10 +426,29 @@
416
426
  window.MyWallpaper = {
417
427
  get config() { return config },
418
428
  layerId: layerId,
419
- version: '2.11.0',
429
+ version: '2.13.0',
420
430
 
421
431
  onSettingsChange: function (fn) { if (typeof fn === 'function') settingsCallbacks.push(fn) },
422
432
 
433
+ /**
434
+ * Register a callback for a button click in settings panel
435
+ * @param {string} settingKey - The button's setting key from manifest
436
+ * @param {function} callback - Function called when button is clicked
437
+ */
438
+ onButtonClick: function (settingKey, callback) {
439
+ if (typeof settingKey === 'string' && typeof callback === 'function') {
440
+ buttonCallbacks.set(settingKey, callback)
441
+ }
442
+ },
443
+
444
+ /**
445
+ * Unregister a button click callback
446
+ * @param {string} settingKey - The button's setting key
447
+ */
448
+ offButtonClick: function (settingKey) {
449
+ buttonCallbacks.delete(settingKey)
450
+ },
451
+
423
452
  onEvent: function (event, fn) {
424
453
  if (typeof fn !== 'function') return
425
454
  if (!eventCallbacks.has(event)) eventCallbacks.set(event, new Set())
@@ -441,7 +470,7 @@
441
470
  isReady = true
442
471
  opts = opts || {}
443
472
  send('ADDON_READY', {
444
- version: '2.11.0',
473
+ version: '2.13.0',
445
474
  capabilities: opts.capabilities || [],
446
475
  subscribedEvents: opts.subscribedEvents || []
447
476
  })
@@ -732,6 +761,42 @@
732
761
  * })))
733
762
  */
734
763
  settings: {
764
+ /**
765
+ * Update a setting value from the addon
766
+ * This syncs the value back to the host UI and persists it
767
+ * @param {string} settingKey - The setting key to update
768
+ * @param {*} value - The new value
769
+ */
770
+ setValue: function (settingKey, value) {
771
+ if (!settingKey || typeof settingKey !== 'string') {
772
+ console.error('[MyWallpaper] settings.setValue: settingKey is required')
773
+ return
774
+ }
775
+ // Update local config immediately
776
+ config[settingKey] = value
777
+ // Send to host to update UI and persist
778
+ send('SETTINGS_VALUE_UPDATE', { settingKey: settingKey, value: value })
779
+ },
780
+
781
+ /**
782
+ * Update multiple setting values at once
783
+ * @param {Record<string, *>} values - Object with settingKey -> value pairs
784
+ */
785
+ setValues: function (values) {
786
+ if (!values || typeof values !== 'object') {
787
+ console.error('[MyWallpaper] settings.setValues: values object is required')
788
+ return
789
+ }
790
+ // Update local config immediately
791
+ for (var key in values) {
792
+ if (Object.prototype.hasOwnProperty.call(values, key)) {
793
+ config[key] = values[key]
794
+ }
795
+ }
796
+ // Send to host to update UI and persist
797
+ send('SETTINGS_VALUES_UPDATE', { values: values })
798
+ },
799
+
735
800
  /**
736
801
  * Update the options for a select-type setting
737
802
  * @param {string} settingKey - The setting key to update
@@ -790,5 +855,5 @@
790
855
  }
791
856
  }
792
857
 
793
- console.warn('[MyWallpaper] SDK v2.11.0 ready:', layerId)
858
+ console.warn('[MyWallpaper] SDK v2.13.0 ready:', layerId)
794
859
  })()