@sdeck/plugin-system 0.2.0 → 0.4.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sdeck/plugin-system",
3
- "version": "0.2.0",
3
+ "version": "0.4.0",
4
4
  "description": "Built-in sdeck actions that reach the computer: apps and commands, media keys and shortcuts, power, screenshots and monitoring.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -32,8 +32,8 @@
32
32
  "test": "bun test"
33
33
  },
34
34
  "peerDependencies": {
35
- "@sdeck/plugin": "^0.1.0",
36
- "@sdeck/schema": "^0.1.0",
35
+ "@sdeck/plugin": "^0.3.0",
36
+ "@sdeck/schema": "^0.3.0",
37
37
  "react": ">=19.3"
38
38
  },
39
39
  "peerDependenciesMeta": {
@@ -48,8 +48,8 @@
48
48
  }
49
49
  },
50
50
  "devDependencies": {
51
- "@sdeck/plugin": "0.1.0",
52
- "@sdeck/schema": "0.1.0"
51
+ "@sdeck/plugin": "0.3.0",
52
+ "@sdeck/schema": "0.3.0"
53
53
  },
54
54
  "repository": {
55
55
  "type": "git",
package/src/index.tsx CHANGED
@@ -102,6 +102,7 @@ const buttonLook = (icon: string, caption: string, image: string, background: st
102
102
 
103
103
  const open = defineAction({
104
104
  id: "open",
105
+ permissions: ["process"],
105
106
  name: "Open",
106
107
  description: "Opens a website, file, folder or app.",
107
108
  category: "System",
@@ -112,9 +113,14 @@ const open = defineAction({
112
113
  label: "URL or path",
113
114
  placeholder: "https://example.com or C:\\Tools\\app.exe",
114
115
  },
115
- text: { type: "text", label: "Text", placeholder: "Optional, under the icon" },
116
- image: { type: "image", label: "Image" },
117
- background: { type: "color", label: "Background", default: "#0969da" },
116
+ text: {
117
+ type: "text",
118
+ label: "Text",
119
+ placeholder: "Optional, under the icon",
120
+ appearance: true,
121
+ },
122
+ image: { type: "image", label: "Image", appearance: true },
123
+ background: { type: "color", label: "Background", default: "#0969da", appearance: true },
118
124
  },
119
125
  run: ({ settings, plugin }) => {
120
126
  if (!settings.target) throw new Error("nothing to open");
@@ -127,6 +133,7 @@ const open = defineAction({
127
133
 
128
134
  const command = defineAction({
129
135
  id: "command",
136
+ permissions: ["shell"],
130
137
  name: "Run command",
131
138
  description: "Runs a shell command. Fails when it exits with an error; its output is the result.",
132
139
  category: "System",
@@ -140,9 +147,14 @@ const command = defineAction({
140
147
  description: "Run to revert it (from the history, or a toggle's second press).",
141
148
  multiline: true,
142
149
  },
143
- text: { type: "text", label: "Text", placeholder: "Optional, under the icon" },
144
- image: { type: "image", label: "Image" },
145
- background: { type: "color", label: "Background", default: "#24292f" },
150
+ text: {
151
+ type: "text",
152
+ label: "Text",
153
+ placeholder: "Optional, under the icon",
154
+ appearance: true,
155
+ },
156
+ image: { type: "image", label: "Image", appearance: true },
157
+ background: { type: "color", label: "Background", default: "#24292f", appearance: true },
146
158
  },
147
159
  run: async ({ settings, plugin, signal }) => {
148
160
  if (!settings.command) throw new Error("no command");
@@ -230,6 +242,7 @@ const METRICS = {
230
242
 
231
243
  const stats = defineAction({
232
244
  id: "stats",
245
+ permissions: [],
233
246
  name: "System stats",
234
247
  description:
235
248
  "Live CPU, memory, disk, network, GPU, ping and FPS (also usable anywhere as {{system.cpu}}).",
@@ -258,7 +271,7 @@ const stats = defineAction({
258
271
  color: { type: "color", label: "Colour", default: "#58a6ff" },
259
272
  background: { type: "color", label: "Background", default: "#0d1117" },
260
273
  },
261
- run: () => undefined,
274
+ display: true,
262
275
  look: (s): Look => {
263
276
  const bar = (id: string, value: string): Layer => ({
264
277
  id,
@@ -320,6 +333,7 @@ const MEDIA = {
320
333
 
321
334
  const media = defineAction({
322
335
  id: "media",
336
+ permissions: ["input"],
323
337
  name: "Media and volume",
324
338
  description: "Presses a media or volume key, as a keyboard would.",
325
339
  category: "Controls",
@@ -344,7 +358,7 @@ const media = defineAction({
344
358
  max: 50,
345
359
  visibleIf: { key: ["volume-up", "volume-down"] },
346
360
  },
347
- background: { type: "color", label: "Background", default: "#1f2937" },
361
+ background: { type: "color", label: "Background", default: "#1f2937", appearance: true },
348
362
  },
349
363
  run: async ({ settings }) => {
350
364
  const controls = await systemControls();
@@ -374,6 +388,7 @@ const media = defineAction({
374
388
 
375
389
  const hotkey = defineAction({
376
390
  id: "hotkey",
391
+ permissions: ["input"],
377
392
  name: "Press a shortcut",
378
393
  description: "Sends a keyboard shortcut to the focused app.",
379
394
  category: "Controls",
@@ -381,8 +396,13 @@ const hotkey = defineAction({
381
396
  slots: ["key", "sensor"],
382
397
  settings: {
383
398
  keys: { type: "text", label: "Shortcut", placeholder: "ctrl+shift+m" },
384
- text: { type: "text", label: "Text", placeholder: "Defaults to the shortcut" },
385
- background: { type: "color", label: "Background", default: "#374151" },
399
+ text: {
400
+ type: "text",
401
+ label: "Text",
402
+ placeholder: "Defaults to the shortcut",
403
+ appearance: true,
404
+ },
405
+ background: { type: "color", label: "Background", default: "#374151", appearance: true },
386
406
  },
387
407
  run: async ({ settings }) => {
388
408
  const accelerator = parseAccelerator(settings.keys);
@@ -395,6 +415,7 @@ const hotkey = defineAction({
395
415
 
396
416
  const type = defineAction({
397
417
  id: "type",
418
+ permissions: ["input"],
398
419
  name: "Type text",
399
420
  description: "Types text into the focused app. The text can use {{templates}}.",
400
421
  category: "Controls",
@@ -402,8 +423,13 @@ const type = defineAction({
402
423
  slots: ["key", "sensor"],
403
424
  settings: {
404
425
  content: { type: "text", label: "Text to type", multiline: true },
405
- text: { type: "text", label: "Key text", placeholder: "Optional, under the icon" },
406
- background: { type: "color", label: "Background", default: "#374151" },
426
+ text: {
427
+ type: "text",
428
+ label: "Key text",
429
+ placeholder: "Optional, under the icon",
430
+ appearance: true,
431
+ },
432
+ background: { type: "color", label: "Background", default: "#374151", appearance: true },
407
433
  },
408
434
  run: async ({ settings }) => {
409
435
  if (!settings.content) throw new Error("nothing to type");
@@ -416,13 +442,19 @@ const type = defineAction({
416
442
 
417
443
  const lock = defineAction({
418
444
  id: "lock",
445
+ permissions: ["process"],
419
446
  name: "Lock the screen",
420
447
  category: "Controls",
421
448
  icon: "lock",
422
449
  slots: ["key", "sensor"],
423
450
  settings: {
424
- text: { type: "text", label: "Text", placeholder: "Optional, under the icon" },
425
- background: { type: "color", label: "Background", default: "#7c2d12" },
451
+ text: {
452
+ type: "text",
453
+ label: "Text",
454
+ placeholder: "Optional, under the icon",
455
+ appearance: true,
456
+ },
457
+ background: { type: "color", label: "Background", default: "#7c2d12", appearance: true },
426
458
  },
427
459
  run: async () => {
428
460
  await (await systemControls()).lock();
@@ -433,14 +465,20 @@ const lock = defineAction({
433
465
 
434
466
  const sleep = defineAction({
435
467
  id: "sleep",
468
+ permissions: ["process"],
436
469
  name: "Sleep",
437
470
  description: "Puts the computer to sleep.",
438
471
  category: "Controls",
439
472
  icon: "moon",
440
473
  slots: ["key", "sensor"],
441
474
  settings: {
442
- text: { type: "text", label: "Text", placeholder: "Optional, under the icon" },
443
- background: { type: "color", label: "Background", default: "#1e1b4b" },
475
+ text: {
476
+ type: "text",
477
+ label: "Text",
478
+ placeholder: "Optional, under the icon",
479
+ appearance: true,
480
+ },
481
+ background: { type: "color", label: "Background", default: "#1e1b4b", appearance: true },
444
482
  },
445
483
  run: async () => {
446
484
  await (await systemControls()).sleep();
@@ -459,6 +497,7 @@ export function screenshotName(at: Date): string {
459
497
 
460
498
  const screenshot = defineAction({
461
499
  id: "screenshot",
500
+ permissions: ["process", "filesystem"],
462
501
  name: "Screenshot",
463
502
  description: "Saves the screen to a file (the result), or opens the region picker.",
464
503
  category: "Controls",
@@ -480,8 +519,13 @@ const screenshot = defineAction({
480
519
  placeholder: "Pictures/sdeck",
481
520
  visibleIf: { mode: "file" },
482
521
  },
483
- text: { type: "text", label: "Text", placeholder: "Optional, under the icon" },
484
- background: { type: "color", label: "Background", default: "#065f46" },
522
+ text: {
523
+ type: "text",
524
+ label: "Text",
525
+ placeholder: "Optional, under the icon",
526
+ appearance: true,
527
+ },
528
+ background: { type: "color", label: "Background", default: "#065f46", appearance: true },
485
529
  },
486
530
  run: async ({ settings }) => {
487
531
  const controls = await systemControls();
@@ -504,13 +548,14 @@ const screenshot = defineAction({
504
548
 
505
549
  const pingAction = defineAction({
506
550
  id: "ping",
551
+ permissions: ["network"],
507
552
  name: "Ping",
508
553
  description: "Pings a host; the result is the round trip in ms. Fails when it does not answer.",
509
554
  category: "Monitoring",
510
555
  icon: "radio",
511
556
  settings: {
512
557
  host: { type: "text", label: "Host", default: "1.1.1.1" },
513
- background: { type: "color", label: "Background", default: "#0d1117" },
558
+ background: { type: "color", label: "Background", default: "#0d1117", appearance: true },
514
559
  },
515
560
  run: async ({ settings, signal }) => {
516
561
  const ms = await ping(settings.host, signal);
@@ -643,6 +688,7 @@ const netState = (id: string, name: string, pick: (c: Counters) => number): Stat
643
688
  name,
644
689
  type: "number",
645
690
  unit: "B/s",
691
+ permissions: ["process"],
646
692
  start: (set, context) => {
647
693
  networkError = (error) => markUnavailable(context, "network speed", error);
648
694
  return throughputSource.listen((rate) => set(pick(rate)));
@@ -660,6 +706,7 @@ const gpuState = (
660
706
  name,
661
707
  type,
662
708
  ...(unit && { unit }),
709
+ permissions: ["process"],
663
710
  poll: {
664
711
  everyMs: 2000,
665
712
  read: async (context) => {
@@ -674,6 +721,7 @@ const monitoring: StateDef[] = [
674
721
  let sample: (() => number[]) | undefined;
675
722
  return {
676
723
  id: "cpuCores",
724
+ permissions: [],
677
725
  name: "CPU use per core",
678
726
  type: "json" as const,
679
727
  description: "system.cpuCores[0] is the first core.",
@@ -688,6 +736,7 @@ const monitoring: StateDef[] = [
688
736
  })(),
689
737
  {
690
738
  id: "disks",
739
+ permissions: ["filesystem"],
691
740
  name: "Disks",
692
741
  type: "json",
693
742
  description: "system.disks.c.percent, .free, .total (choose them in the plugin's settings).",
@@ -695,6 +744,7 @@ const monitoring: StateDef[] = [
695
744
  },
696
745
  {
697
746
  id: "disk",
747
+ permissions: ["filesystem"],
698
748
  name: "Disk space used",
699
749
  type: "number",
700
750
  unit: "%",
@@ -708,6 +758,7 @@ const monitoring: StateDef[] = [
708
758
  netState("netUp", "Upload speed", (c) => c.sent),
709
759
  {
710
760
  id: "ping",
761
+ permissions: ["network"],
711
762
  name: "Ping",
712
763
  type: "number",
713
764
  unit: "ms",
@@ -723,6 +774,7 @@ const monitoring: StateDef[] = [
723
774
  gpuState("gpuName", "GPU name", "string", (g) => g.name),
724
775
  {
725
776
  id: "cpuTemp",
777
+ permissions: ["process"],
726
778
  name: "CPU temperature",
727
779
  type: "number",
728
780
  unit: "°C",
@@ -733,6 +785,7 @@ const monitoring: StateDef[] = [
733
785
  },
734
786
  {
735
787
  id: "fps",
788
+ permissions: ["process"],
736
789
  name: "Frame rate",
737
790
  type: "number",
738
791
  description: "Of the app in front, measured by PresentMon.",
@@ -796,6 +849,7 @@ function onProcess(name: string, want: "started" | "stopped", fire: (event: unkn
796
849
 
797
850
  const appOpen = defineTrigger({
798
851
  id: "app-open",
852
+ permissions: ["process"],
799
853
  name: "When an app opens",
800
854
  description: "Runs when a process starts (checked every 3 s).",
801
855
  settings: processSetting,
@@ -804,6 +858,7 @@ const appOpen = defineTrigger({
804
858
 
805
859
  const appClose = defineTrigger({
806
860
  id: "app-close",
861
+ permissions: ["process"],
807
862
  name: "When an app closes",
808
863
  description: "Runs when a process exits (checked every 3 s).",
809
864
  settings: processSetting,
@@ -812,6 +867,7 @@ const appClose = defineTrigger({
812
867
 
813
868
  const fileCreated = defineTrigger({
814
869
  id: "file-created",
870
+ permissions: ["filesystem"],
815
871
  name: "When a file appears",
816
872
  description: "Runs when a new file shows up in a folder (event.name, event.path).",
817
873
  settings: {
@@ -834,6 +890,7 @@ const fileCreated = defineTrigger({
834
890
 
835
891
  const networkChange = defineTrigger({
836
892
  id: "network-change",
893
+ permissions: [],
837
894
  name: "When the network changes",
838
895
  description: "Runs when network addresses change (event.online, event.addresses).",
839
896
  settings: {},
@@ -851,6 +908,7 @@ const networkChange = defineTrigger({
851
908
 
852
909
  const idleTrigger = defineTrigger({
853
910
  id: "idle",
911
+ permissions: ["process"],
854
912
  name: "When the computer is idle",
855
913
  description: "Runs after no keyboard or mouse input for a while, or when input comes back.",
856
914
  settings: {
@@ -889,6 +947,7 @@ const idleTrigger = defineTrigger({
889
947
 
890
948
  const appFocus = defineTrigger({
891
949
  id: "app-focus",
950
+ permissions: ["process"],
892
951
  name: "When an app comes to the front",
893
952
  description: "Runs when a window of this app gets focus (event.app), or of any app if empty.",
894
953
  settings: {
@@ -918,7 +977,7 @@ const appFocus = defineTrigger({
918
977
  export default definePlugin({
919
978
  id: "@sdeck/plugin-system",
920
979
  name: "System",
921
- version: "0.2.0",
980
+ version: "0.4.0",
922
981
  description:
923
982
  "Open apps and run commands, press media keys and shortcuts, lock and sleep, take screenshots, and monitor the computer.",
924
983
  author: "sdeck",
@@ -946,6 +1005,7 @@ export default definePlugin({
946
1005
  let sample: (() => number) | undefined;
947
1006
  return {
948
1007
  id: "cpu",
1008
+ permissions: [],
949
1009
  name: "CPU use",
950
1010
  type: "number" as const,
951
1011
  unit: "%",
@@ -960,6 +1020,7 @@ export default definePlugin({
960
1020
  })(),
961
1021
  {
962
1022
  id: "memory",
1023
+ permissions: [],
963
1024
  name: "Memory use",
964
1025
  type: "number",
965
1026
  unit: "%",
@@ -967,6 +1028,7 @@ export default definePlugin({
967
1028
  },
968
1029
  {
969
1030
  id: "memoryFree",
1031
+ permissions: [],
970
1032
  name: "Free memory",
971
1033
  type: "number",
972
1034
  unit: "bytes",
@@ -974,6 +1036,7 @@ export default definePlugin({
974
1036
  },
975
1037
  {
976
1038
  id: "processes",
1039
+ permissions: ["process"],
977
1040
  name: "Running processes",
978
1041
  type: "json",
979
1042
  description: 'Lowercased names; e.g. contains(system.processes, "javaw.exe").',
@@ -981,6 +1044,7 @@ export default definePlugin({
981
1044
  },
982
1045
  {
983
1046
  id: "idle",
1047
+ permissions: ["process"],
984
1048
  name: "Idle time",
985
1049
  type: "number",
986
1050
  unit: "s",
@@ -989,6 +1053,7 @@ export default definePlugin({
989
1053
  },
990
1054
  {
991
1055
  id: "foreground",
1056
+ permissions: ["process"],
992
1057
  name: "App in front",
993
1058
  type: "string",
994
1059
  description:
@@ -997,6 +1062,7 @@ export default definePlugin({
997
1062
  },
998
1063
  {
999
1064
  id: "online",
1065
+ permissions: [],
1000
1066
  name: "Online",
1001
1067
  type: "boolean",
1002
1068
  description: "Whether any network interface has an address.",