Rename UTM-Dolphin.js to legacy.js and drop screenshot demos

This commit is contained in:
CelloSerenity 2026-07-25 16:39:08 -06:00
parent 2047bcbe85
commit 03b7c109ac
5 changed files with 21 additions and 72 deletions

View file

@ -201,21 +201,7 @@ struct ScriptListView: View {
// MARK: - File Ops // MARK: - File Ops
private func scriptsDirectory() throws -> URL { private func scriptsDirectory() throws -> URL {
let directory = try ScriptStore.prepareDirectory() 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)
}
} }
private func loadScripts() { 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();
"""

View file

@ -36,7 +36,7 @@ extension ScriptStore {
"Flycast", "Flycast",
"ARMSX2 iOS" "ARMSX2 iOS"
], ],
resource: ScriptResource(resourceName: "UTM-Dolphin", fileName: "UTM-Dolphin.js") resource: ScriptResource(resourceName: "legacy", fileName: "legacy.js")
), ),
AutoScriptAssignment( AutoScriptAssignment(
appNames: [ appNames: [

View file

@ -20,7 +20,7 @@ enum ScriptStore {
ScriptResource(resourceName: "maciOS", fileName: "maciOS.js"), ScriptResource(resourceName: "maciOS", fileName: "maciOS.js"),
ScriptResource(resourceName: "universal", fileName: "universal.js"), ScriptResource(resourceName: "universal", fileName: "universal.js"),
ScriptResource(resourceName: "Geode", fileName: "Geode.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 { static var directoryURL: URL {
@ -54,6 +54,16 @@ enum ScriptStore {
return directory.appendingPathComponent(scriptName) 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? { static func assignedScriptName(for bundleID: String, defaults: UserDefaults = .standard) -> String? {
assignedScriptMap(defaults: defaults)[bundleID] assignedScriptMap(defaults: defaults)[bundleID]
} }

View file

@ -175,6 +175,14 @@ struct HomeView: View {
} }
if let scriptName = queryValue(["script-name", "scriptName", "script_name"], in: components) { if let scriptName = queryValue(["script-name", "scriptName", "script_name"], in: components) {
config.scriptName = scriptName 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, if config.scriptData == nil, let bundleID = config.bundleID,
let scriptInfo = ScriptStore.preferredScript(for: bundleID) { let scriptInfo = ScriptStore.preferredScript(for: bundleID) {