Skip to content

Commit

Permalink
Merge pull request #766 from quoid/fix/ios-initialization
Browse files Browse the repository at this point in the history
fix(ios): make default directory initialization work again
  • Loading branch information
ACTCD authored Jan 4, 2025
2 parents 26dbb09 + e6c920d commit 652e4c6
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
8 changes: 6 additions & 2 deletions xcode/App-Shared/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,10 @@ class ViewController: PlatformViewController, WKNavigationDelegate, WKScriptMess
func updateEnableLoggerState() {
self.webView.evaluateJavaScript("webapp.switchLogger(\(Preferences.enableLogger),\(Preferences.promptLogger))")
}

func updateCurrentDirectory() {
self.webView.evaluateJavaScript("webapp.updateDirectory('\(getCurrentScriptsDirectoryString())')")
}

#if os(macOS)
deinit {
Expand Down Expand Up @@ -268,7 +272,7 @@ extension ViewController: UIDocumentPickerDelegate {

func changeSaveLocationHandler(_ url: URL) {
Preferences.scriptsDirectoryUrl = url
webView.evaluateJavaScript("webapp.updateDirectory('\(getCurrentScriptsDirectoryString())')")
self.updateCurrentDirectory()
}

func exportLogFiles() {
Expand Down Expand Up @@ -367,7 +371,7 @@ extension ViewController {
// try set new save location path to bookmark
guard setSaveLocationURL(url: url) else { return }
// update user interface text display
self.webView.evaluateJavaScript("webapp.updateDirectory('\(getCurrentScriptsDirectoryString())')")
self.updateCurrentDirectory()
// notify browser extension of relevant updates
sendExtensionMessage(
name: "SAVE_LOCATION_CHANGED",
Expand Down
9 changes: 5 additions & 4 deletions xcode/Shared/Preferences.swift
Original file line number Diff line number Diff line change
Expand Up @@ -252,11 +252,12 @@ private struct SecurityScopedBookmark {
set(url) {
let k = key // key cannot be log directly with error: Escaping autoclosure captures mutating 'self' parameter
logger?.info("\(#function, privacy: .public) - try set bookmark: \(k, privacy: .public) \(url, privacy: .public)")
guard url.startAccessingSecurityScopedResource() else {
logger?.error("\(#function, privacy: .public) - failed access url: \(url, privacy: .public)")
return
// true - when url from UIDocumentPicker
// false - when set default app document
let didStartAccessing = url.startAccessingSecurityScopedResource()
defer {
if didStartAccessing { url.stopAccessingSecurityScopedResource() }
}
defer { url.stopAccessingSecurityScopedResource() }
guard let data = createBookmark(url) else {
logger?.info("\(#function, privacy: .public) - failed create bookmark: \(k, privacy: .public) \(url, privacy: .public)")
return
Expand Down

0 comments on commit 652e4c6

Please sign in to comment.