key-screen-framework 1.5.0 → 1.5.1

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
@@ -4,7 +4,7 @@ import { createRequire } from "node:module";
4
4
  import { join, dirname, extname, relative, sep, normalize } from "node:path";
5
5
  import { Readable } from "node:stream";
6
6
  import { fileURLToPath } from "node:url";
7
- import { app, protocol, dialog, ipcMain, shell, BrowserWindow, screen } from "electron";
7
+ import { app, protocol, dialog, screen, ipcMain, shell, BrowserWindow } from "electron";
8
8
  import Store from "electron-store";
9
9
  import { validateArduinoBoardConfig, suggestArduinoBoardPreset, defaultArduinoBoardConfig } from "../shared/arduino-board.js";
10
10
  import { createScreenCatalog } from "../shared/screen-catalog.js";
@@ -70,6 +70,7 @@ function buildArduinoUploadArgs(options) {
70
70
  return [
71
71
  "compile",
72
72
  "--upload",
73
+ "--verbose",
73
74
  "-p",
74
75
  options.portPath,
75
76
  "--fqbn",
@@ -295,6 +296,14 @@ function isReloadShortcut(input, platform = process.platform) {
295
296
  }
296
297
  return Boolean(input.key?.toLowerCase() === "f5" || hasPrimaryModifier$1(input, platform) && isKey$1(input, "r"));
297
298
  }
299
+ const FUNCTION_KEY_PATTERN = /^f([1-9]|1[0-9]|2[0-4])$/;
300
+ function isBlockedFunctionKey(input) {
301
+ const key = input.key?.toLowerCase() ?? "";
302
+ if (!FUNCTION_KEY_PATTERN.test(key)) {
303
+ return false;
304
+ }
305
+ return !(input.alt && key === "f4");
306
+ }
298
307
  const SERIAL_BAUD_RATE = 115200;
299
308
  const REQUEST_TIMEOUT_MS = 500;
300
309
  const REQUEST_RETRY_LIMIT = 3;
@@ -1389,6 +1398,10 @@ function parseByteRange(rangeHeader, sizeBytes) {
1389
1398
  end: Math.min(requestedEnd, sizeBytes - 1)
1390
1399
  };
1391
1400
  }
1401
+ const COVERING_TOLERANCE_PX = 2;
1402
+ function isWindowCoveringDisplay(windowBounds, displayBounds) {
1403
+ return windowBounds.x <= displayBounds.x + COVERING_TOLERANCE_PX && windowBounds.y <= displayBounds.y + COVERING_TOLERANCE_PX && windowBounds.x + windowBounds.width >= displayBounds.x + displayBounds.width - COVERING_TOLERANCE_PX && windowBounds.y + windowBounds.height >= displayBounds.y + displayBounds.height - COVERING_TOLERANCE_PX;
1404
+ }
1392
1405
  function getEnvWindowModeOverride(env) {
1393
1406
  if (env.KEYESCAPE_KIOSK === "1") {
1394
1407
  return "kiosk";
@@ -1419,6 +1432,10 @@ function applyWindowMode(window, mode, options = {}) {
1419
1432
  window.setMovable(isWindowed);
1420
1433
  window.setFullScreenable(true);
1421
1434
  if (isKiosk) {
1435
+ if (options.forceKioskReentry) {
1436
+ window.setKiosk(false);
1437
+ window.setFullScreen(false);
1438
+ }
1422
1439
  if (canUnmaximize) {
1423
1440
  window.unmaximize();
1424
1441
  }
@@ -1469,6 +1486,10 @@ public static class KioskWindowsKeyBlocker {
1469
1486
  private const int WM_SYSKEYUP = 0x0105;
1470
1487
  private const int VK_LWIN = 0x5B;
1471
1488
  private const int VK_RWIN = 0x5C;
1489
+ private const int VK_TAB = 0x09;
1490
+ private const int VK_ESCAPE = 0x1B;
1491
+ private const int VK_CONTROL = 0x11;
1492
+ private const int LLKHF_ALTDOWN = 0x20;
1472
1493
 
1473
1494
  private static LowLevelKeyboardProc proc = HookCallback;
1474
1495
  private static IntPtr hookId = IntPtr.Zero;
@@ -1491,7 +1512,8 @@ public static class KioskWindowsKeyBlocker {
1491
1512
  private static IntPtr HookCallback(int nCode, IntPtr wParam, IntPtr lParam) {
1492
1513
  if (nCode >= 0 && IsKeyboardMessage(wParam)) {
1493
1514
  int vkCode = Marshal.ReadInt32(lParam);
1494
- if (vkCode == VK_LWIN || vkCode == VK_RWIN) {
1515
+ int flags = Marshal.ReadInt32(lParam, 8);
1516
+ if (IsBlockedKey(vkCode, (flags & LLKHF_ALTDOWN) != 0)) {
1495
1517
  return (IntPtr)1;
1496
1518
  }
1497
1519
  }
@@ -1499,6 +1521,21 @@ public static class KioskWindowsKeyBlocker {
1499
1521
  return CallNextHookEx(hookId, nCode, wParam, lParam);
1500
1522
  }
1501
1523
 
1524
+ // Ctrl+Esc and Ctrl+Shift+Esc open Start and Task Manager; Alt+Tab and Alt+Esc switch windows.
1525
+ // Ctrl+Alt+Del cannot be intercepted here; see docs/windows-store-pc-lockdown.md.
1526
+ private static bool IsBlockedKey(int vkCode, bool altDown) {
1527
+ if (vkCode == VK_LWIN || vkCode == VK_RWIN) {
1528
+ return true;
1529
+ }
1530
+
1531
+ bool controlDown = (GetAsyncKeyState(VK_CONTROL) & 0x8000) != 0;
1532
+ if (vkCode == VK_ESCAPE) {
1533
+ return controlDown || altDown;
1534
+ }
1535
+
1536
+ return vkCode == VK_TAB && altDown;
1537
+ }
1538
+
1502
1539
  private static bool IsKeyboardMessage(IntPtr wParam) {
1503
1540
  int message = wParam.ToInt32();
1504
1541
  return message == WM_KEYDOWN || message == WM_KEYUP || message == WM_SYSKEYDOWN || message == WM_SYSKEYUP;
@@ -1514,6 +1551,9 @@ public static class KioskWindowsKeyBlocker {
1514
1551
  [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
1515
1552
  private static extern IntPtr CallNextHookEx(IntPtr hhk, int nCode, IntPtr wParam, IntPtr lParam);
1516
1553
 
1554
+ [DllImport("user32.dll")]
1555
+ private static extern short GetAsyncKeyState(int vKey);
1556
+
1517
1557
  [DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)]
1518
1558
  private static extern IntPtr GetModuleHandle(string lpModuleName);
1519
1559
  }
@@ -1602,6 +1642,7 @@ function startKeyScreenMain(options) {
1602
1642
  let mainWindow = null;
1603
1643
  let currentWindowMode = "windowed";
1604
1644
  let allowKioskQuit = false;
1645
+ let kioskEnforcementTimers = [];
1605
1646
  let activeArduinoBuild = null;
1606
1647
  let arduinoLogSequence = 0;
1607
1648
  let arduinoBuildStatus = {
@@ -1909,19 +1950,40 @@ function startKeyScreenMain(options) {
1909
1950
  activeArduinoBuild = null;
1910
1951
  }
1911
1952
  }
1912
- function applyCurrentWindowMode() {
1953
+ function getKioskBounds(window) {
1954
+ return screen.getDisplayMatching(window.getBounds()).bounds;
1955
+ }
1956
+ function applyCurrentWindowMode(options2 = {}) {
1913
1957
  if (!mainWindow) {
1914
1958
  return;
1915
1959
  }
1916
1960
  applyWindowMode(mainWindow, currentWindowMode, {
1917
- kioskBounds: screen.getDisplayMatching(mainWindow.getBounds()).bounds
1961
+ kioskBounds: getKioskBounds(mainWindow),
1962
+ forceKioskReentry: options2.forceKioskReentry
1963
+ });
1964
+ }
1965
+ function logWindowState(reason) {
1966
+ if (!mainWindow || mainWindow.isDestroyed()) {
1967
+ return;
1968
+ }
1969
+ log.info("[window]", reason, {
1970
+ mode: currentWindowMode,
1971
+ bounds: mainWindow.getBounds(),
1972
+ displayBounds: getKioskBounds(mainWindow),
1973
+ isFullScreen: mainWindow.isFullScreen(),
1974
+ isKiosk: mainWindow.isKiosk(),
1975
+ isVisible: mainWindow.isVisible()
1918
1976
  });
1919
1977
  }
1920
1978
  function enforceKioskWindowMode() {
1921
- if (!mainWindow || currentWindowMode !== "kiosk") {
1979
+ if (!mainWindow || mainWindow.isDestroyed() || currentWindowMode !== "kiosk") {
1922
1980
  return;
1923
1981
  }
1924
- applyCurrentWindowMode();
1982
+ const isCovering = isWindowCoveringDisplay(mainWindow.getBounds(), getKioskBounds(mainWindow));
1983
+ if (!isCovering) {
1984
+ logWindowState("kiosk window does not cover display, re-entering kiosk");
1985
+ }
1986
+ applyCurrentWindowMode({ forceKioskReentry: !isCovering });
1925
1987
  mainWindow.show();
1926
1988
  mainWindow.focus();
1927
1989
  }
@@ -1929,9 +1991,11 @@ function startKeyScreenMain(options) {
1929
1991
  if (currentWindowMode !== "kiosk") {
1930
1992
  return;
1931
1993
  }
1932
- for (const delayMs of [50, 250, 1e3, 2500]) {
1933
- setTimeout(enforceKioskWindowMode, delayMs);
1994
+ for (const timer of kioskEnforcementTimers) {
1995
+ clearTimeout(timer);
1934
1996
  }
1997
+ kioskEnforcementTimers = [50, 250, 1e3, 2500, 5e3].map((delayMs) => setTimeout(enforceKioskWindowMode, delayMs));
1998
+ kioskEnforcementTimers.push(setTimeout(() => logWindowState("kiosk enforcement finished"), 5500));
1935
1999
  }
1936
2000
  function syncWindowsKeyLockToWindowMode() {
1937
2001
  if (currentWindowMode === "kiosk") {
@@ -1989,8 +2053,9 @@ function startKeyScreenMain(options) {
1989
2053
  minHeight: 760,
1990
2054
  show: false,
1991
2055
  autoHideMenuBar: true,
1992
- fullscreen: initialWindowMode !== "windowed",
1993
- kiosk: initialWindowMode === "kiosk",
2056
+ // 키오스크는 숨긴 창을 처음부터 전체화면으로 만들면 작은 창으로 남을 수 있어, 창을 보인 뒤 관리자 화면에서 켤 때와 같은 경로로 적용한다.
2057
+ fullscreen: initialWindowMode === "fullscreen",
2058
+ kiosk: false,
1994
2059
  resizable: initialWindowMode === "windowed",
1995
2060
  minimizable: initialWindowMode === "windowed",
1996
2061
  maximizable: initialWindowMode === "windowed",
@@ -2008,8 +2073,14 @@ function startKeyScreenMain(options) {
2008
2073
  mainWindow.setMenuBarVisibility(false);
2009
2074
  }
2010
2075
  mainWindow.on("ready-to-show", () => {
2011
- applyCurrentWindowMode();
2012
- mainWindow?.show();
2076
+ if (currentWindowMode === "kiosk") {
2077
+ mainWindow?.show();
2078
+ applyCurrentWindowMode();
2079
+ } else {
2080
+ applyCurrentWindowMode();
2081
+ mainWindow?.show();
2082
+ }
2083
+ logWindowState("ready-to-show");
2013
2084
  scheduleKioskWindowModeEnforcement();
2014
2085
  });
2015
2086
  mainWindow.on("close", (event) => {
@@ -2018,7 +2089,7 @@ function startKeyScreenMain(options) {
2018
2089
  }
2019
2090
  });
2020
2091
  mainWindow.webContents.on("before-input-event", (event, input) => {
2021
- if (!isDev && isReloadShortcut(input)) {
2092
+ if (!isDev && (isReloadShortcut(input) || isBlockedFunctionKey(input))) {
2022
2093
  event.preventDefault();
2023
2094
  return;
2024
2095
  }
@@ -2107,8 +2178,16 @@ function startKeyScreenMain(options) {
2107
2178
  });
2108
2179
  createWindow();
2109
2180
  syncWindowsKeyLockToWindowMode();
2181
+ const handleDisplayChange = (reason) => () => {
2182
+ logWindowState(reason);
2183
+ scheduleKioskWindowModeEnforcement();
2184
+ };
2185
+ screen.on("display-added", handleDisplayChange("display-added"));
2186
+ screen.on("display-removed", handleDisplayChange("display-removed"));
2187
+ screen.on("display-metrics-changed", handleDisplayChange("display-metrics-changed"));
2110
2188
  arduinoCliRunner = new ArduinoCliRunner(resolveArduinoCliPaths(app));
2111
2189
  arduinoCliRunner.on("log", (entry) => {
2190
+ log.info(`[arduino:${entry.stream}]`, entry.line);
2112
2191
  broadcastArduinoLog(entry);
2113
2192
  });
2114
2193
  const deviceLogWriter = new DeviceLogWriter(app.getPath("logs"), {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "key-screen-framework",
3
- "version": "1.5.0",
3
+ "version": "1.5.1",
4
4
  "description": "Screen framework for Keyescape desktop projects.",
5
5
  "repository": {
6
6
  "type": "git",
@@ -1,4 +1,5 @@
1
1
  import type { Input } from 'electron';
2
2
  type Platform = NodeJS.Platform;
3
3
  export declare function isReloadShortcut(input: Input, platform?: Platform): boolean;
4
+ export declare function isBlockedFunctionKey(input: Pick<Input, 'key' | 'alt'>): boolean;
4
5
  export {};
@@ -8,7 +8,9 @@ export type WindowBounds = {
8
8
  };
9
9
  export type ApplyWindowModeOptions = {
10
10
  kioskBounds?: WindowBounds;
11
+ forceKioskReentry?: boolean;
11
12
  };
13
+ export declare function isWindowCoveringDisplay(windowBounds: WindowBounds, displayBounds: WindowBounds): boolean;
12
14
  export declare function getEnvWindowModeOverride(env: NodeJS.ProcessEnv): WindowMode | undefined;
13
15
  export declare function resolveInitialWindowMode(options: {
14
16
  env: NodeJS.ProcessEnv;