Skip to content

Commit

Permalink
Merge pull request #670 from glouel/master
Browse files Browse the repository at this point in the history
Beta 4
  • Loading branch information
glouel authored Nov 19, 2018
2 parents 46b37b4 + 0d58347 commit bf60285
Show file tree
Hide file tree
Showing 7 changed files with 88 additions and 39 deletions.
2 changes: 1 addition & 1 deletion Aerial/App/Resources/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>1.4.6beta1</string>
<string>1.4.6beta4</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
Expand Down
30 changes: 23 additions & 7 deletions Aerial/Source/Controllers/PreferencesWindowController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ final class PreferencesWindowController: NSWindowController, NSOutlineViewDataSo
@IBOutlet var newVideosModePopup: NSPopUpButton!

@IBOutlet var lastCheckedVideosLabel: NSTextField!
@IBOutlet var checkNowButton: NSButton!

var player: AVPlayer = AVPlayer()

Expand Down Expand Up @@ -568,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)
Expand Down Expand Up @@ -1061,6 +1065,11 @@ final class PreferencesWindowController: NSWindowController, NSOutlineViewDataSo
preferences.newVideosMode = sender.indexOfSelectedItem
}

@IBAction func checkNowButtonClick(_ sender: NSButton) {
checkNowButton.isEnabled = false
// TODO
}

// MARK: - Time panel

@IBAction func overrideNightOnDarkModeClick(_ button: NSButton) {
Expand Down Expand Up @@ -1478,14 +1487,17 @@ final class PreferencesWindowController: NSWindowController, NSOutlineViewDataSo
}

func downloadAllVideos() {
guard let videos = videos else {
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)
}
}
}
}
Expand Down Expand Up @@ -1526,6 +1538,10 @@ final class PreferencesWindowController: NSWindowController, NSOutlineViewDataSo
}
}

func reloadJson() {
ManifestLoader.instance.reloadFiles()
}

func loaded(manifestVideos: [AerialVideo]) {
var videos = [AerialVideo]()
var cities = [String: City]()
Expand Down
13 changes: 12 additions & 1 deletion Aerial/Source/Models/Cache/VideoCache.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -39,6 +45,8 @@ final class VideoCache {
cacheDirectory = defaultCacheDirectory
}

//NSLog("AerialP: cd \(String(describing: cacheDirectory))")

guard let appCacheDirectory = cacheDirectory else {
return nil
}
Expand All @@ -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
}

Expand Down
58 changes: 32 additions & 26 deletions Aerial/Source/Models/ErrorLog.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
}
}
}
Expand Down
4 changes: 4 additions & 0 deletions Aerial/Source/Models/ManifestLoader.swift
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,10 @@ class ManifestLoader {
}
}

func reloadFiles() {
// TODO
}

func addCallback(_ callback:@escaping ManifestLoadCallback) {
if !loadedManifest.isEmpty {
callback(loadedManifest)
Expand Down
4 changes: 2 additions & 2 deletions Resources/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
<key>CFBundlePackageType</key>
<string>BNDL</string>
<key>CFBundleShortVersionString</key>
<string>1.4.6beta3</string>
<string>1.4.6beta4</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>1.4.6beta3</string>
<string>1.4.6beta4</string>
<key>LSApplicationCategoryType</key>
<string></string>
<key>LSMinimumSystemVersion</key>
Expand Down
16 changes: 14 additions & 2 deletions Resources/PreferencesWindow.xib
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
<outlet property="cacheSizeTextField" destination="L70-Vj-qPk" id="EIq-de-VmH"/>
<outlet property="calculateCoordinatesLabel" destination="YXF-Ei-ZTD" id="LEn-QN-uyy"/>
<outlet property="changeCornerMargins" destination="VPG-cS-U1N" id="F9P-rV-FaD"/>
<outlet property="checkNowButton" destination="EeC-Lg-0GW" id="3zr-3y-AW9"/>
<outlet property="cornerBottomLeft" destination="Qhn-AB-VZ5" id="YIg-vu-QIS"/>
<outlet property="cornerBottomRight" destination="4Rr-4h-bRr" id="5oY-Eh-CdE"/>
<outlet property="cornerContainer" destination="NQf-K9-FZk" id="SU0-YA-s4F"/>
Expand Down Expand Up @@ -137,7 +138,7 @@
<font key="font" metaFont="system"/>
<tabViewItems>
<tabViewItem label="Videos" identifier="1" id="dfl-QA-fvD">
<view key="view" ambiguous="YES" id="zsM-Ha-kCO">
<view key="view" id="zsM-Ha-kCO">
<rect key="frame" x="10" y="33" width="614" height="381"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
Expand Down Expand Up @@ -1323,7 +1324,7 @@ Shift, but macOS 10.12.4 or above and a compatible Mac are required) </string>
</view>
</tabViewItem>
<tabViewItem label="Cache" identifier="2" id="kp1-xv-zNG">
<view key="view" id="93q-v8-yxM">
<view key="view" ambiguous="YES" id="93q-v8-yxM">
<rect key="frame" x="10" y="33" width="614" height="381"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
Expand Down Expand Up @@ -1474,6 +1475,17 @@ Shift, but macOS 10.12.4 or above and a compatible Mac are required) </string>
<color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
</textField>
<button hidden="YES" verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="EeC-Lg-0GW">
<rect key="frame" x="239" y="264" width="109" height="32"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<buttonCell key="cell" type="push" title="Check Now" bezelStyle="rounded" alignment="center" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="BzW-k0-hBJ">
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
<font key="font" metaFont="system"/>
</buttonCell>
<connections>
<action selector="checkNowButtonClick:" target="-2" id="m24-Vz-0bi"/>
</connections>
</button>
</subviews>
</view>
</tabViewItem>
Expand Down

0 comments on commit bf60285

Please sign in to comment.