Skip to content

Commit

Permalink
refactor: various miscellaneous optimizations
Browse files Browse the repository at this point in the history
  • Loading branch information
ACTCD committed Sep 29, 2024
1 parent 3c961e5 commit 4e1f5fb
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 21 deletions.
15 changes: 4 additions & 11 deletions src/app/App.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,8 @@
let directory = "init";
window.APP = {
show: () => {},
printVersion: (v, b) => {
version = v;
build = b;
},
printDirectory: (d) => {
directory = d;
},
window.webapp = {
updateDirectory: (newDir) => (directory = newDir),
};
async function initialize() {
Expand All @@ -25,11 +18,11 @@
}
function changeDirectory() {
window.webkit?.messageHandlers.controller.postMessage("CHANGE_DIRECTORY");
webkit.postMessage("CHANGE_DIRECTORY");
}
function openDirectory() {
window.webkit?.messageHandlers.controller.postMessage("OPEN_DIRECTORY");
webkit.postMessage("OPEN_DIRECTORY");
}
</script>

Expand Down
20 changes: 11 additions & 9 deletions src/app/global.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,25 @@

declare global {
interface Window {
APP: {
show: (
platform: "ios" | "mac",
enabled: boolean,
useSettingsInsteadOfPreferences: boolean,
) => void;
printVersion: (v: string, b: string) => void;
printDirectory: (d: string) => void;
webapp: {
updateDirectory: (directory: string) => void;
};
webkit: {
messageHandlers: {
controller: {
postMessage: function;
postMessage: <T extends MessageBody>(
message: T,
) => Promise<MessageReply<T>>;
};
};
};
}
}

type MessageBody = "INIT" | "CHANGE_DIRECTORY" | "OPEN_DIRECTORY";

type MessageReply<T> = T extends "INIT"
? { build: string; version: string; directory: string }
: void;

export {};
2 changes: 1 addition & 1 deletion xcode/App-Shared/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,6 @@ class ViewController: UIViewController, WKNavigationDelegate, WKScriptMessageHan

func documentPicker(_ controller: UIDocumentPickerViewController, didPickDocumentAt url: URL) {
Preferences.scriptsDirectoryUrl = url
webView.evaluateJavaScript("APP.printDirectory('\(getCurrentScriptsDirectoryString())')")
webView.evaluateJavaScript("webapp.updateDirectory('\(getCurrentScriptsDirectoryString())')")
}
}

0 comments on commit 4e1f5fb

Please sign in to comment.