key-screen-framework 1.2.1 → 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 CHANGED
@@ -1,5 +1,5 @@
1
1
  import { createReadStream } from "node:fs";
2
- import { mkdir, appendFile, readdir, rm, stat, readFile, copyFile, writeFile } from "node:fs/promises";
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
- dataDir: join(resourcesRoot, "data"),
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
- return Promise.reject(new Error("Arduino CLI is already running."));
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: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "key-screen-framework",
3
- "version": "1.2.1",
3
+ "version": "1.2.2",
4
4
  "description": "Screen framework for Keyescape desktop projects.",
5
5
  "repository": {
6
6
  "type": "git",
@@ -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[];