Skip to content

Commit

Permalink
Merge pull request #719 from kiwix/gpl3-headers
Browse files Browse the repository at this point in the history
GPLv3 compliant headers
  • Loading branch information
kelson42 authored Apr 6, 2024
2 parents 596815c + ec98aae commit 7e88d7d
Show file tree
Hide file tree
Showing 97 changed files with 1,569 additions and 779 deletions.
13 changes: 13 additions & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Automactic <[email protected]>
BPH <[email protected]>
rgaudin <[email protected]>
Kelson <[email protected]>
translatewiki.net <[email protected]>
tvision251 <[email protected]>
Alistair Findlay <[email protected]>
codnee <[email protected]>
Denis Gladkikh <[email protected]>
Ernesto Cedeno <[email protected]>
Julian Harty <[email protected]>
quocduyvu6262 <[email protected]>
Valentin Vila <[email protected]>
28 changes: 18 additions & 10 deletions App/App_iOS.swift
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
// App_iOS.swift
// Kiwix
// This file is part of Kiwix for iOS & macOS.
//
// Created by Chris Li on 7/27/23.
// Copyright © 2023 Chris Li. All rights reserved.
// 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/.

import SwiftUI
import UserNotifications
Expand All @@ -15,15 +23,15 @@ struct Kiwix: App {
@StateObject private var library = LibraryViewModel()
@StateObject private var navigation = NavigationViewModel()
@UIApplicationDelegateAdaptor(AppDelegate.self) private var appDelegate

private let fileMonitor: DirectoryMonitor

init() {
fileMonitor = DirectoryMonitor(url: URL.documentDirectory) { LibraryOperations.scanDirectory($0) }
LibraryOperations.registerBackgroundTask()
UNUserNotificationCenter.current().delegate = appDelegate
}

var body: some Scene {
WindowGroup {
RootView()
Expand Down Expand Up @@ -74,7 +82,7 @@ struct Kiwix: App {
}
}
}

private class AppDelegate: NSObject, UIApplicationDelegate, UNUserNotificationCenterDelegate {
/// Storing background download completion handler sent to application delegate
func application(_ application: UIApplication,
Expand All @@ -93,7 +101,7 @@ struct Kiwix: App {
}
completionHandler()
}

/// Purge some cached browser view models when receiving memory warning
func applicationDidReceiveMemoryWarning(_ application: UIApplication) {
BrowserViewModel.purgeCache()
Expand All @@ -103,11 +111,11 @@ struct Kiwix: App {

private struct RootView: UIViewControllerRepresentable {
@EnvironmentObject private var navigation: NavigationViewModel

func makeUIViewController(context: Context) -> SplitViewController {
SplitViewController(navigationViewModel: navigation)
}

func updateUIViewController(_ controller: SplitViewController, context: Context) {
}
}
Expand Down
19 changes: 13 additions & 6 deletions App/App_macOS.swift
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
// This file is part of Kiwix for iOS & macOS.
//
// App_macOS.swift
// Kiwix
// 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.
//
// Created by Chris Li on 8/13/23.
// Copyright © 2023 Chris Li. All rights reserved.
// 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/.

import SwiftUI
import UserNotifications
Expand All @@ -28,7 +35,7 @@ struct Kiwix: App {
init() {
UNUserNotificationCenter.current().delegate = notificationCenterDelegate
}

var body: some Scene {
WindowGroup {
RootView()
Expand Down Expand Up @@ -89,7 +96,7 @@ struct RootView: View {
@Environment(\.controlActiveState) var controlActiveState
@StateObject private var browser = BrowserViewModel()
@StateObject private var navigation = NavigationViewModel()

private let primaryItems: [NavigationItem] = [.reading, .bookmarks]
private let libraryItems: [NavigationItem] = [.opened, .categories, .downloads, .new]
private let openURL = NotificationCenter.default.publisher(for: .openURL)
Expand Down
15 changes: 15 additions & 0 deletions App/CompactViewController.swift
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
// 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/.

//
// CompactViewController.swift
// Kiwix
Expand Down
55 changes: 31 additions & 24 deletions App/SidebarViewController.swift
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
// This file is part of Kiwix for iOS & macOS.
//
// SidebarViewController.swift
// Kiwix
// 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.
//
// Created by Chris Li on 9/4/23.
// Copyright © 2023 Chris Li. All rights reserved.
// 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(iOS)
import CoreData
Expand Down Expand Up @@ -37,7 +44,7 @@ class SidebarViewController: UICollectionViewController, NSFetchedResultsControl
sectionNameKeyPath: nil,
cacheName: nil
)

enum Section: String, CaseIterable {
case primary
case tabs
Expand All @@ -52,7 +59,7 @@ class SidebarViewController: UICollectionViewController, NSFetchedResultsControl
}
}
}

init() {
super.init(collectionViewLayout: UICollectionViewLayout())
collectionView.collectionViewLayout = UICollectionViewCompositionalLayout { sectionIndex, layoutEnvironment in
Expand All @@ -65,25 +72,25 @@ class SidebarViewController: UICollectionViewController, NSFetchedResultsControl
return section
}
}

required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}

func updateSelection() {
guard let splitViewController = splitViewController as? SplitViewController,
let currentItem = splitViewController.navigationViewModel.currentItem,
let indexPath = dataSource.indexPath(for: currentItem),
collectionView.indexPathsForSelectedItems?.first != indexPath else { return }
collectionView.selectItem(at: indexPath, animated: true, scrollPosition: [])
}

// MARK: - Lifecycle

override func viewDidLoad() {
super.viewDidLoad()
fetchedResultController.delegate = self

// configure view
navigationItem.title = Brand.appName
navigationItem.rightBarButtonItem = UIBarButtonItem(
Expand Down Expand Up @@ -112,7 +119,7 @@ class SidebarViewController: UICollectionViewController, NSFetchedResultsControl
}
])
)

// apply initial snapshot
var snapshot = NSDiffableDataSourceSnapshot<Section, NavigationItem>()
snapshot.appendSections(Section.allSections)
Expand All @@ -124,19 +131,19 @@ class SidebarViewController: UICollectionViewController, NSFetchedResultsControl
dataSource.apply(snapshot, animatingDifferences: false)
try? fetchedResultController.performFetch()
}

override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
navigationController?.navigationBar.prefersLargeTitles = true
}

override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
updateSelection()
}

// MARK: - Delegations

nonisolated func controller(
_ controller: NSFetchedResultsController<NSFetchRequestResult>,
didChangeContentWith snapshot: NSDiffableDataSourceSnapshotReference
Expand Down Expand Up @@ -165,7 +172,7 @@ class SidebarViewController: UICollectionViewController, NSFetchedResultsControl
}
}
}

override func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
guard let splitViewController = splitViewController as? SplitViewController,
let navigationItem = dataSource.itemIdentifier(for: indexPath) else { return }
Expand All @@ -174,13 +181,13 @@ class SidebarViewController: UICollectionViewController, NSFetchedResultsControl
splitViewController.hide(.primary)
}
}

override func collectionView(_ collectionView: UICollectionView, canFocusItemAt indexPath: IndexPath) -> Bool {
return false
}

// MARK: - Collection View Configuration

private func configureCell(cell: UICollectionViewListCell, indexPath: IndexPath, item: NavigationItem) {
if case let .tab(objectID) = item, let tab = try? Database.viewContext.existingObject(with: objectID) as? Tab {
if #available(iOS 16.0, *) {
Expand All @@ -200,9 +207,9 @@ class SidebarViewController: UICollectionViewController, NSFetchedResultsControl
config.image = UIImage(systemName: item.icon)
cell.contentConfiguration = config
}

}

private func configureHeader(headerView: UICollectionViewListCell, elementKind: String, indexPath: IndexPath) {
let section = Section.allSections[indexPath.section]
switch section {
Expand All @@ -218,12 +225,12 @@ class SidebarViewController: UICollectionViewController, NSFetchedResultsControl
headerView.contentConfiguration = nil
}
}

private func configureSwipeAction(indexPath: IndexPath) -> UISwipeActionsConfiguration? {
guard let splitViewController = splitViewController as? SplitViewController,
let item = dataSource.itemIdentifier(for: indexPath),
case let .tab(tabID) = item else { return nil }
let action = UIContextualAction(style: .destructive,
let action = UIContextualAction(style: .destructive,
title: "sidebar_view.navigation.button.close".localized) { _, _, _ in
splitViewController.navigationViewModel.deleteTab(tabID: tabID)
}
Expand Down
33 changes: 20 additions & 13 deletions App/SplitViewController.swift
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
// This file is part of Kiwix for iOS & macOS.
//
// SplitViewController.swift
// Kiwix
// 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.
//
// Created by Chris Li on 9/4/23.
// Copyright © 2023 Chris Li. All rights reserved.
// 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(iOS)
import Combine
Expand All @@ -16,28 +23,28 @@ final class SplitViewController: UISplitViewController {
private var navigationItemObserver: AnyCancellable?
private var openURLObserver: NSObjectProtocol?
private var toggleSidebarObserver: NSObjectProtocol?

init(navigationViewModel: NavigationViewModel) {
self.navigationViewModel = navigationViewModel
super.init(style: .doubleColumn)
}

required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}

deinit {
NotificationCenter.default.removeObserver(self)
}

// MARK: - Lifecycle

override func viewDidLoad() {
super.viewDidLoad()
if #available(iOS 16.0, *) {} else {
presentsWithGesture = false
}

// setup controllers
setViewController(UINavigationController(rootViewController: CompactViewController()), for: .compact)
setViewController(SidebarViewController(), for: .primary)
Expand Down Expand Up @@ -79,15 +86,15 @@ final class SplitViewController: UISplitViewController {
}
}
}

/// Dismiss any controller that is already presented when horizontal size class is about to change
override func willTransition(to newCollection: UITraitCollection,
with coordinator: UIViewControllerTransitionCoordinator) {
super.willTransition(to: newCollection, with: coordinator)
guard newCollection.horizontalSizeClass != traitCollection.horizontalSizeClass else { return }
presentedViewController?.dismiss(animated: false)
}

override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) {
super.traitCollectionDidChange(previousTraitCollection)
guard previousTraitCollection?.horizontalSizeClass != traitCollection.horizontalSizeClass else { return }
Expand All @@ -97,7 +104,7 @@ final class SplitViewController: UISplitViewController {
setSecondaryController()
}
}

private func setSecondaryController() {
switch navigationViewModel.currentItem {
case .bookmarks:
Expand Down
Loading

0 comments on commit 7e88d7d

Please sign in to comment.