Skip to content

Commit

Permalink
Clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
BPerlakiH authored and kelson42 committed Nov 1, 2024
1 parent 36247d1 commit f85839d
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 38 deletions.
22 changes: 8 additions & 14 deletions App/App_macOS.swift
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,10 @@ struct RootView: View {
var body: some View {
NavigationSplitView {
List(selection: $navigation.currentItem) {
ForEach([NavigationItem.tab(objectID: navigation.currentTabId)] + primaryItems, id: \.self) { navigationItem in
ForEach(
[NavigationItem.tab(objectID: navigation.currentTabId)] + primaryItems,
id: \.self
) { navigationItem in
Label(navigationItem.name, systemImage: navigationItem.icon)
}
if FeatureFlags.hasLibrary {
Expand All @@ -132,15 +135,10 @@ struct RootView: View {
case .tab(let tabID):
let browser = BrowserViewModel.getCached(tabID: tabID)
BrowserTab().environmentObject(browser)
.withHostingWindow { [weak browser] window in
// if let windowNumber = window?.windowNumber {
// browser.restoreByWindowNumber(windowNumber: windowNumber,
// urlToTabIdConverter: navigation.tabIDFor(url:))
// } else {
if FeatureFlags.hasLibrary == false {
browser?.loadMainArticle()
}
// }
.withHostingWindow { [weak browser] _ in
if FeatureFlags.hasLibrary == false {
browser?.loadMainArticle()
}
}
case .bookmarks:
Bookmarks()
Expand Down Expand Up @@ -170,11 +168,7 @@ struct RootView: View {
}
}
.onReceive(openURL) { notification in
debugPrint("received openURL from: \(notification) for: \(navigation.uuid)")
guard let url = notification.userInfo?["url"] as? URL else {
// TODO: double check if we need a new solution based on tabID ?
// let navID = notification.userInfo?["navigationID"] as? UUID,
// navigation.uuid == navID else {
return
}
if notification.userInfo?["isFileContext"] as? Bool == true {
Expand Down
4 changes: 2 additions & 2 deletions App/SidebarViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class SidebarViewController: UICollectionViewController, NSFetchedResultsControl
collectionView, indexPath, item in
collectionView.dequeueConfiguredReusableCell(using: cellRegistration, for: indexPath, item: item)
}
dataSource.supplementaryViewProvider = { collectionView, elementKind, indexPath in
dataSource.supplementaryViewProvider = { collectionView, _, indexPath in
collectionView.dequeueConfiguredReusableSupplementary(using: headerRegistration, for: indexPath)
}
return dataSource
Expand Down Expand Up @@ -66,7 +66,7 @@ class SidebarViewController: UICollectionViewController, NSFetchedResultsControl

init() {
super.init(collectionViewLayout: UICollectionViewLayout())
collectionView.collectionViewLayout = UICollectionViewCompositionalLayout { sectionIndex, layoutEnvironment in
collectionView.collectionViewLayout = UICollectionViewCompositionalLayout { _, layoutEnvironment in
var config = UICollectionLayoutListConfiguration(appearance: .sidebar)
config.headerMode = .supplementary
config.trailingSwipeActionsConfigurationProvider = { [unowned self] indexPath in
Expand Down
8 changes: 4 additions & 4 deletions Model/Entities/Entities.swift
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ final class Tab: NSManagedObject, Identifiable {

@NSManaged var zimFile: ZimFile?

class func fetchRequest(
static func fetchRequest(
predicate: NSPredicate? = nil, sortDescriptors: [NSSortDescriptor] = []
) -> NSFetchRequest<Tab> {
// swiftlint:disable:next force_cast
Expand All @@ -139,7 +139,7 @@ final class Tab: NSManagedObject, Identifiable {
return request
}

class func fetchRequest(id: UUID) -> NSFetchRequest<Tab> {
static func fetchRequest(id: UUID) -> NSFetchRequest<Tab> {
// swiftlint:disable:next force_cast
let request = super.fetchRequest() as! NSFetchRequest<Tab>
request.predicate = NSPredicate(format: "id == %@", id as CVarArg)
Expand Down Expand Up @@ -265,7 +265,7 @@ final class ZimFile: NSManagedObject, Identifiable {
Predicate.notMissing
])

class func fetchRequest(
static func fetchRequest(
predicate: NSPredicate? = nil, sortDescriptors: [NSSortDescriptor] = []
) -> NSFetchRequest<ZimFile> {
// swiftlint:disable:next force_cast
Expand All @@ -275,7 +275,7 @@ final class ZimFile: NSManagedObject, Identifiable {
return request
}

class func fetchRequest(fileID: UUID) -> NSFetchRequest<ZimFile> {
static func fetchRequest(fileID: UUID) -> NSFetchRequest<ZimFile> {
// swiftlint:disable:next force_cast
let request = super.fetchRequest() as! NSFetchRequest<ZimFile>
request.predicate = NSPredicate(format: "fileID == %@", fileID as CVarArg)
Expand Down
7 changes: 2 additions & 5 deletions ViewModel/BrowserViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ final class BrowserViewModel: NSObject, ObservableObject,
@MainActor @Published private(set) var hasURL: Bool = false
@MainActor @Published private(set) var url: URL? {
didSet {
debugPrint("BrowserViewModel url: \(url?.absoluteString)")
if !FeatureFlags.hasLibrary, url == nil {
loadMainArticle()
}
Expand All @@ -88,7 +87,6 @@ final class BrowserViewModel: NSObject, ObservableObject,
@Published var externalURL: URL?
private var metaData: URLContentMetaData?


#if os(macOS)
private var windowURLs: [URL] {
UserDefaults.standard[.windowURLs]
Expand Down Expand Up @@ -188,7 +186,6 @@ final class BrowserViewModel: NSObject, ObservableObject,

@MainActor
func clear() async {
debugPrint("BrowserViewModel.clear()")
await webView.setAllMediaPlaybackSuspended(true)
await webView.closeAllMediaPresentations()
webView.stopLoading()
Expand Down Expand Up @@ -575,7 +572,7 @@ final class BrowserViewModel: NSObject, ObservableObject,
return WebViewController(webView: webView)
},
actionProvider: { [weak self] _ in
guard let self else { return UIMenu(children: []) }
guard let self = self else { return UIMenu(children: []) }
var actions = [UIAction]()

// open url
Expand All @@ -588,7 +585,7 @@ final class BrowserViewModel: NSObject, ObservableObject,
actions.append(
UIAction(title: "common.dialog.button.open_in_new_tab".localized,
image: UIImage(systemName: "doc.badge.plus")) { [weak self] _ in
guard let self else { return }
guard let self = self else { return }
NotificationCenter.openURL(url, inNewTab: true)
}
)
Expand Down
1 change: 0 additions & 1 deletion ViewModel/LaunchViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,6 @@ class LaunchViewModelBase: LaunchProtocol, ObservableObject {
var cancellables = Set<AnyCancellable>()

func updateTo(_ newState: LaunchSequence) {
debugPrint("LaunchViewModelBase updateTo: \(newState)")
guard newState != state else { return }
state = newState
}
Expand Down
7 changes: 1 addition & 6 deletions ViewModel/NavigationViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,7 @@ import WebKit
final class NavigationViewModel: ObservableObject {
let uuid = UUID()
// remained optional due to focusedSceneValue conformance
@Published var currentItem: NavigationItem? = .loading {
didSet {
debugPrint("NavigationViewModel.currentItem: \(currentItem)")
}
}
@Published var currentItem: NavigationItem? = .loading
#if os(macOS)
var isTerminating: Bool = false

Expand Down Expand Up @@ -161,7 +157,6 @@ final class NavigationViewModel: ObservableObject {
!tabIds.contains(currentId) else {
return
}
debugPrint("NavigationViewModel.keepOnlyTabsBy: \(tabIds)")
// setting it to nil ensures a new tab (and webview) will be created
// on accessing the public currentTabId
currentTabIdValue = nil
Expand Down
9 changes: 3 additions & 6 deletions Views/ViewModifiers/FileImport.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ import UniformTypeIdentifiers

/// Button that presents a file importer.
/// Note 1: Does not work on iOS / iPadOS via commands.
/// Note 2: Does not allow multiple selection, because we want a new tab to be opened with main page when file is opened,
/// Note 2: Does not allow multiple selection,
/// because we want a new tab to be opened with main page when file is opened,
/// and the multitab implementation on iOS / iPadOS does not support open multiple tabs with an url right now.
struct OpenFileButton<Label: View>: View {
@State private var isPresented: Bool = false
Expand Down Expand Up @@ -86,11 +87,7 @@ struct OpenFileHandler: ViewModifier {
NotificationCenter.openURL(url, inNewTab: true)
} else if .file == context {
// Note: inNewTab:true/false has no meaning here, the system will open a new window anyway
NotificationCenter.openURL(
url,
inNewTab: true,
isFileContext: true
)
NotificationCenter.openURL(url, inNewTab: true, isFileContext: true)
}
#elseif os(iOS)
NotificationCenter.openURL(url, inNewTab: true)
Expand Down

0 comments on commit f85839d

Please sign in to comment.