mirror of
https://github.com/kiwix/kiwix-apple.git
synced 2025-09-22 02:52:39 -04:00
Reduce open file cases
This commit is contained in:
parent
b2613c2ca8
commit
6199536717
@ -140,12 +140,14 @@ enum ExternalLinkLoadingPolicy: String, CaseIterable, Identifiable, Defaults.Ser
|
|||||||
|
|
||||||
enum OpenURLContext {
|
enum OpenURLContext {
|
||||||
case deepLink(id: UUID?)
|
case deepLink(id: UUID?)
|
||||||
case file
|
|
||||||
}
|
}
|
||||||
|
|
||||||
enum OpenFileContext {
|
enum OpenFileContext {
|
||||||
case command
|
#if os(iOS)
|
||||||
case file(deepLinkId: UUID? = nil)
|
case file(deepLinkId: UUID? = nil)
|
||||||
|
#else
|
||||||
|
case command
|
||||||
|
#endif
|
||||||
case welcomeScreen
|
case welcomeScreen
|
||||||
case library
|
case library
|
||||||
}
|
}
|
||||||
|
@ -77,39 +77,35 @@ struct OpenFileHandler: ViewModifier {
|
|||||||
invalidURLs.insert(url)
|
invalidURLs.insert(url)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// action for zim files that can be opened (e.g. open main page)
|
if case .library = context {
|
||||||
switch context {
|
// don't need to open the main page
|
||||||
case .command, .file:
|
} else {
|
||||||
for fileID in openedZimFileIDs {
|
for fileID in openedZimFileIDs {
|
||||||
guard let url = await ZimFileService.shared.getMainPageURL(zimFileID: fileID) else { return }
|
if let url = await ZimFileService.shared.getMainPageURL(zimFileID: fileID) {
|
||||||
#if os(macOS)
|
// action for zim files that can be opened (e.g. open main page)
|
||||||
switch context {
|
switch context {
|
||||||
case .command:
|
#if os(iOS)
|
||||||
NotificationCenter.openURL(url, inNewTab: true)
|
case .file(.none):
|
||||||
case .file:
|
NotificationCenter.openURL(url, inNewTab: true)
|
||||||
// Note: inNewTab:true/false has no meaning here, the system will open a new window anyway
|
case .file(.some(let deepLinkID)):
|
||||||
NotificationCenter.openURL(url, inNewTab: true, context: .file)
|
NotificationCenter.openURL(
|
||||||
default:
|
url,
|
||||||
break
|
inNewTab: true,
|
||||||
|
context: .deepLink(id: deepLinkID)
|
||||||
|
)
|
||||||
|
#else
|
||||||
|
case .command:
|
||||||
|
NotificationCenter.openURL(url, inNewTab: true)
|
||||||
|
#endif
|
||||||
|
case .welcomeScreen:
|
||||||
|
NotificationCenter.openURL(url)
|
||||||
|
case .library:
|
||||||
|
break
|
||||||
|
}
|
||||||
}
|
}
|
||||||
#elseif os(iOS)
|
|
||||||
if case .file(.some(let deepLinkID)) = context {
|
|
||||||
NotificationCenter.openURL(url, inNewTab: true, context: .deepLink(id: deepLinkID))
|
|
||||||
} else {
|
|
||||||
NotificationCenter.openURL(url, inNewTab: true)
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
case .welcomeScreen:
|
|
||||||
for fileID in openedZimFileIDs {
|
|
||||||
guard let url = await ZimFileService.shared.getMainPageURL(zimFileID: fileID) else { return }
|
|
||||||
NotificationCenter.openURL(url)
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
break
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// show alert if there are any files that cannot be opened
|
// show alert if there are any files that cannot be opened
|
||||||
if !invalidURLs.isEmpty {
|
if !invalidURLs.isEmpty {
|
||||||
isAlertPresented = true
|
isAlertPresented = true
|
||||||
|
Loading…
x
Reference in New Issue
Block a user