@walldock/agent 0.1.3 → 0.1.5

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/dist/sync.d.ts CHANGED
@@ -17,6 +17,7 @@ export declare class SyncService {
17
17
  private sse;
18
18
  private tickInFlight;
19
19
  private lastScreensFingerprint;
20
+ private invalidTokenHandled;
20
21
  /** Per-process cache: stableId → wallpaperId we successfully applied */
21
22
  private readonly applied;
22
23
  constructor(api: AgentApi, callbacks: SyncCallbacks);
package/dist/sync.js CHANGED
@@ -17,6 +17,7 @@ class SyncService {
17
17
  sse = null;
18
18
  tickInFlight = null;
19
19
  lastScreensFingerprint = null;
20
+ invalidTokenHandled = false;
20
21
  /** Per-process cache: stableId → wallpaperId we successfully applied */
21
22
  applied = new Map();
22
23
  constructor(api, callbacks) {
@@ -27,6 +28,7 @@ class SyncService {
27
28
  this.stop();
28
29
  this.context = context;
29
30
  this.lastScreensFingerprint = null;
31
+ this.invalidTokenHandled = false;
30
32
  this.applied.clear();
31
33
  const sseUrl = `${this.api.endpoint.replace('/api/graphql', '')}/api/agent/events?token=${encodeURIComponent(context.token)}`;
32
34
  this.sse = (0, sse_1.connectSse)(sseUrl, (type) => {
@@ -76,6 +78,9 @@ class SyncService {
76
78
  }
77
79
  }
78
80
  notifyInvalidToken() {
81
+ if (this.invalidTokenHandled)
82
+ return;
83
+ this.invalidTokenHandled = true;
79
84
  this.stop();
80
85
  this.callbacks.onInvalidToken();
81
86
  }
@@ -1,5 +1 @@
1
- /**
2
- * Set wallpaper on Windows using the IDesktopWallpaper COM interface via inline C# in PowerShell.
3
- * monitorIndex maps to GetMonitorDevicePathAt(monitorIndex) — same order as our screen enumeration.
4
- */
5
1
  export declare function setWallpaperWindows(imagePath: string, monitorIndex: number): Promise<void>;
@@ -4,55 +4,54 @@ exports.setWallpaperWindows = setWallpaperWindows;
4
4
  const node_child_process_1 = require("node:child_process");
5
5
  const node_util_1 = require("node:util");
6
6
  const exec = (0, node_util_1.promisify)(node_child_process_1.execFile);
7
- /**
8
- * Set wallpaper on Windows using the IDesktopWallpaper COM interface via inline C# in PowerShell.
9
- * monitorIndex maps to GetMonitorDevicePathAt(monitorIndex) — same order as our screen enumeration.
10
- */
11
7
  async function setWallpaperWindows(imagePath, monitorIndex) {
12
- // Escape path for PowerShell string
13
8
  const safePath = imagePath.replace(/'/g, "''");
9
+ // All COM work is done inside the C# class — PowerShell cannot cast System.__ComObject
10
+ // to a custom Add-Type interface, but C# can cast it natively via COM interop.
14
11
  const script = `
15
12
  $ErrorActionPreference = 'Stop'
16
13
  Add-Type @"
17
14
  using System;
18
15
  using System.Runtime.InteropServices;
19
-
20
- [ComImport, Guid("B92B56A9-8B55-4E14-9A89-0199BBB6F93B"),
21
- InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
22
- public interface IDesktopWallpaper {
23
- void SetWallpaper([MarshalAs(UnmanagedType.LPWStr)] string monitorID,
24
- [MarshalAs(UnmanagedType.LPWStr)] string wallpaper);
25
- [return: MarshalAs(UnmanagedType.LPWStr)]
26
- string GetWallpaper([MarshalAs(UnmanagedType.LPWStr)] string monitorID);
27
- [return: MarshalAs(UnmanagedType.LPWStr)]
28
- string GetMonitorDevicePathAt(uint monitorIndex);
29
- [return: MarshalAs(UnmanagedType.U4)]
30
- uint GetMonitorDevicePathCount();
31
- void GetMonitorRECT([MarshalAs(UnmanagedType.LPWStr)] string monitorID,
32
- out tagRECT displayRect);
33
- void SetBackgroundColor(uint color);
34
- uint GetBackgroundColor();
35
- void SetPosition(int position);
36
- int GetPosition();
37
- void SetSlideshow(object items);
38
- void GetSlideshow(out object items);
39
- void SetSlideshowOptions(int options, uint tick);
40
- void GetSlideshowOptions(out int options, out uint tick);
41
- void AdvanceSlideshow([MarshalAs(UnmanagedType.LPWStr)] string monitorID, int direction);
42
- int GetStatus([MarshalAs(UnmanagedType.LPWStr)] string monitorID);
43
- bool Enable(bool enable);
16
+ public class WallpaperHelper {
17
+ [ComImport, Guid("B92B56A9-8B55-4E14-9A89-0199BBB6F93B"),
18
+ InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
19
+ private interface IDesktopWallpaper {
20
+ void SetWallpaper([MarshalAs(UnmanagedType.LPWStr)] string monitorID,
21
+ [MarshalAs(UnmanagedType.LPWStr)] string wallpaper);
22
+ [return: MarshalAs(UnmanagedType.LPWStr)]
23
+ string GetWallpaper([MarshalAs(UnmanagedType.LPWStr)] string monitorID);
24
+ [return: MarshalAs(UnmanagedType.LPWStr)]
25
+ string GetMonitorDevicePathAt(uint monitorIndex);
26
+ [return: MarshalAs(UnmanagedType.U4)]
27
+ uint GetMonitorDevicePathCount();
28
+ void GetMonitorRECT([MarshalAs(UnmanagedType.LPWStr)] string monitorID,
29
+ out tagRECT displayRect);
30
+ void SetBackgroundColor(uint color);
31
+ uint GetBackgroundColor();
32
+ void SetPosition(int position);
33
+ int GetPosition();
34
+ void SetSlideshow(object items);
35
+ void GetSlideshow(out object items);
36
+ void SetSlideshowOptions(int options, uint tick);
37
+ void GetSlideshowOptions(out int options, out uint tick);
38
+ void AdvanceSlideshow([MarshalAs(UnmanagedType.LPWStr)] string monitorID, int direction);
39
+ int GetStatus([MarshalAs(UnmanagedType.LPWStr)] string monitorID);
40
+ bool Enable(bool enable);
41
+ }
42
+ [StructLayout(LayoutKind.Sequential)]
43
+ private struct tagRECT { public int left, top, right, bottom; }
44
+ [ComImport, Guid("C2CF3110-460E-4FC1-B9D0-8A1C0C9CC4BD")]
45
+ private class DesktopWallpaperClass {}
46
+ public static void Set(uint monitorIndex, string wallpaperPath) {
47
+ var wt = new DesktopWallpaperClass();
48
+ var wp = (IDesktopWallpaper)wt;
49
+ var monPath = wp.GetMonitorDevicePathAt(monitorIndex);
50
+ wp.SetWallpaper(monPath, wallpaperPath);
51
+ }
44
52
  }
45
-
46
- [StructLayout(LayoutKind.Sequential)]
47
- public struct tagRECT { public int left, top, right, bottom; }
48
-
49
- [ComImport, Guid("C2CF3110-460E-4FC1-B9D0-8A1C0C9CC4BD")]
50
- public class DesktopWallpaperClass {}
51
53
  "@
52
- $wt = [System.Activator]::CreateInstance([Type]::GetTypeFromCLSID([Guid]'C2CF3110-460E-4FC1-B9D0-8A1C0C9CC4BD'))
53
- $wp = [IDesktopWallpaper]$wt
54
- $monPath = $wp.GetMonitorDevicePathAt(${monitorIndex})
55
- $wp.SetWallpaper($monPath, '${safePath}')
54
+ [WallpaperHelper]::Set(${monitorIndex}, '${safePath}')
56
55
  `.trim();
57
56
  await exec('powershell.exe', ['-NoProfile', '-Command', script]);
58
57
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@walldock/agent",
3
- "version": "0.1.3",
3
+ "version": "0.1.5",
4
4
  "description": "Walldock desktop agent — sync wallpapers across all your screens",
5
5
  "license": "MIT",
6
6
  "main": "dist/main.js",