From 01fe39afda9688d71ea0a6b4c1cd5ee48ab7e340 Mon Sep 17 00:00:00 2001 From: automactic Date: Mon, 16 May 2016 00:42:04 -0400 Subject: [PATCH] Global Queue Refactor --- Kiwix.xcodeproj/project.pbxproj | 8 -------- Kiwix/AppDelegate.swift | 13 +++++++------ Kiwix/AppDelegateObjs.swift | 25 ------------------------- Kiwix/LanguageTBVC.swift | 5 ++--- Kiwix/LibraryLocalTBVC.swift | 2 +- Kiwix/LibraryOnlineTBVC.swift | 4 ++-- Kiwix/LibraryScanOperation.swift | 13 ------------- Kiwix/MainVC.swift | 2 +- Kiwix/UIOperations.swift | 2 +- Kiwix/ZimMultiReader.swift | 2 +- 10 files changed, 15 insertions(+), 61 deletions(-) delete mode 100644 Kiwix/AppDelegateObjs.swift delete mode 100644 Kiwix/LibraryScanOperation.swift diff --git a/Kiwix.xcodeproj/project.pbxproj b/Kiwix.xcodeproj/project.pbxproj index f3280984..698705e0 100644 --- a/Kiwix.xcodeproj/project.pbxproj +++ b/Kiwix.xcodeproj/project.pbxproj @@ -83,7 +83,6 @@ 978C58A21C1CFD850077AE47 /* Reachability.swift in Sources */ = {isa = PBXBuildFile; fileRef = 978C58A11C1CFD850077AE47 /* Reachability.swift */; }; 978C58AD1C1CFF700077AE47 /* PreferenceLibrary.swift in Sources */ = {isa = PBXBuildFile; fileRef = 978C58AC1C1CFF700077AE47 /* PreferenceLibrary.swift */; }; 978C58AF1C1CFFE30077AE47 /* SwiftyUserDefaults.swift in Sources */ = {isa = PBXBuildFile; fileRef = 978C58AE1C1CFFE30077AE47 /* SwiftyUserDefaults.swift */; }; - 978C58B11C1E02970077AE47 /* AppDelegateObjs.swift in Sources */ = {isa = PBXBuildFile; fileRef = 978C58B01C1E02970077AE47 /* AppDelegateObjs.swift */; }; 97999D891C52D27D003CAFF3 /* SearchBar.swift in Sources */ = {isa = PBXBuildFile; fileRef = 97999D881C52D27D003CAFF3 /* SearchBar.swift */; }; 97A2AB8C1C1B80FF00052E74 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 97A2AB8B1C1B80FF00052E74 /* AppDelegate.swift */; }; 97A2AB941C1B80FF00052E74 /* Kiwix.xcdatamodeld in Sources */ = {isa = PBXBuildFile; fileRef = 97A2AB921C1B80FF00052E74 /* Kiwix.xcdatamodeld */; }; @@ -104,7 +103,6 @@ 97CCC4E81C1F0D970041DAEE /* BarButtonItems.swift in Sources */ = {isa = PBXBuildFile; fileRef = 97CCC4E71C1F0D970041DAEE /* BarButtonItems.swift */; }; 97DA06C71CB6DA3400EBA609 /* LibraryLocalBookDetailTBVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = 97DA06C61CB6DA3400EBA609 /* LibraryLocalBookDetailTBVC.swift */; }; 97DF23551CE807A1003E1E5A /* GlobalOperationQueue.swift in Sources */ = {isa = PBXBuildFile; fileRef = 97DF23541CE807A1003E1E5A /* GlobalOperationQueue.swift */; }; - 97DF23571CE8083C003E1E5A /* LibraryScanOperation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 97DF23561CE8083C003E1E5A /* LibraryScanOperation.swift */; }; 97E067241C52980F0079C13C /* MainVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = 97E067231C52980F0079C13C /* MainVC.swift */; }; 97E067261C52AA000079C13C /* MainVCWebViewD.swift in Sources */ = {isa = PBXBuildFile; fileRef = 97E067251C52AA000079C13C /* MainVCWebViewD.swift */; }; 97E067281C52AC360079C13C /* MainVCOtherD.swift in Sources */ = {isa = PBXBuildFile; fileRef = 97E067271C52AC360079C13C /* MainVCOtherD.swift */; }; @@ -266,7 +264,6 @@ 978C58A11C1CFD850077AE47 /* Reachability.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Reachability.swift; sourceTree = ""; }; 978C58AC1C1CFF700077AE47 /* PreferenceLibrary.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PreferenceLibrary.swift; sourceTree = ""; }; 978C58AE1C1CFFE30077AE47 /* SwiftyUserDefaults.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SwiftyUserDefaults.swift; sourceTree = ""; }; - 978C58B01C1E02970077AE47 /* AppDelegateObjs.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AppDelegateObjs.swift; sourceTree = ""; }; 97999D881C52D27D003CAFF3 /* SearchBar.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SearchBar.swift; sourceTree = ""; }; 97A2AB881C1B80FF00052E74 /* Kiwix.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Kiwix.app; sourceTree = BUILT_PRODUCTS_DIR; }; 97A2AB8B1C1B80FF00052E74 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; lineEnding = 0; path = AppDelegate.swift; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.swift; }; @@ -292,7 +289,6 @@ 97CCC4E71C1F0D970041DAEE /* BarButtonItems.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BarButtonItems.swift; sourceTree = ""; }; 97DA06C61CB6DA3400EBA609 /* LibraryLocalBookDetailTBVC.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LibraryLocalBookDetailTBVC.swift; sourceTree = ""; }; 97DF23541CE807A1003E1E5A /* GlobalOperationQueue.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = GlobalOperationQueue.swift; sourceTree = ""; }; - 97DF23561CE8083C003E1E5A /* LibraryScanOperation.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LibraryScanOperation.swift; sourceTree = ""; }; 97E067231C52980F0079C13C /* MainVC.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MainVC.swift; sourceTree = ""; }; 97E067251C52AA000079C13C /* MainVCWebViewD.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MainVCWebViewD.swift; sourceTree = ""; }; 97E067271C52AC360079C13C /* MainVCOtherD.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MainVCOtherD.swift; sourceTree = ""; }; @@ -696,7 +692,6 @@ isa = PBXGroup; children = ( 97A2AB8B1C1B80FF00052E74 /* AppDelegate.swift */, - 978C58B01C1E02970077AE47 /* AppDelegateObjs.swift */, 978C587A1C1CCC9C0077AE47 /* Storyboards */, 978C58821C1CCDAF0077AE47 /* Controllers */, 977998821C1E2A5C00B1DD5E /* View */, @@ -830,7 +825,6 @@ 970103F91C6824FA00DC48F6 /* RefreshLibraryOperation.swift */, 97B50C7E1CA1E4810010BD79 /* UIOperations.swift */, 973970EC1CB9A04C00350507 /* SearchOperation.swift */, - 97DF23561CE8083C003E1E5A /* LibraryScanOperation.swift */, ); name = Operation; sourceTree = ""; @@ -1147,7 +1141,6 @@ 9714D8D71C6E5C2600AABCA7 /* LTBarButtonItem.swift in Sources */, 97E571221CA0500400FF4F1D /* ReachabilityCondition.swift in Sources */, 97E570FE1CA0500400FF4F1D /* BlockOperation.swift in Sources */, - 97DF23571CE8083C003E1E5A /* LibraryScanOperation.swift in Sources */, 973381631C331D660016CEFB /* ArticleCells.swift in Sources */, 97E571211CA0500400FF4F1D /* PushCapability-OSX.swift in Sources */, 97E571241CA0500400FF4F1D /* SilentCondition.swift in Sources */, @@ -1167,7 +1160,6 @@ 97A7140A1C274FCB00951244 /* DirectoryMonitor.swift in Sources */, 978C58841C1CCE4D0077AE47 /* LanguageTBVC.swift in Sources */, 97E571071CA0500400FF4F1D /* GroupOperation.swift in Sources */, - 978C58B11C1E02970077AE47 /* AppDelegateObjs.swift in Sources */, 97E5711E1CA0500400FF4F1D /* PhotosCapability.swift in Sources */, 97E5711C1CA0500400FF4F1D /* PassbookCapability.swift in Sources */, 97E5710D1CA0500400FF4F1D /* LocationCapability-OSX.swift in Sources */, diff --git a/Kiwix/AppDelegate.swift b/Kiwix/AppDelegate.swift index f4956437..b95e130c 100644 --- a/Kiwix/AppDelegate.swift +++ b/Kiwix/AppDelegate.swift @@ -12,15 +12,10 @@ import CoreData class AppDelegate: UIResponder, UIApplicationDelegate, OperationQueueDelegate { var window: UIWindow? - let globalOperationQueue = OperationQueue() func recordActiveSession() { Preference.activeUseHistory.append(NSDate()) } - - func operationQueue(operationQueue: OperationQueue, operationDidFinish operation: NSOperation, withErrors errors: [NSError]) { - print(globalOperationQueue.operationCount) - } func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { NSURLProtocol.registerClass(KiwixURLProtocol) @@ -40,8 +35,14 @@ class AppDelegate: UIResponder, UIApplicationDelegate, OperationQueueDelegate { func applicationWillResignActive(application: UIApplication) { // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game. - UIApplication.updateApplicationIconBadgeNumber() +// UIApplication.updateApplicationIconBadgeNumber() } + + // class func updateApplicationIconBadgeNumber() { + // guard let settings = UIApplication.sharedApplication().currentUserNotificationSettings() else {return} + // guard settings.types.contains(UIUserNotificationType.Badge) else {return} + // //UIApplication.sharedApplication().applicationIconBadgeNumber = downloader.taskCount ?? 0 + // } func applicationDidEnterBackground(application: UIApplication) { // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. diff --git a/Kiwix/AppDelegateObjs.swift b/Kiwix/AppDelegateObjs.swift deleted file mode 100644 index 15cdbebe..00000000 --- a/Kiwix/AppDelegateObjs.swift +++ /dev/null @@ -1,25 +0,0 @@ -// -// AppDelegateObjs.swift -// Kiwix -// -// Created by Chris on 12/13/15. -// Copyright © 2015 Chris. All rights reserved. -// - -import UIKit - -extension UIApplication { - - // MARK: - Class Accessor - - class var globalOperationQueue: OperationQueue { - get {return appDelegate.globalOperationQueue} - } - - class func updateApplicationIconBadgeNumber() { - guard let settings = UIApplication.sharedApplication().currentUserNotificationSettings() else {return} - guard settings.types.contains(UIUserNotificationType.Badge) else {return} - //UIApplication.sharedApplication().applicationIconBadgeNumber = downloader.taskCount ?? 0 - } -} - diff --git a/Kiwix/LanguageTBVC.swift b/Kiwix/LanguageTBVC.swift index aadc9a4d..536e03d0 100644 --- a/Kiwix/LanguageTBVC.swift +++ b/Kiwix/LanguageTBVC.swift @@ -59,8 +59,8 @@ class LanguageTBVC: UITableViewController, NSFetchedResultsControllerDelegate { } } - func sortByCountDesc(var languages: [Language]) -> [Language] { - languages.sortInPlace { (language1, language2) -> Bool in + func sortByCountDesc(languages: [Language]) -> [Language] { + return languages.sort { (language1, language2) -> Bool in guard let count1 = language1.books?.count else {return false} guard let count2 = language2.books?.count else {return false} if count1 == count2 { @@ -71,7 +71,6 @@ class LanguageTBVC: UITableViewController, NSFetchedResultsControllerDelegate { return count1 > count2 } } - return languages } // MARK: - Table view data source diff --git a/Kiwix/LibraryLocalTBVC.swift b/Kiwix/LibraryLocalTBVC.swift index a9e304d7..eb6d6cb2 100644 --- a/Kiwix/LibraryLocalTBVC.swift +++ b/Kiwix/LibraryLocalTBVC.swift @@ -112,7 +112,7 @@ class LibraryLocalTBVC: UITableViewController, NSFetchedResultsControllerDelegat func emptyDataSetDidTapButton(scrollView: UIScrollView!) { let operation = ShowHelpPageOperation(type: .ImportBookLearnMore, presentationContext: self) - UIApplication.appDelegate.globalOperationQueue.addOperation(operation) + GlobalOperationQueue.sharedInstance.addOperation(operation) } // MARK: - TableView Data Source diff --git a/Kiwix/LibraryOnlineTBVC.swift b/Kiwix/LibraryOnlineTBVC.swift index fedca70f..4d0f7373 100644 --- a/Kiwix/LibraryOnlineTBVC.swift +++ b/Kiwix/LibraryOnlineTBVC.swift @@ -89,12 +89,12 @@ class LibraryOnlineTBVC: UITableViewController, NSFetchedResultsControllerDelega let codes = errors.map() {$0.code} if codes.contains(OperationErrorCode.NetworkError.rawValue) { let alertOperation = RefreshLibraryInternetRequiredAlert(presentationContext: self) - UIApplication.appDelegate.globalOperationQueue.addOperation(alertOperation) + GlobalOperationQueue.sharedInstance.addOperation(alertOperation) } } else { guard !Preference.libraryHasShownPreferredLanguagePrompt else {return} let operation = RefreshLibraryLanguageFilterAlert(libraryOnlineTBVC: self) - UIApplication.appDelegate.globalOperationQueue.addOperation(operation) + GlobalOperationQueue.sharedInstance.addOperation(operation) } } diff --git a/Kiwix/LibraryScanOperation.swift b/Kiwix/LibraryScanOperation.swift deleted file mode 100644 index 122e79fc..00000000 --- a/Kiwix/LibraryScanOperation.swift +++ /dev/null @@ -1,13 +0,0 @@ -// -// LibraryScanOperation.swift -// Kiwix -// -// Created by Chris Li on 5/14/16. -// Copyright © 2016 Chris. All rights reserved. -// - -import UIKit - -class LibraryScanOperation: Operation { - -} diff --git a/Kiwix/MainVC.swift b/Kiwix/MainVC.swift index df219dbe..a460db54 100644 --- a/Kiwix/MainVC.swift +++ b/Kiwix/MainVC.swift @@ -69,7 +69,7 @@ class MainVC: UIViewController { func showGetStartedAlert() { guard !Preference.hasShowGetStartedAlert else {return} let operation = GetStartedAlert(mainController: self) - UIApplication.appDelegate.globalOperationQueue.addOperation(operation) + GlobalOperationQueue.sharedInstance.addOperation(operation) Preference.hasShowGetStartedAlert = true } diff --git a/Kiwix/UIOperations.swift b/Kiwix/UIOperations.swift index 4d5ae90b..ff74edb5 100644 --- a/Kiwix/UIOperations.swift +++ b/Kiwix/UIOperations.swift @@ -119,7 +119,7 @@ class GetStartedAlert: AlertOperation { } addAction(NSLocalizedString("Import", comment: comment), style: .Default) { (alert) in let operation = ShowHelpPageOperation(type: .ImportBookLearnMore, presentationContext: mainController) - UIApplication.appDelegate.globalOperationQueue.addOperation(operation) + GlobalOperationQueue.sharedInstance.addOperation(operation) } addAction(NSLocalizedString("Dismiss", comment: comment)) } diff --git a/Kiwix/ZimMultiReader.swift b/Kiwix/ZimMultiReader.swift index ee7a86b2..8de251f9 100644 --- a/Kiwix/ZimMultiReader.swift +++ b/Kiwix/ZimMultiReader.swift @@ -34,7 +34,7 @@ class ZIMMultiReader: NSObject, DirectoryMonitorDelegate { func directoryMonitorDidObserveChange() { let operation = RescanZimMultiReaderOperation() - UIApplication.globalOperationQueue.addOperation(operation) + GlobalOperationQueue.sharedInstance.addOperation(operation) } // MARK: - Refresh