From 03b7c109ac2767d7558e88c621924fbf9b18ad74 Mon Sep 17 00:00:00 2001 From: CelloSerenity <195480169+CelloSerenity@users.noreply.github.com> Date: Sat, 25 Jul 2026 16:39:08 -0600 Subject: [PATCH] Rename UTM-Dolphin.js to legacy.js and drop screenshot demos --- StikDebug/JSSupport/ScriptListView.swift | 71 +------------------ .../Scripts/{UTM-Dolphin.js => legacy.js} | 0 StikDebug/Support/AutoScriptAssignments.swift | 2 +- StikDebug/Support/ScriptStore.swift | 12 +++- StikDebug/Views/HomeView.swift | 8 +++ 5 files changed, 21 insertions(+), 72 deletions(-) rename StikDebug/Scripts/{UTM-Dolphin.js => legacy.js} (100%) diff --git a/StikDebug/JSSupport/ScriptListView.swift b/StikDebug/JSSupport/ScriptListView.swift index 0f0d8ae..ac5b596 100644 --- a/StikDebug/JSSupport/ScriptListView.swift +++ b/StikDebug/JSSupport/ScriptListView.swift @@ -201,21 +201,7 @@ struct ScriptListView: View { // MARK: - File Ops private func scriptsDirectory() throws -> URL { - let directory = try ScriptStore.prepareDirectory() - try ensureEditorScripts(in: directory) - return directory - } - - private func ensureEditorScripts(in directory: URL) throws { - let fm = FileManager.default - let screenshotURL = directory.appendingPathComponent("screenshot-demo.js") - if !fm.fileExists(atPath: screenshotURL.path) { - try screenshotDemoScript.write(to: screenshotURL, atomically: true, encoding: .utf8) - } - let standaloneURL = directory.appendingPathComponent("screenshot-capture.js") - if !fm.fileExists(atPath: standaloneURL.path) { - try screenshotCaptureScript.write(to: standaloneURL, atomically: true, encoding: .utf8) - } + try ScriptStore.prepareDirectory() } private func loadScripts() { @@ -331,58 +317,3 @@ struct ScriptListView: View { } } } - -// MARK: - Script content stubs - -private let screenshotDemoScript = """ -// Screenshot Demo Script -// Attaches to the target, captures a PNG screenshot, and detaches. - -function takeScreenshotDemo() { - log("[ScreenshotDemo] Starting demo"); - - const pid = get_pid(); - log(`[ScreenshotDemo] Target PID: ${pid}`); - - const attachResponse = send_command(`vAttach;${pid.toString(16)}`); - log(`[ScreenshotDemo] attach_response = ${attachResponse}`); - - const timestamp = new Date().toISOString().replace(/[:.]/g, "-"); - const fileName = `screenshot-${timestamp}.png`; - const savedPath = take_screenshot(fileName); - - if (savedPath && savedPath.length > 0) { - log(`[ScreenshotDemo] Screenshot saved to ${savedPath}`); - } else { - log("[ScreenshotDemo] Device did not report a saved path."); - } - - const detachResponse = send_command("D"); - log(`[ScreenshotDemo] detach_response = ${detachResponse}`); - log("[ScreenshotDemo] Demo complete."); -} - -takeScreenshotDemo(); -""" - -private let screenshotCaptureScript = """ -// Screenshot Capture Script -// Takes a screenshot without sending any debugserver commands. - -function captureScreenshot() { - log("[ScreenshotCapture] Requesting screenshot without attaching…"); - const timestamp = new Date().toISOString().replace(/[:.]/g, "-"); - const fileName = `standalone-${timestamp}.png`; - const savedPath = take_screenshot(fileName); - - if (savedPath && savedPath.length > 0) { - log(`[ScreenshotCapture] Screenshot saved to ${savedPath}`); - } else { - log("[ScreenshotCapture] Device did not report a saved path."); - } - - log("[ScreenshotCapture] Done."); -} - -captureScreenshot(); -""" diff --git a/StikDebug/Scripts/UTM-Dolphin.js b/StikDebug/Scripts/legacy.js similarity index 100% rename from StikDebug/Scripts/UTM-Dolphin.js rename to StikDebug/Scripts/legacy.js diff --git a/StikDebug/Support/AutoScriptAssignments.swift b/StikDebug/Support/AutoScriptAssignments.swift index 6457e41..2b90954 100644 --- a/StikDebug/Support/AutoScriptAssignments.swift +++ b/StikDebug/Support/AutoScriptAssignments.swift @@ -36,7 +36,7 @@ extension ScriptStore { "Flycast", "ARMSX2 iOS" ], - resource: ScriptResource(resourceName: "UTM-Dolphin", fileName: "UTM-Dolphin.js") + resource: ScriptResource(resourceName: "legacy", fileName: "legacy.js") ), AutoScriptAssignment( appNames: [ diff --git a/StikDebug/Support/ScriptStore.swift b/StikDebug/Support/ScriptStore.swift index 0e609a3..1dc18d8 100644 --- a/StikDebug/Support/ScriptStore.swift +++ b/StikDebug/Support/ScriptStore.swift @@ -20,7 +20,7 @@ enum ScriptStore { ScriptResource(resourceName: "maciOS", fileName: "maciOS.js"), ScriptResource(resourceName: "universal", fileName: "universal.js"), ScriptResource(resourceName: "Geode", fileName: "Geode.js"), - ScriptResource(resourceName: "UTM-Dolphin", fileName: "UTM-Dolphin.js") + ScriptResource(resourceName: "legacy", fileName: "legacy.js") ] static var directoryURL: URL { @@ -54,6 +54,16 @@ enum ScriptStore { return directory.appendingPathComponent(scriptName) } + static func script(named scriptName: String, fileManager: FileManager = .default) -> (data: Data, name: String)? { + guard let normalizedName = normalizedScriptFileName(scriptName), + let scriptURL = try? scriptURL(named: normalizedName, fileManager: fileManager), + let data = try? Data(contentsOf: scriptURL) else { + return nil + } + + return (data, normalizedName) + } + static func assignedScriptName(for bundleID: String, defaults: UserDefaults = .standard) -> String? { assignedScriptMap(defaults: defaults)[bundleID] } diff --git a/StikDebug/Views/HomeView.swift b/StikDebug/Views/HomeView.swift index d9a592b..a7b1b54 100644 --- a/StikDebug/Views/HomeView.swift +++ b/StikDebug/Views/HomeView.swift @@ -175,6 +175,14 @@ struct HomeView: View { } if let scriptName = queryValue(["script-name", "scriptName", "script_name"], in: components) { config.scriptName = scriptName + if config.scriptData == nil { + if let namedScript = ScriptStore.script(named: scriptName) { + config.scriptData = namedScript.data + config.scriptName = namedScript.name + } else { + LogManager.shared.addWarningLog("Script \(scriptName) was not found in the scripts folder") + } + } } if config.scriptData == nil, let bundleID = config.bundleID, let scriptInfo = ScriptStore.preferredScript(for: bundleID) {