mirror of
https://github.com/kiwix/kiwix-apple.git
synced 2025-09-08 03:34:13 -04:00
Revert to a single solution, no settings
This commit is contained in:
parent
27b7e464e5
commit
c8f1943559
@ -167,21 +167,6 @@ struct Kiwix: App {
|
|||||||
window.identifier?.rawValue == "donation"
|
window.identifier?.rawValue == "donation"
|
||||||
}?.close()
|
}?.close()
|
||||||
}
|
}
|
||||||
|
|
||||||
private class NotificationCenterDelegate: NSObject, UNUserNotificationCenterDelegate {
|
|
||||||
/// Handling file download complete notification
|
|
||||||
func userNotificationCenter(_ center: UNUserNotificationCenter,
|
|
||||||
didReceive response: UNNotificationResponse,
|
|
||||||
withCompletionHandler completionHandler: @escaping () -> Void) {
|
|
||||||
Task {
|
|
||||||
if let zimFileID = UUID(uuidString: response.notification.request.identifier),
|
|
||||||
let mainPageURL = await ZimFileService.shared.getMainPageURL(zimFileID: zimFileID) {
|
|
||||||
NSWorkspace.shared.open(mainPageURL)
|
|
||||||
}
|
|
||||||
await MainActor.run { completionHandler() }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
struct RootView: View {
|
struct RootView: View {
|
||||||
@ -196,7 +181,6 @@ struct RootView: View {
|
|||||||
// Open file alerts
|
// Open file alerts
|
||||||
@State private var isOpenFileAlertPresented = false
|
@State private var isOpenFileAlertPresented = false
|
||||||
@State private var openFileAlert: OpenFileAlert?
|
@State private var openFileAlert: OpenFileAlert?
|
||||||
@Default(.externalEventTabOpenPolicy) private var externalEventTabOpenPolicy
|
|
||||||
|
|
||||||
private let primaryItems: [MenuItem] = [.bookmarks]
|
private let primaryItems: [MenuItem] = [.bookmarks]
|
||||||
private let libraryItems: [MenuItem] = [.opened, .categories, .downloads, .new]
|
private let libraryItems: [MenuItem] = [.opened, .categories, .downloads, .new]
|
||||||
@ -207,6 +191,8 @@ struct RootView: View {
|
|||||||
private let goForwardPublisher = NotificationCenter.default.publisher(for: .goForward)
|
private let goForwardPublisher = NotificationCenter.default.publisher(for: .goForward)
|
||||||
/// Close other tabs then the ones received
|
/// Close other tabs then the ones received
|
||||||
private let keepOnlyTabs = NotificationCenter.default.publisher(for: .keepOnlyTabs)
|
private let keepOnlyTabs = NotificationCenter.default.publisher(for: .keepOnlyTabs)
|
||||||
|
// in essence it's the "zim://" value
|
||||||
|
private static let zimURL: String = "\(KiwixURLSchemeHandler.ZIMScheme)://"
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
NavigationSplitView {
|
NavigationSplitView {
|
||||||
@ -274,21 +260,23 @@ struct RootView: View {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
.onOpenURL { url in
|
.onOpenURL { url in
|
||||||
|
/// if the app was just started via URL or file (wasn't open before)
|
||||||
|
/// we want to load the content in the first window
|
||||||
|
/// otherwise in a new tab (but within the currently active window)
|
||||||
|
let isAppStart = NSApplication.shared.windows.count == 1
|
||||||
if url.isFileURL {
|
if url.isFileURL {
|
||||||
// from opening an external file
|
// from opening an external file
|
||||||
let browser = BrowserViewModel.getCached(tabID: navigation.currentTabId)
|
let browser = BrowserViewModel.getCached(tabID: navigation.currentTabId)
|
||||||
if externalEventTabOpenPolicy == .openInNewDetachedWindow {
|
if isAppStart {
|
||||||
browser.forceLoadingState() // we are already in the new window, show loading immediately
|
browser.forceLoadingState()
|
||||||
}
|
}
|
||||||
|
|
||||||
Task { // open the ZIM file
|
Task { // open the ZIM file
|
||||||
if let metadata = await LibraryOperations.open(url: url),
|
if let metadata = await LibraryOperations.open(url: url),
|
||||||
let mainPageURL = await ZimFileService.shared.getMainPageURL(zimFileID: metadata.fileID) {
|
let mainPageURL = await ZimFileService.shared.getMainPageURL(zimFileID: metadata.fileID) {
|
||||||
switch externalEventTabOpenPolicy {
|
if isAppStart {
|
||||||
case .openInNewTabSameWindow:
|
|
||||||
browser.createNewWindow(with: mainPageURL)
|
|
||||||
case .openInNewDetachedWindow:
|
|
||||||
browser.load(url: mainPageURL)
|
browser.load(url: mainPageURL)
|
||||||
|
} else {
|
||||||
|
browser.createNewWindow(with: mainPageURL)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
await browser.clear()
|
await browser.clear()
|
||||||
@ -298,8 +286,10 @@ struct RootView: View {
|
|||||||
}
|
}
|
||||||
} else if url.isZIMURL {
|
} else if url.isZIMURL {
|
||||||
// from deeplinks
|
// from deeplinks
|
||||||
switch externalEventTabOpenPolicy {
|
if isAppStart {
|
||||||
case .openInNewTabSameWindow:
|
let browser = BrowserViewModel.getCached(tabID: navigation.currentTabId)
|
||||||
|
browser.load(url: url)
|
||||||
|
} else {
|
||||||
Task { @MainActor in
|
Task { @MainActor in
|
||||||
// we want to open the deeplink a new tab (in the currently active window)
|
// we want to open the deeplink a new tab (in the currently active window)
|
||||||
// at this point though, the latest tab is active, that received the deeplink handling
|
// at this point though, the latest tab is active, that received the deeplink handling
|
||||||
@ -309,11 +299,6 @@ struct RootView: View {
|
|||||||
let browser = BrowserViewModel.getCached(tabID: navigation.currentTabId)
|
let browser = BrowserViewModel.getCached(tabID: navigation.currentTabId)
|
||||||
browser.createNewWindow(with: url)
|
browser.createNewWindow(with: url)
|
||||||
}
|
}
|
||||||
case .openInNewDetachedWindow:
|
|
||||||
// in this case the system created a new detached window / single tab
|
|
||||||
// that is currently active
|
|
||||||
let browser = BrowserViewModel.getCached(tabID: navigation.currentTabId)
|
|
||||||
browser.load(url: url)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -404,7 +389,10 @@ struct RootView: View {
|
|||||||
.withHostingWindow { [weak windowTracker] hostWindow in
|
.withHostingWindow { [weak windowTracker] hostWindow in
|
||||||
windowTracker?.current = hostWindow
|
windowTracker?.current = hostWindow
|
||||||
}
|
}
|
||||||
.modifier(ExternalEventHandler(openInSameWindow: externalEventTabOpenPolicy == .openInNewTabSameWindow))
|
.handlesExternalEvents(
|
||||||
|
preferring: Set([Self.zimURL]),
|
||||||
|
allowing: Set([Self.zimURL, "file:///"])
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -13,4 +13,23 @@
|
|||||||
// You should have received a copy of the GNU General Public License
|
// You should have received a copy of the GNU General Public License
|
||||||
// along with Kiwix; If not, see https://www.gnu.org/licenses/.
|
// along with Kiwix; If not, see https://www.gnu.org/licenses/.
|
||||||
|
|
||||||
|
#if os(macOS)
|
||||||
import Foundation
|
import Foundation
|
||||||
|
import UserNotifications
|
||||||
|
import AppKit
|
||||||
|
|
||||||
|
final class NotificationCenterDelegate: NSObject, UNUserNotificationCenterDelegate {
|
||||||
|
/// Handling file download complete notification
|
||||||
|
func userNotificationCenter(_ center: UNUserNotificationCenter,
|
||||||
|
didReceive response: UNNotificationResponse,
|
||||||
|
withCompletionHandler completionHandler: @escaping () -> Void) {
|
||||||
|
Task {
|
||||||
|
if let zimFileID = UUID(uuidString: response.notification.request.identifier),
|
||||||
|
let mainPageURL = await ZimFileService.shared.getMainPageURL(zimFileID: zimFileID) {
|
||||||
|
NSWorkspace.shared.open(mainPageURL)
|
||||||
|
}
|
||||||
|
await MainActor.run { completionHandler() }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
@ -159,7 +159,6 @@
|
|||||||
"reading_settings.zoom.title" = "Page zoom";
|
"reading_settings.zoom.title" = "Page zoom";
|
||||||
"reading_settings.zoom.reset.button" = "Reset";
|
"reading_settings.zoom.reset.button" = "Reset";
|
||||||
"reading_settings.external_link.title" = "External Link";
|
"reading_settings.external_link.title" = "External Link";
|
||||||
"reading_settings.external_events_tab_opening.title" = "URLs and files should";
|
|
||||||
"reading_settings.search_snippet.title" = "Search snippet";
|
"reading_settings.search_snippet.title" = "Search snippet";
|
||||||
"reading_settings.tab.reading" = "Reading";
|
"reading_settings.tab.reading" = "Reading";
|
||||||
"library_settings.catalog.title" = "Catalog";
|
"library_settings.catalog.title" = "Catalog";
|
||||||
@ -256,8 +255,6 @@
|
|||||||
"enum.external_link_loading_policy.always_ask" = "Always Ask";
|
"enum.external_link_loading_policy.always_ask" = "Always Ask";
|
||||||
"enum.external_link_loading_policy.always_load" = "Always Load";
|
"enum.external_link_loading_policy.always_load" = "Always Load";
|
||||||
"enum.external_link_loading_policy.never_load" = "Never Load";
|
"enum.external_link_loading_policy.never_load" = "Never Load";
|
||||||
"enum.external_event.open_in_new_tab_same_window" = "Open in a new tab in the active window";
|
|
||||||
"enum.external_event.open_new_detached_window" = "Open in a new detached window";
|
|
||||||
"enum.flavor.max" = "max";
|
"enum.flavor.max" = "max";
|
||||||
"enum.flavor.no_pic" = "no pic";
|
"enum.flavor.no_pic" = "no pic";
|
||||||
"enum.flavor.mini" = "mini";
|
"enum.flavor.mini" = "mini";
|
||||||
|
@ -124,7 +124,6 @@
|
|||||||
"reading_settings.zoom.title" = "Label title for a percentage selector in app settings, eg: 100%";
|
"reading_settings.zoom.title" = "Label title for a percentage selector in app settings, eg: 100%";
|
||||||
"reading_settings.zoom.reset.button" = "Button title for percentage selector for zoom level in app settings";
|
"reading_settings.zoom.reset.button" = "Button title for percentage selector for zoom level in app settings";
|
||||||
"reading_settings.external_link.title" = "Label title for option picker. External Link: Always Ask | Always Load | Never Load";
|
"reading_settings.external_link.title" = "Label title for option picker. External Link: Always Ask | Always Load | Never Load";
|
||||||
"reading_settings.external_events_tab_opening.title" = "Label title for option picker. URLs and files should: Open in a new tab in the active window | Open in a new detached window";
|
|
||||||
"reading_settings.search_snippet.title" = "Label title for option picker. Search snippet: Disabled | First Paragraph | First Sentence | Matches";
|
"reading_settings.search_snippet.title" = "Label title for option picker. Search snippet: Disabled | First Paragraph | First Sentence | Matches";
|
||||||
"reading_settings.tab.reading" = "Settings page tab title";
|
"reading_settings.tab.reading" = "Settings page tab title";
|
||||||
"library_settings.catalog.title" = "In settings: Label next to button Catalog: [Refresh] Last Refresh: 30 minutes ago";
|
"library_settings.catalog.title" = "In settings: Label next to button Catalog: [Refresh] Last Refresh: 30 minutes ago";
|
||||||
@ -212,8 +211,6 @@
|
|||||||
"enum.external_link_loading_policy.always_ask" = "Settings picker option title: how external links should be treated";
|
"enum.external_link_loading_policy.always_ask" = "Settings picker option title: how external links should be treated";
|
||||||
"enum.external_link_loading_policy.always_load" = "Settings picker option title: how external links should be treated";
|
"enum.external_link_loading_policy.always_load" = "Settings picker option title: how external links should be treated";
|
||||||
"enum.external_link_loading_policy.never_load" = "Settings picker option title: how external links should be treated";
|
"enum.external_link_loading_policy.never_load" = "Settings picker option title: how external links should be treated";
|
||||||
"enum.external_event.open_in_new_tab_same_window" = "Settings picker option title: how to handle zim urls, and files opened in Finder: they should be opened in a new tab attached to the currently active window";
|
|
||||||
"enum.external_event.open_new_detached_window" = "Settings picker option title: how to handle zim urls, and files opened in Finder: they should be opened in a new detached window on top of the currently running application window";
|
|
||||||
"enum.flavor.max" = "short, abreviated label displayed in the corner of zim file cards, describing the flavour of the file. The shorter the better.";
|
"enum.flavor.max" = "short, abreviated label displayed in the corner of zim file cards, describing the flavour of the file. The shorter the better.";
|
||||||
"enum.flavor.no_pic" = "short, abreviated label displayed in the corner of zim file cards, describing the flavour of the file. The shorter the better.";
|
"enum.flavor.no_pic" = "short, abreviated label displayed in the corner of zim file cards, describing the flavour of the file. The shorter the better.";
|
||||||
"enum.flavor.mini" = "short, abreviated label displayed in the corner of zim file cards, describing the flavour of the file. The shorter the better.";
|
"enum.flavor.mini" = "short, abreviated label displayed in the corner of zim file cards, describing the flavour of the file. The shorter the better.";
|
||||||
|
@ -23,9 +23,6 @@ extension Defaults.Keys {
|
|||||||
static let externalLinkLoadingPolicy = Key<ExternalLinkLoadingPolicy>(
|
static let externalLinkLoadingPolicy = Key<ExternalLinkLoadingPolicy>(
|
||||||
"externalLinkLoadingPolicy", default: Brand.defaultExternalLinkPolicy
|
"externalLinkLoadingPolicy", default: Brand.defaultExternalLinkPolicy
|
||||||
)
|
)
|
||||||
static let externalEventTabOpenPolicy = Key<ExternalEventOpeningPolicy>(
|
|
||||||
"ExternalEventOpeningPolicy", default: .openInNewTabSameWindow
|
|
||||||
)
|
|
||||||
static let searchResultSnippetMode = Key<SearchResultSnippetMode>(
|
static let searchResultSnippetMode = Key<SearchResultSnippetMode>(
|
||||||
"searchResultSnippetMode", default: Brand.defaultSearchSnippetMode
|
"searchResultSnippetMode", default: Brand.defaultSearchSnippetMode
|
||||||
)
|
)
|
||||||
|
@ -138,21 +138,6 @@ enum ExternalLinkLoadingPolicy: String, CaseIterable, Identifiable, Defaults.Ser
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
enum ExternalEventOpeningPolicy: String, CaseIterable, Identifiable, Defaults.Serializable {
|
|
||||||
var id: String { self.rawValue }
|
|
||||||
case openInNewTabSameWindow
|
|
||||||
case openInNewDetachedWindow
|
|
||||||
|
|
||||||
var name: String {
|
|
||||||
switch self {
|
|
||||||
case .openInNewTabSameWindow:
|
|
||||||
return LocalString.enum_external_event_open_in_new_tab_same_window
|
|
||||||
case .openInNewDetachedWindow:
|
|
||||||
return LocalString.enum_external_event_open_new_detached_window
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
enum OpenURLContext {
|
enum OpenURLContext {
|
||||||
case deepLink(id: UUID?)
|
case deepLink(id: UUID?)
|
||||||
}
|
}
|
||||||
|
@ -22,7 +22,6 @@ struct ReadingSettings: View {
|
|||||||
@Default(.externalLinkLoadingPolicy) private var externalLinkLoadingPolicy
|
@Default(.externalLinkLoadingPolicy) private var externalLinkLoadingPolicy
|
||||||
@Default(.searchResultSnippetMode) private var searchResultSnippetMode
|
@Default(.searchResultSnippetMode) private var searchResultSnippetMode
|
||||||
@Default(.webViewPageZoom) private var webViewPageZoom
|
@Default(.webViewPageZoom) private var webViewPageZoom
|
||||||
@Default(.externalEventTabOpenPolicy) private var externalEventTabOpenPolicy
|
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
let isSnippet = Binding {
|
let isSnippet = Binding {
|
||||||
@ -52,16 +51,6 @@ struct ReadingSettings: View {
|
|||||||
} label: { }
|
} label: { }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if !AppType.isCustom {
|
|
||||||
SettingSection(name: LocalString.reading_settings_external_events_tab_opening_title) {
|
|
||||||
Picker(selection: $externalEventTabOpenPolicy) {
|
|
||||||
ForEach(ExternalEventOpeningPolicy.allCases) { policy in
|
|
||||||
Text(policy.name).tag(policy)
|
|
||||||
}
|
|
||||||
} label: { }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if FeatureFlags.showSearchSnippetInSettings {
|
if FeatureFlags.showSearchSnippetInSettings {
|
||||||
SettingSection(name: LocalString.reading_settings_search_snippet_title) {
|
SettingSection(name: LocalString.reading_settings_search_snippet_title) {
|
||||||
Toggle(" ", isOn: isSnippet)
|
Toggle(" ", isOn: isSnippet)
|
||||||
|
@ -1,38 +0,0 @@
|
|||||||
// This file is part of Kiwix for iOS & macOS.
|
|
||||||
//
|
|
||||||
// Kiwix is free software; you can redistribute it and/or modify it
|
|
||||||
// under the terms of the GNU General Public License as published by
|
|
||||||
// the Free Software Foundation; either version 3 of the License, or
|
|
||||||
// any later version.
|
|
||||||
//
|
|
||||||
// Kiwix is distributed in the hope that it will be useful, but
|
|
||||||
// WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
||||||
// General Public License for more details.
|
|
||||||
//
|
|
||||||
// You should have received a copy of the GNU General Public License
|
|
||||||
// along with Kiwix; If not, see https://www.gnu.org/licenses/.
|
|
||||||
|
|
||||||
#if os(macOS)
|
|
||||||
import SwiftUI
|
|
||||||
|
|
||||||
struct ExternalEventHandler: ViewModifier {
|
|
||||||
|
|
||||||
let openInSameWindow: Bool
|
|
||||||
|
|
||||||
// in essence it's the "zim://" value
|
|
||||||
static private let zimURL: String = "\(KiwixURLSchemeHandler.ZIMScheme)://"
|
|
||||||
|
|
||||||
func body(content: Content) -> some View {
|
|
||||||
if openInSameWindow {
|
|
||||||
content.handlesExternalEvents(
|
|
||||||
preferring: Set([Self.zimURL]),
|
|
||||||
allowing: Set([Self.zimURL, "file:///"])
|
|
||||||
)
|
|
||||||
} else {
|
|
||||||
content
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
#endif
|
|
Loading…
x
Reference in New Issue
Block a user