key-screen-framework 1.2.0 → 1.2.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.
- package/main/index.js +58 -26
- package/package.json +1 -1
- package/types/main/arduino-cli.d.ts +2 -0
- package/types/main/media-manager.d.ts +1 -0
package/main/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { createReadStream } from "node:fs";
|
|
2
|
-
import { mkdir, appendFile, readdir, rm, stat,
|
|
2
|
+
import { readFile, mkdir, cp, writeFile, appendFile, readdir, rm, stat, copyFile } from "node:fs/promises";
|
|
3
3
|
import { createRequire } from "node:module";
|
|
4
4
|
import { join, dirname, extname, relative, sep, normalize } from "node:path";
|
|
5
5
|
import { Readable } from "node:stream";
|
|
@@ -11,18 +11,26 @@ import { createScreenCatalog } from "../shared/screen-catalog.js";
|
|
|
11
11
|
import { RESET_SCREEN_TARGET, buildDefaultGlobalShortcuts, mergeGlobalShortcuts, normalizeShortcutAccelerator } from "../shared/screen-shortcuts.js";
|
|
12
12
|
import { b as normalizeScreenOverrides, m as mergeScreenOverrides, a as normalizeDisplayFit, n as normalizeAdminZoom, c as normalizeStoredScreenOverrides } from "../chunks/screen-overrides-0d_pEdnM.js";
|
|
13
13
|
import { EventEmitter } from "node:events";
|
|
14
|
+
import { createHash } from "node:crypto";
|
|
14
15
|
import { spawn } from "node:child_process";
|
|
15
16
|
import { acceleratorToArduinoKeyboardShortcut } from "../shared/arduino-keyboard-shortcut.js";
|
|
16
17
|
import { SerialPort } from "serialport";
|
|
17
18
|
import { Buffer as Buffer$1 } from "node:buffer";
|
|
18
19
|
const now$4 = () => (/* @__PURE__ */ new Date()).toISOString();
|
|
20
|
+
const ARDUINO_CLI_DATA_READY_FILE = ".key-screen-framework-arduino-data-ready";
|
|
21
|
+
async function getBundledArduinoDataRevision(bundledDataDir) {
|
|
22
|
+
const packageIndex = await readFile(join(bundledDataDir, "package_index.json"));
|
|
23
|
+
return createHash("sha256").update(packageIndex).digest("hex");
|
|
24
|
+
}
|
|
19
25
|
function resolveArduinoCliPaths(app2, options = {}) {
|
|
20
26
|
const platform = options.platform ?? process.platform;
|
|
21
27
|
const arch = options.arch ?? process.arch;
|
|
22
28
|
const resourcesRoot = app2.isPackaged ? join(options.resourcesPath ?? process.resourcesPath, "arduino") : join(app2.getAppPath(), "resources", "arduino", `${platform}-${arch}`);
|
|
29
|
+
const bundledDataDir = join(resourcesRoot, "data");
|
|
23
30
|
return {
|
|
24
31
|
cliPath: join(resourcesRoot, "bin", platform === "win32" ? "arduino-cli.exe" : "arduino-cli"),
|
|
25
|
-
|
|
32
|
+
bundledDataDir,
|
|
33
|
+
dataDir: app2.isPackaged ? join(app2.getPath("userData"), "arduino-cli-data") : bundledDataDir,
|
|
26
34
|
userDir: join(app2.getPath("userData"), "arduino-cli-user"),
|
|
27
35
|
libraryPaths: [
|
|
28
36
|
join(resourcesRoot, "libraries", "KeyescapeSerialProtocolBridge"),
|
|
@@ -30,6 +38,25 @@ function resolveArduinoCliPaths(app2, options = {}) {
|
|
|
30
38
|
]
|
|
31
39
|
};
|
|
32
40
|
}
|
|
41
|
+
async function prepareArduinoCliData(paths) {
|
|
42
|
+
if (paths.dataDir === paths.bundledDataDir) {
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
const bundledDataRevision = await getBundledArduinoDataRevision(paths.bundledDataDir);
|
|
46
|
+
try {
|
|
47
|
+
const ready = await readFile(join(paths.dataDir, ARDUINO_CLI_DATA_READY_FILE), "utf8");
|
|
48
|
+
if (ready === bundledDataRevision) {
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
} catch (error) {
|
|
52
|
+
if (error.code !== "ENOENT") {
|
|
53
|
+
throw error;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
await mkdir(paths.dataDir, { recursive: true });
|
|
57
|
+
await cp(paths.bundledDataDir, paths.dataDir, { force: true, recursive: true });
|
|
58
|
+
await writeFile(join(paths.dataDir, ARDUINO_CLI_DATA_READY_FILE), bundledDataRevision, "utf8");
|
|
59
|
+
}
|
|
33
60
|
function buildArduinoCompileArgs(options) {
|
|
34
61
|
return [
|
|
35
62
|
"compile",
|
|
@@ -71,11 +98,15 @@ class ArduinoCliRunner extends EventEmitter {
|
|
|
71
98
|
this.cancelled = true;
|
|
72
99
|
this.currentProcess?.kill("SIGTERM");
|
|
73
100
|
}
|
|
74
|
-
run(args) {
|
|
101
|
+
async run(args) {
|
|
75
102
|
if (this.currentProcess) {
|
|
76
|
-
|
|
103
|
+
throw new Error("Arduino CLI is already running.");
|
|
77
104
|
}
|
|
78
105
|
this.cancelled = false;
|
|
106
|
+
await prepareArduinoCliData(this.paths);
|
|
107
|
+
if (this.currentProcess) {
|
|
108
|
+
throw new Error("Arduino CLI is already running.");
|
|
109
|
+
}
|
|
79
110
|
return new Promise((resolve, reject) => {
|
|
80
111
|
const child = this.spawnProcess(this.paths.cliPath, args, {
|
|
81
112
|
env: {
|
|
@@ -1083,6 +1114,29 @@ const MEDIA_EXTENSION_BY_TYPE = {
|
|
|
1083
1114
|
audio: /* @__PURE__ */ new Set([".aac", ".flac", ".m4a", ".mp3", ".oga", ".ogg", ".wav", ".weba"]),
|
|
1084
1115
|
font: /* @__PURE__ */ new Set([".otf", ".ttf", ".woff", ".woff2"])
|
|
1085
1116
|
};
|
|
1117
|
+
function getMediaContentType(fileName) {
|
|
1118
|
+
const extension = extname(fileName).toLowerCase();
|
|
1119
|
+
if (extension === ".mp4" || extension === ".m4v") return "video/mp4";
|
|
1120
|
+
if (extension === ".mov") return "video/quicktime";
|
|
1121
|
+
if (extension === ".webm") return "video/webm";
|
|
1122
|
+
if (extension === ".ogg" || extension === ".ogv") return "video/ogg";
|
|
1123
|
+
if (extension === ".mp3") return "audio/mpeg";
|
|
1124
|
+
if (extension === ".wav") return "audio/wav";
|
|
1125
|
+
if (extension === ".m4a") return "audio/mp4";
|
|
1126
|
+
if (extension === ".aac") return "audio/aac";
|
|
1127
|
+
if (extension === ".flac") return "audio/flac";
|
|
1128
|
+
if (extension === ".png") return "image/png";
|
|
1129
|
+
if (extension === ".jpg" || extension === ".jpeg") return "image/jpeg";
|
|
1130
|
+
if (extension === ".webp") return "image/webp";
|
|
1131
|
+
if (extension === ".gif") return "image/gif";
|
|
1132
|
+
if (extension === ".avif") return "image/avif";
|
|
1133
|
+
if (extension === ".svg") return "image/svg+xml";
|
|
1134
|
+
if (extension === ".woff2") return "font/woff2";
|
|
1135
|
+
if (extension === ".woff") return "font/woff";
|
|
1136
|
+
if (extension === ".ttf") return "font/ttf";
|
|
1137
|
+
if (extension === ".otf") return "font/otf";
|
|
1138
|
+
return "application/octet-stream";
|
|
1139
|
+
}
|
|
1086
1140
|
function assertMediaType(type) {
|
|
1087
1141
|
if (!MEDIA_TYPES.includes(type)) {
|
|
1088
1142
|
throw new Error(`Unsupported media type: ${type}`);
|
|
@@ -1566,28 +1620,6 @@ function startKeyScreenMain(options) {
|
|
|
1566
1620
|
const name = decodeURIComponent(url.pathname.replace(/^\/+/, ""));
|
|
1567
1621
|
return { type, name };
|
|
1568
1622
|
}
|
|
1569
|
-
function getMediaContentType(fileName) {
|
|
1570
|
-
const extension = extname(fileName).toLowerCase();
|
|
1571
|
-
if (extension === ".mp4" || extension === ".m4v") return "video/mp4";
|
|
1572
|
-
if (extension === ".mov") return "video/quicktime";
|
|
1573
|
-
if (extension === ".webm") return "video/webm";
|
|
1574
|
-
if (extension === ".ogg" || extension === ".ogv") return "video/ogg";
|
|
1575
|
-
if (extension === ".mp3") return "audio/mpeg";
|
|
1576
|
-
if (extension === ".wav") return "audio/wav";
|
|
1577
|
-
if (extension === ".m4a") return "audio/mp4";
|
|
1578
|
-
if (extension === ".aac") return "audio/aac";
|
|
1579
|
-
if (extension === ".flac") return "audio/flac";
|
|
1580
|
-
if (extension === ".png") return "image/png";
|
|
1581
|
-
if (extension === ".jpg" || extension === ".jpeg") return "image/jpeg";
|
|
1582
|
-
if (extension === ".webp") return "image/webp";
|
|
1583
|
-
if (extension === ".gif") return "image/gif";
|
|
1584
|
-
if (extension === ".avif") return "image/avif";
|
|
1585
|
-
if (extension === ".woff2") return "font/woff2";
|
|
1586
|
-
if (extension === ".woff") return "font/woff";
|
|
1587
|
-
if (extension === ".ttf") return "font/ttf";
|
|
1588
|
-
if (extension === ".otf") return "font/otf";
|
|
1589
|
-
return "application/octet-stream";
|
|
1590
|
-
}
|
|
1591
1623
|
async function createMediaProtocolResponse(mediaManager, request) {
|
|
1592
1624
|
const ref = parseMediaProtocolUrl(request.url);
|
|
1593
1625
|
const filePath = mediaManager.resolveMediaPath(ref);
|
package/package.json
CHANGED
|
@@ -2,6 +2,7 @@ import { EventEmitter } from 'node:events';
|
|
|
2
2
|
import { spawn } from 'node:child_process';
|
|
3
3
|
export interface ArduinoCliPaths {
|
|
4
4
|
cliPath: string;
|
|
5
|
+
bundledDataDir: string;
|
|
5
6
|
dataDir: string;
|
|
6
7
|
userDir: string;
|
|
7
8
|
libraryPaths: string[];
|
|
@@ -29,6 +30,7 @@ export declare function resolveArduinoCliPaths(app: AppPathLike, options?: {
|
|
|
29
30
|
platform?: NodeJS.Platform;
|
|
30
31
|
resourcesPath?: string;
|
|
31
32
|
}): ArduinoCliPaths;
|
|
33
|
+
export declare function prepareArduinoCliData(paths: ArduinoCliPaths): Promise<void>;
|
|
32
34
|
export declare function buildArduinoCompileArgs(options: {
|
|
33
35
|
fqbn: string;
|
|
34
36
|
libraryPaths: string[];
|