跳到主要内容

Claude Cage · 面向 Claude 的隔离开发环境,支持桌面工作台、多账号、远程部署与移动端连接。上游 Lee-xeo/Claude-Cage 完整源码镜像,非灵栈原创;主许可 MIT,第三方组件遵循各自许可。来源:https://github.com/Lee-xeo/Claude-Cage 。手动同步,不附带 Release 安装包。

浏览文件

display-density.mjs

60 行 · 2.0 KB历史下载
1import { spawn } from "node:child_process";
2import { existsSync, mkdirSync, renameSync, writeFileSync } from "node:fs";
3import path from "node:path";
4
5// Chromium applies an XSETTINGS density in steps of 1/64.
6export function displayDensity(value) {
7 return typeof value === "number" && value >= 0.75 && value <= 4 ? Math.round(value * 64) / 64 : null;
8}
9
10export function densitySettings(scale) {
11 const dpi = Math.round(scale * 96 * 1024);
12 return `Xft/DPI ${dpi}\nGdk/WindowScalingFactor 1\nGdk/UnscaledDPI ${dpi}\n`;
13}
14
15// A display's pixel density is an XSETTINGS value, and Chromium follows a
16// change without restarting. Each viewer can then have the density of its own
17// screen. Without xsettingsd the display keeps the density it started with.
18export function createDisplaySettings({
19 file, initial, available = existsSync("/usr/bin/xsettingsd"),
20 start = () => spawn("/usr/bin/xsettingsd", ["--config=" + file], { stdio: "ignore" }), restart = 1000,
21}) {
22 let scale = initial, child, timer, closed = false;
23 const write = () => {
24 writeFileSync(file + ".new", densitySettings(scale));
25 renameSync(file + ".new", file);
26 };
27 const run = () => {
28 const current = child = start();
29 // Applications fall back to 96 DPI while no manager owns the settings.
30 const ended = () => {
31 if (child !== current) return;
32 child = undefined;
33 if (!closed) timer = setTimeout(run, restart);
34 };
35 current.on("error", ended);
36 current.on("exit", ended);
37 };
38 if (available) {
39 mkdirSync(path.dirname(file), { recursive: true });
40 write();
41 run();
42 }
43 return {
44 available,
45 get scale() { return scale; },
46 set(value) {
47 if (!available || value === scale) return scale;
48 scale = value;
49 write();
50 // A manager that is being restarted reads the new file when it starts.
51 child?.kill("SIGHUP");
52 return scale;
53 },
54 close() {
55 closed = true;
56 clearTimeout(timer);
57 child?.kill();
58 },
59 };
60}