@walldock/agent 0.1.0 → 0.1.2

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.
@@ -23,21 +23,23 @@ public class MonitorHelper {
23
23
  [MarshalAs(UnmanagedType.ByValTStr, SizeConst=32)] public string Device;
24
24
  }
25
25
  public delegate bool MonitorEnumProc(IntPtr hMon, IntPtr hdc, ref RECT rc, IntPtr data);
26
+ private static List<string> _results = new List<string>();
27
+ private static bool Callback(IntPtr hMon, IntPtr hdc, ref RECT rc, IntPtr data) {
28
+ var info = new MonitorInfo(); info.Size = (uint)Marshal.SizeOf(info);
29
+ GetMonitorInfo(hMon, ref info);
30
+ uint dx, dy;
31
+ GetDpiForMonitor(hMon, 0, out dx, out dy);
32
+ double scale = dx / 96.0;
33
+ int w = info.Monitor.R - info.Monitor.L;
34
+ int h = info.Monitor.B - info.Monitor.T;
35
+ int primary = (info.Flags & 1) != 0 ? 1 : 0;
36
+ _results.Add(info.Device + "|" + info.Monitor.L + "|" + info.Monitor.T + "|" + w + "|" + h + "|" + scale.ToString("F6") + "|" + primary);
37
+ return true;
38
+ }
26
39
  public static List<string> Enumerate() {
27
- var results = new List<string>();
28
- EnumDisplayMonitors(IntPtr.Zero, IntPtr.Zero, (hMon, hdc, ref rc, data) => {
29
- var info = new MonitorInfo(); info.Size = (uint)Marshal.SizeOf(info);
30
- GetMonitorInfo(hMon, ref info);
31
- uint dx, dy;
32
- GetDpiForMonitor(hMon, 0, out dx, out dy);
33
- double scale = dx / 96.0;
34
- int w = info.Monitor.R - info.Monitor.L;
35
- int h = info.Monitor.B - info.Monitor.T;
36
- int primary = (info.Flags & 1) != 0 ? 1 : 0;
37
- results.Add(info.Device + "|" + info.Monitor.L + "|" + info.Monitor.T + "|" + w + "|" + h + "|" + scale.ToString("F6") + "|" + primary);
38
- return true;
39
- }, IntPtr.Zero);
40
- return results;
40
+ _results = new List<string>();
41
+ EnumDisplayMonitors(IntPtr.Zero, IntPtr.Zero, new MonitorEnumProc(Callback), IntPtr.Zero);
42
+ return _results;
41
43
  }
42
44
  }
43
45
  "@
@@ -42,8 +42,8 @@ exports.clearDeviceIdentity = clearDeviceIdentity;
42
42
  const fs = __importStar(require("node:fs/promises"));
43
43
  const path = __importStar(require("node:path"));
44
44
  const os = __importStar(require("node:os"));
45
- const KEYTAR_SERVICE = 'walldock-agent';
46
- const KEYTAR_ACCOUNT = 'device-token';
45
+ const KEYRING_SERVICE = 'walldock-agent';
46
+ const KEYRING_ACCOUNT = 'device-token';
47
47
  function configDir() {
48
48
  if (process.platform === 'win32') {
49
49
  return path.join(process.env['APPDATA'] ?? os.homedir(), 'walldock');
@@ -67,57 +67,44 @@ async function writeAuthFile(data) {
67
67
  await fs.mkdir(path.dirname(CONFIG_FILE), { recursive: true });
68
68
  await fs.writeFile(CONFIG_FILE, JSON.stringify(data, null, 2), { mode: 0o600 });
69
69
  }
70
- async function tryKeytar() {
70
+ function secureEntry() {
71
+ // eslint-disable-next-line @typescript-eslint/no-require-imports
72
+ const { Entry } = require('@napi-rs/keyring');
73
+ return new Entry(KEYRING_SERVICE, KEYRING_ACCOUNT);
74
+ }
75
+ async function getDeviceToken() {
71
76
  try {
72
- // eslint-disable-next-line @typescript-eslint/no-require-imports
73
- return require('keytar');
77
+ const token = secureEntry().getPassword();
78
+ if (token)
79
+ return token;
74
80
  }
75
81
  catch {
76
- return null;
77
- }
78
- }
79
- async function getDeviceToken() {
80
- const keytar = await tryKeytar();
81
- if (keytar) {
82
- try {
83
- const token = await keytar.getPassword(KEYTAR_SERVICE, KEYTAR_ACCOUNT);
84
- if (token)
85
- return token;
86
- }
87
- catch {
88
- // fall through to file
89
- }
82
+ // keyring unavailable or entry not found — fall through to file
90
83
  }
91
84
  const auth = await readAuthFile();
92
85
  return auth.deviceToken ?? null;
93
86
  }
94
87
  async function setDeviceToken(token) {
95
- const keytar = await tryKeytar();
96
- if (keytar) {
97
- try {
98
- await keytar.setPassword(KEYTAR_SERVICE, KEYTAR_ACCOUNT, token);
99
- // also write identity file (without token) so offline boot still works
100
- const auth = await readAuthFile();
101
- delete auth.deviceToken;
102
- await writeAuthFile(auth);
103
- return;
104
- }
105
- catch {
106
- // fall through to file
107
- }
88
+ try {
89
+ secureEntry().setPassword(token);
90
+ // also write identity file (without token) so offline boot still works
91
+ const auth = await readAuthFile();
92
+ delete auth.deviceToken;
93
+ await writeAuthFile(auth);
94
+ return;
95
+ }
96
+ catch {
97
+ // keyring unavailable — fall through to file
108
98
  }
109
99
  const auth = await readAuthFile();
110
100
  auth.deviceToken = token;
111
101
  await writeAuthFile(auth);
112
102
  }
113
103
  async function deleteDeviceToken() {
114
- const keytar = await tryKeytar();
115
- if (keytar) {
116
- try {
117
- await keytar.deletePassword(KEYTAR_SERVICE, KEYTAR_ACCOUNT);
118
- }
119
- catch { /* ok */ }
104
+ try {
105
+ secureEntry().deletePassword();
120
106
  }
107
+ catch { /* ok */ }
121
108
  const auth = await readAuthFile();
122
109
  delete auth.deviceToken;
123
110
  await writeAuthFile(auth);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@walldock/agent",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
4
4
  "description": "Walldock desktop agent — sync wallpapers across all your screens",
5
5
  "license": "MIT",
6
6
  "main": "dist/main.js",
@@ -14,10 +14,9 @@
14
14
  "node": ">=18.0.0"
15
15
  },
16
16
  "dependencies": {
17
- "keytar": "^7.9.0"
17
+ "@napi-rs/keyring": "^1.1.5"
18
18
  },
19
19
  "devDependencies": {
20
- "@types/keytar": "^4.4.2",
21
20
  "@types/node": "^20.0.0",
22
21
  "typescript": "^5.4.0"
23
22
  },