pi-sync-system-theme 0.2.1 → 0.2.3
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/index.ts +20 -9
- package/package.json +1 -1
package/index.ts
CHANGED
|
@@ -61,7 +61,7 @@ const DEFAULT_CONFIG: Config = {
|
|
|
61
61
|
const GLOBAL_CONFIG_PATH = path.join(os.homedir(), ".pi", "agent", "system-theme.json");
|
|
62
62
|
const DETECTION_TIMEOUT_MS = 1200;
|
|
63
63
|
const MIN_POLL_MS = 1000;
|
|
64
|
-
const OSC11_QUERY_TIMEOUT_MS =
|
|
64
|
+
const OSC11_QUERY_TIMEOUT_MS = 2200;
|
|
65
65
|
const OSC11_MIN_INTERVAL_MS = 15_000;
|
|
66
66
|
const OSC11_DISABLE_AFTER_FAILURES = 3;
|
|
67
67
|
const OSC11_DISABLE_COOLDOWN_MS = 60_000;
|
|
@@ -216,13 +216,16 @@ let fd;
|
|
|
216
216
|
try { fd = fs.openSync('/dev/tty', fs.constants.O_RDWR | fs.constants.O_NOCTTY | O_NONBLOCK); }
|
|
217
217
|
catch { process.exit(1); }
|
|
218
218
|
|
|
219
|
-
// Send OSC 11 query
|
|
220
|
-
try {
|
|
219
|
+
// Send OSC 11 query. Emit both ST and BEL terminated variants for compatibility.
|
|
220
|
+
try {
|
|
221
|
+
fs.writeSync(fd, '\x1b]11;?\x1b\\');
|
|
222
|
+
fs.writeSync(fd, '\x1b]11;?\x07');
|
|
223
|
+
}
|
|
221
224
|
catch { try { fs.closeSync(fd); } catch {} process.exit(1); }
|
|
222
225
|
|
|
223
226
|
const buf = Buffer.alloc(1024);
|
|
224
227
|
let response = '';
|
|
225
|
-
const deadline = Date.now() +
|
|
228
|
+
const deadline = Date.now() + 1800;
|
|
226
229
|
|
|
227
230
|
function tryRead() {
|
|
228
231
|
while (true) {
|
|
@@ -239,13 +242,21 @@ function tryRead() {
|
|
|
239
242
|
}
|
|
240
243
|
}
|
|
241
244
|
|
|
245
|
+
function to8Bit(hex) {
|
|
246
|
+
if (!hex) return 0;
|
|
247
|
+
const h = String(hex);
|
|
248
|
+
if (h.length <= 2) return parseInt(h.padEnd(2, h[h.length - 1] || '0'), 16);
|
|
249
|
+
return parseInt(h.slice(0, 2), 16);
|
|
250
|
+
}
|
|
251
|
+
|
|
242
252
|
function done() {
|
|
243
253
|
try { fs.closeSync(fd); } catch {}
|
|
244
|
-
|
|
254
|
+
// Keep parser permissive: tmux may wrap control sequences, but rgb payload remains stable.
|
|
255
|
+
const m = response.match(/rgb:([0-9a-fA-F]{2,8})\\/([0-9a-fA-F]{2,8})\\/([0-9a-fA-F]{2,8})/);
|
|
245
256
|
if (m) {
|
|
246
|
-
const r =
|
|
247
|
-
const g =
|
|
248
|
-
const b =
|
|
257
|
+
const r = to8Bit(m[1]);
|
|
258
|
+
const g = to8Bit(m[2]);
|
|
259
|
+
const b = to8Bit(m[3]);
|
|
249
260
|
const luminance = 0.299 * r + 0.587 * g + 0.114 * b;
|
|
250
261
|
process.stdout.write(luminance < 128 ? 'dark' : 'light');
|
|
251
262
|
}
|
|
@@ -254,7 +265,7 @@ function done() {
|
|
|
254
265
|
|
|
255
266
|
function poll() {
|
|
256
267
|
tryRead();
|
|
257
|
-
if (response.includes('
|
|
268
|
+
if (response.includes('rgb:') || Date.now() > deadline) return done();
|
|
258
269
|
setTimeout(poll, 16);
|
|
259
270
|
}
|
|
260
271
|
|