From c186d8fb1f2c5adcec9397d0d926e2ec2caec1d5 Mon Sep 17 00:00:00 2001 From: Guillaume Louel Date: Sat, 17 Nov 2018 18:32:10 +0100 Subject: [PATCH 1/5] WIP check now/reload files --- Aerial/App/Resources/Info.plist | 2 +- .../PreferencesWindowController.swift | 12 +++++++++++- Aerial/Source/Models/ManifestLoader.swift | 4 ++++ Resources/Info.plist | 4 ++-- Resources/PreferencesWindow.xib | 16 ++++++++++++++-- 5 files changed, 32 insertions(+), 6 deletions(-) diff --git a/Aerial/App/Resources/Info.plist b/Aerial/App/Resources/Info.plist index 74bdec92..5fd57064 100644 --- a/Aerial/App/Resources/Info.plist +++ b/Aerial/App/Resources/Info.plist @@ -17,7 +17,7 @@ CFBundlePackageType APPL CFBundleShortVersionString - 1.4.6beta1 + 1.4.6beta4 CFBundleSignature ???? CFBundleVersion diff --git a/Aerial/Source/Controllers/PreferencesWindowController.swift b/Aerial/Source/Controllers/PreferencesWindowController.swift index ad27cf52..72f2219e 100644 --- a/Aerial/Source/Controllers/PreferencesWindowController.swift +++ b/Aerial/Source/Controllers/PreferencesWindowController.swift @@ -181,7 +181,8 @@ final class PreferencesWindowController: NSWindowController, NSOutlineViewDataSo @IBOutlet var newVideosModePopup: NSPopUpButton! @IBOutlet var lastCheckedVideosLabel: NSTextField! - + @IBOutlet var checkNowButton: NSButton! + var player: AVPlayer = AVPlayer() var videos: [AerialVideo]? @@ -1051,6 +1052,11 @@ final class PreferencesWindowController: NSWindowController, NSOutlineViewDataSo preferences.newVideosMode = sender.indexOfSelectedItem } + @IBAction func checkNowButtonClick(_ sender: NSButton) { + checkNowButton.isEnabled = false + + } + // MARK: - Time panel @IBAction func overrideNightOnDarkModeClick(_ button: NSButton) { @@ -1488,6 +1494,10 @@ final class PreferencesWindowController: NSWindowController, NSOutlineViewDataSo self.loaded(manifestVideos: manifestVideos) } } + + func reloadJson() { + ManifestLoader.instance.reloadFiles() + } func loaded(manifestVideos: [AerialVideo]) { var videos = [AerialVideo]() diff --git a/Aerial/Source/Models/ManifestLoader.swift b/Aerial/Source/Models/ManifestLoader.swift index c6414637..56c85c41 100644 --- a/Aerial/Source/Models/ManifestLoader.swift +++ b/Aerial/Source/Models/ManifestLoader.swift @@ -293,6 +293,10 @@ class ManifestLoader { } } + func reloadFiles() { + + } + func addCallback(_ callback:@escaping ManifestLoadCallback) { if !loadedManifest.isEmpty { callback(loadedManifest) diff --git a/Resources/Info.plist b/Resources/Info.plist index 3a443bef..dc63ba39 100644 --- a/Resources/Info.plist +++ b/Resources/Info.plist @@ -15,11 +15,11 @@ CFBundlePackageType BNDL CFBundleShortVersionString - 1.4.6beta3 + 1.4.6beta4 CFBundleSignature ???? CFBundleVersion - 1.4.6beta3 + 1.4.6beta4 LSApplicationCategoryType LSMinimumSystemVersion diff --git a/Resources/PreferencesWindow.xib b/Resources/PreferencesWindow.xib index 3be80b47..0f181783 100644 --- a/Resources/PreferencesWindow.xib +++ b/Resources/PreferencesWindow.xib @@ -15,6 +15,7 @@ + @@ -137,7 +138,7 @@ - + @@ -1323,7 +1324,7 @@ Shift, but macOS 10.12.4 or above and a compatible Mac are required) - + @@ -1474,6 +1475,17 @@ Shift, but macOS 10.12.4 or above and a compatible Mac are required) + From e7221bd39c065cea09ccbac469ce4d315277acbc Mon Sep 17 00:00:00 2001 From: Guillaume Louel Date: Mon, 19 Nov 2018 14:07:47 +0100 Subject: [PATCH 2/5] Tentative fixes --- .../PreferencesWindowController.swift | 6 +- Aerial/Source/Models/Cache/VideoCache.swift | 13 ++++- Aerial/Source/Models/ErrorLog.swift | 58 ++++++++++--------- Aerial/Source/Models/ManifestLoader.swift | 2 +- Resources/Info.plist | 4 +- Resources/PreferencesWindow.xib | 4 +- 6 files changed, 52 insertions(+), 35 deletions(-) diff --git a/Aerial/Source/Controllers/PreferencesWindowController.swift b/Aerial/Source/Controllers/PreferencesWindowController.swift index 58437bca..5afe9a57 100644 --- a/Aerial/Source/Controllers/PreferencesWindowController.swift +++ b/Aerial/Source/Controllers/PreferencesWindowController.swift @@ -182,7 +182,7 @@ final class PreferencesWindowController: NSWindowController, NSOutlineViewDataSo @IBOutlet var lastCheckedVideosLabel: NSTextField! @IBOutlet var checkNowButton: NSButton! - + var player: AVPlayer = AVPlayer() var videos: [AerialVideo]? @@ -1058,7 +1058,7 @@ final class PreferencesWindowController: NSWindowController, NSOutlineViewDataSo @IBAction func checkNowButtonClick(_ sender: NSButton) { checkNowButton.isEnabled = false - + // TODO } // MARK: - Time panel @@ -1493,7 +1493,7 @@ final class PreferencesWindowController: NSWindowController, NSOutlineViewDataSo self.loaded(manifestVideos: manifestVideos) } } - + func reloadJson() { ManifestLoader.instance.reloadFiles() } diff --git a/Aerial/Source/Models/Cache/VideoCache.swift b/Aerial/Source/Models/Cache/VideoCache.swift index 214da43a..5145ce93 100644 --- a/Aerial/Source/Models/Cache/VideoCache.swift +++ b/Aerial/Source/Models/Cache/VideoCache.swift @@ -20,15 +20,21 @@ final class VideoCache { static var cacheDirectory: String? { var cacheDirectory: String? - let preferences = Preferences.sharedInstance + if let customCacheDirectory = preferences.customCacheDirectory { + //NSLog("AerialP: \(customCacheDirectory)") cacheDirectory = customCacheDirectory } else { let cachePaths = NSSearchPathForDirectoriesInDomains(.cachesDirectory, .userDomainMask, true) + + //NSLog("AerialP: cachePaths.count : \(cachePaths.count)") + //NSLog("AerialP: cachePaths \(cachePaths)") + if cachePaths.isEmpty { + //NSLog("AerialP: no cache paths") errorLog("Couldn't find cache paths!") return nil } @@ -39,6 +45,8 @@ final class VideoCache { cacheDirectory = defaultCacheDirectory } + //NSLog("AerialP: cd \(String(describing: cacheDirectory))") + guard let appCacheDirectory = cacheDirectory else { return nil } @@ -49,10 +57,13 @@ final class VideoCache { try fileManager.createDirectory(atPath: appCacheDirectory as String, withIntermediateDirectories: false, attributes: nil) } catch let error { + //NSLog("AerialP: couldn't create cache directory") errorLog("Couldn't create cache directory: \(error)") return nil } } + + //NSLog("AerialP: acd \(appCacheDirectory)") return appCacheDirectory } diff --git a/Aerial/Source/Models/ErrorLog.swift b/Aerial/Source/Models/ErrorLog.swift index 133c9407..fbc2fb53 100644 --- a/Aerial/Source/Models/ErrorLog.swift +++ b/Aerial/Source/Models/ErrorLog.swift @@ -72,34 +72,40 @@ func Log(level: ErrorLevel, message: String) { logger.callBack(level: level) } - // We may log to disk + // We may log to disk, asyncly if preferences.logToDisk { - let dateFormatter = DateFormatter() - dateFormatter.dateStyle = .none - dateFormatter.timeStyle = .medium - let string = dateFormatter.string(from: Date()) + " : " + message + "\n" - //let string = message + "\n" - if let cacheDirectory = VideoCache.cacheDirectory { - var cacheFileUrl = URL(fileURLWithPath: cacheDirectory as String) - cacheFileUrl.appendPathComponent("AerialLog.txt") - - let data = string.data(using: String.Encoding.utf8, allowLossyConversion: false)! - //let data = message.data(using: String.Encoding.utf8, allowLossyConversion: false)! - - if FileManager.default.fileExists(atPath: cacheFileUrl.path) { - do { - let fileHandle = try FileHandle(forWritingTo: cacheFileUrl) - fileHandle.seekToEndOfFile() - fileHandle.write(data) - fileHandle.closeFile() - } catch { - print("Can't open handle") + DispatchQueue.main.async { + let dateFormatter = DateFormatter() + dateFormatter.dateStyle = .none + dateFormatter.timeStyle = .medium + let string = dateFormatter.string(from: Date()) + " : " + message + "\n" + //let string = message + "\n" + if let cacheDirectory = VideoCache.cacheDirectory { + if VideoCache.cacheDirectory == nil { + NSLog("AerialError: No cache directory, this is super bad") } - } else { - do { - try data.write(to: cacheFileUrl, options: .atomic) - } catch { - print("Can't write to file") + + var cacheFileUrl = URL(fileURLWithPath: cacheDirectory as String) + cacheFileUrl.appendPathComponent("AerialLog.txt") + + let data = string.data(using: String.Encoding.utf8, allowLossyConversion: false)! + //let data = message.data(using: String.Encoding.utf8, allowLossyConversion: false)! + + if FileManager.default.fileExists(atPath: cacheFileUrl.path) { + do { + let fileHandle = try FileHandle(forWritingTo: cacheFileUrl) + fileHandle.seekToEndOfFile() + fileHandle.write(data) + fileHandle.closeFile() + } catch { + print("Can't open handle") + } + } else { + do { + try data.write(to: cacheFileUrl, options: .atomic) + } catch { + print("Can't write to file") + } } } } diff --git a/Aerial/Source/Models/ManifestLoader.swift b/Aerial/Source/Models/ManifestLoader.swift index 56c85c41..51bf2148 100644 --- a/Aerial/Source/Models/ManifestLoader.swift +++ b/Aerial/Source/Models/ManifestLoader.swift @@ -294,7 +294,7 @@ class ManifestLoader { } func reloadFiles() { - + // TODO } func addCallback(_ callback:@escaping ManifestLoadCallback) { diff --git a/Resources/Info.plist b/Resources/Info.plist index dc63ba39..12e877fc 100644 --- a/Resources/Info.plist +++ b/Resources/Info.plist @@ -15,11 +15,11 @@ CFBundlePackageType BNDL CFBundleShortVersionString - 1.4.6beta4 + 1.4.6test4a CFBundleSignature ???? CFBundleVersion - 1.4.6beta4 + 1.4.6test4a LSApplicationCategoryType LSMinimumSystemVersion diff --git a/Resources/PreferencesWindow.xib b/Resources/PreferencesWindow.xib index 0f181783..ba3e7b01 100644 --- a/Resources/PreferencesWindow.xib +++ b/Resources/PreferencesWindow.xib @@ -138,7 +138,7 @@ - + @@ -1324,7 +1324,7 @@ Shift, but macOS 10.12.4 or above and a compatible Mac are required) - + From e2f0452e52cda30f500b7613c3a1c13c789c5633 Mon Sep 17 00:00:00 2001 From: Guillaume Louel Date: Mon, 19 Nov 2018 14:33:07 +0100 Subject: [PATCH 3/5] Queue all videos in order --- .../PreferencesWindowController.swift | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/Aerial/Source/Controllers/PreferencesWindowController.swift b/Aerial/Source/Controllers/PreferencesWindowController.swift index 3aecb10b..cac84074 100644 --- a/Aerial/Source/Controllers/PreferencesWindowController.swift +++ b/Aerial/Source/Controllers/PreferencesWindowController.swift @@ -569,6 +569,9 @@ final class PreferencesWindowController: NSWindowController, NSOutlineViewDataSo } @IBAction func close(_ sender: AnyObject?) { + // This seems needed for screensavers as our lifecycle is different from a regular app + preferences.synchronize() + logPanel.close() if appMode { NSApplication.shared.terminate(nil) @@ -1469,10 +1472,16 @@ final class PreferencesWindowController: NSWindowController, NSOutlineViewDataSo return } let videoManager = VideoManager.sharedInstance - - for video in videos where !video.isAvailableOffline { - if !videoManager.isVideoQueued(id: video.id) { - videoManager.queueDownload(video) + for city in cities { + for video in city.day.videos where !video.isAvailableOffline { + if !videoManager.isVideoQueued(id: video.id) { + videoManager.queueDownload(video) + } + } + for video in city.night.videos where !video.isAvailableOffline { + if !videoManager.isVideoQueued(id: video.id) { + videoManager.queueDownload(video) + } } } } From ac626ffd9c0bced5fffb5e7749f19e7e25d428e3 Mon Sep 17 00:00:00 2001 From: Guillaume Louel Date: Mon, 19 Nov 2018 14:54:27 +0100 Subject: [PATCH 4/5] beta4, removing non working check now button --- Aerial/Source/Controllers/PreferencesWindowController.swift | 3 --- Resources/PreferencesWindow.xib | 6 +++--- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/Aerial/Source/Controllers/PreferencesWindowController.swift b/Aerial/Source/Controllers/PreferencesWindowController.swift index 17b65029..af5d5566 100644 --- a/Aerial/Source/Controllers/PreferencesWindowController.swift +++ b/Aerial/Source/Controllers/PreferencesWindowController.swift @@ -1487,9 +1487,6 @@ final class PreferencesWindowController: NSWindowController, NSOutlineViewDataSo } func downloadAllVideos() { - guard let videos = videos else { - return - } let videoManager = VideoManager.sharedInstance for city in cities { for video in city.day.videos where !video.isAvailableOffline { diff --git a/Resources/PreferencesWindow.xib b/Resources/PreferencesWindow.xib index ba3e7b01..2de08168 100644 --- a/Resources/PreferencesWindow.xib +++ b/Resources/PreferencesWindow.xib @@ -138,7 +138,7 @@ - + @@ -1324,7 +1324,7 @@ Shift, but macOS 10.12.4 or above and a compatible Mac are required) - + @@ -1475,7 +1475,7 @@ Shift, but macOS 10.12.4 or above and a compatible Mac are required) -