Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(ios): make default directory initialization work again #766

Merged
merged 2 commits into from
Jan 4, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading