fix(launcher): use per-profile timing overrides

This commit is contained in:
Scott Idem
2026-05-13 12:48:43 -04:00
parent 4923099cfb
commit 39749c608a
7 changed files with 258 additions and 117 deletions

View File

@@ -5,11 +5,11 @@
* replacement for the legacy OSIT MasterKey Swift app.
*
* These are the last-resort defaults. Override priority (high → low):
* 1. event_file.cfg_json.display_override — per-file, display_mode only
* 2. event_device.data_json.launch_profiles[ext] — full profile, per device (API)
* 3. $events_loc.launcher.launch_profiles[ext] — local persistent override
* 4. DEFAULT_LAUNCH_PROFILES[ext] — extension aliases to canonical built-ins
* 5. DEFAULT_LAUNCH_PROFILES['default'] — catch-all
* 1. event_file.cfg_json.display_override — per-file, display_mode only
* 2. event_device.data_json.launch_profiles[profile] — per-profile override, per device (API)
* 3. $events_loc.launcher.launch_profiles[profile] — local persistent override
* 4. DEFAULT_LAUNCH_PROFILES[profile/alias] — canonical built-ins + aliases
* 5. DEFAULT_LAUNCH_PROFILES['default'] — catch-all
*
* Keys are lowercase file extensions without the dot: "pptx", "key", "pdf", etc.
* The special key "default" catches any unrecognised extension.
@@ -43,7 +43,7 @@ export interface LaunchProfile {
post_script?: string;
/**
* Milliseconds to wait after open_cmd before running post_script.
* Default: 2000. Can be overridden per device via other_json.launcher.post_delay_ms.
* Default: 2000. Can be overridden per profile via launch_profiles[profile].post_delay_ms.
*/
post_delay_ms?: number;
@@ -266,22 +266,33 @@ export const DEFAULT_LAUNCH_PROFILES: Record<string, LaunchProfile> = Object.fro
export function resolve_launch_profile(
extension: string,
display_override?: 'extend' | 'mirror' | 'none' | null,
device_profiles?: Record<string, LaunchProfile> | null,
local_profiles?: Record<string, LaunchProfile> | null
device_profiles?: Record<string, Partial<LaunchProfile>> | null,
local_profiles?: Record<string, Partial<LaunchProfile>> | null
): LaunchProfile {
const ext = (extension || '').toLowerCase().replace(/^\./, '');
const default_profile_name = DEFAULT_LAUNCH_PROFILE_ALIASES[ext] ?? ext;
const canonical_profile_name = DEFAULT_LAUNCH_PROFILE_ALIASES[ext] ?? ext;
// Priority: device config → local config → canonical built-ins → default
const source =
device_profiles?.[ext] ??
device_profiles?.['default'] ??
local_profiles?.[ext] ??
local_profiles?.['default'] ??
DEFAULT_LAUNCH_PROFILES[default_profile_name] ??
const built_in_profile =
DEFAULT_LAUNCH_PROFILE_LIBRARY[canonical_profile_name] ??
DEFAULT_LAUNCH_PROFILE_LIBRARY.os_default;
const profile = { ...source };
const local_profile =
local_profiles?.[canonical_profile_name] ??
local_profiles?.[ext] ??
local_profiles?.['default'] ??
null;
const device_profile =
device_profiles?.[canonical_profile_name] ??
device_profiles?.[ext] ??
device_profiles?.['default'] ??
null;
const profile = {
...built_in_profile,
...(local_profile ?? {}),
...(device_profile ?? {})
};
// Per-file display override wins over everything
if (display_override) {

View File

@@ -80,7 +80,7 @@ export async function launch_from_cache({
* - AppleScript: multi-line string with {{path}} placeholder (macOS only)
* - Shell command: prefix with "shell:" → e.g. "shell:open \"{{path}}\""
*
* Configure via event_device.data_json.launch_profiles or $events_loc.launcher.launch_profiles.
* Configure via per-profile launch_profiles overrides in event_device.data_json or $events_loc.launcher.
* If null, Electron should treat that as a missing profile error.
*/
native_template?: string | null;