Skip to content

Commit

Permalink
Add workaround message box to change cache folder in Catalina
Browse files Browse the repository at this point in the history
Fix POI no longer loading in beta 5/6
Aerial will now use ~/Library/Application Support/Aerial as it's default cache for new users
  • Loading branch information
glouel committed Jun 25, 2019
1 parent fae84ae commit 32bf7b0
Show file tree
Hide file tree
Showing 5 changed files with 131 additions and 57 deletions.
48 changes: 31 additions & 17 deletions Aerial/Source/Controllers/PWC Tabs/PWC+Cache.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ extension PreferencesWindowController {
cacheLocation.url = nil
}
}

func updateCacheSize() {
// get your directory url
let documentsDirectoryURL = URL(fileURLWithPath: VideoCache.cacheDirectory!)
Expand Down Expand Up @@ -75,27 +76,40 @@ extension PreferencesWindowController {
}

@IBAction func userSetCacheLocation(_ button: NSButton?) {
let openPanel = NSOpenPanel()

openPanel.canChooseDirectories = true
openPanel.canChooseFiles = false
openPanel.canCreateDirectories = true
openPanel.allowsMultipleSelection = false
openPanel.title = "Choose Aerial Cache Directory"
openPanel.prompt = "Choose"
openPanel.directoryURL = cacheLocation.url

openPanel.begin { result in
guard result.rawValue == NSFileHandlingPanelOKButton, !openPanel.urls.isEmpty else {
return
}
if #available(OSX 10.15, *) {
cacheFolderTextField.stringValue = VideoCache.cacheDirectory!
changeCacheFolderPanel.makeKeyAndOrderFront(self)
} else {
let openPanel = NSOpenPanel()

openPanel.canChooseDirectories = true
openPanel.canChooseFiles = false
openPanel.canCreateDirectories = true
openPanel.allowsMultipleSelection = false
openPanel.title = "Choose Aerial Cache Directory"
openPanel.prompt = "Choose"
openPanel.directoryURL = cacheLocation.url

let cacheDirectory = openPanel.urls[0]
self.preferences.customCacheDirectory = cacheDirectory.path
self.cacheLocation.url = cacheDirectory
openPanel.begin { result in
guard result.rawValue == NSFileHandlingPanelOKButton, !openPanel.urls.isEmpty else {
return
}

let cacheDirectory = openPanel.urls[0]
self.preferences.customCacheDirectory = cacheDirectory.path
self.cacheLocation.url = cacheDirectory
}
}
}

// This is part of the Catalina workaround of showing a Panel
@IBAction func validateChangeFolderButton(_ sender: Any) {
debugLog("Changed cache Folder to : \(cacheFolderTextField.stringValue)")
self.preferences.customCacheDirectory = cacheFolderTextField.stringValue
self.cacheLocation.url = URL(fileURLWithPath: cacheFolderTextField.stringValue)
changeCacheFolderPanel.close()
}

@IBAction func resetCacheLocation(_ button: NSButton?) {
preferences.customCacheDirectory = nil
if let cacheDirectory = VideoCache.cacheDirectory {
Expand Down
4 changes: 4 additions & 0 deletions Aerial/Source/Controllers/PreferencesWindowController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,10 @@ final class PreferencesWindowController: NSWindowController, NSOutlineViewDataSo
// Quit confirmation Panel
@IBOutlet var quitConfirmationPanel: NSPanel!

// Change cache folder Panel
@IBOutlet var changeCacheFolderPanel: NSPanel!
@IBOutlet var cacheFolderTextField: NSTextField!

var player: AVPlayer = AVPlayer()

var videos: [AerialVideo]?
Expand Down
6 changes: 3 additions & 3 deletions Aerial/Source/Models/Cache/PoiStringProvider.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,15 @@ final class PoiStringProvider {
// Idle string bundle
let preferences = Preferences.sharedInstance

var bundlePath = VideoCache.cacheDirectory!
var bundlePath = VideoCache.appSupportDirectory!
if preferences.localizeDescriptions {
bundlePath.append(contentsOf: "/TVIdleScreenStrings.bundle")
} else {
bundlePath.append(contentsOf: "/TVIdleScreenStrings.bundle/en.lproj/")
}

if let sb = Bundle.init(path: bundlePath) {
let dictPath = VideoCache.cacheDirectory!.appending("/TVIdleScreenStrings.bundle/en.lproj/Localizable.nocache.strings")
let dictPath = VideoCache.appSupportDirectory!.appending("/TVIdleScreenStrings.bundle/en.lproj/Localizable.nocache.strings")

// We could probably only work with that...
if let sd = NSDictionary(contentsOfFile: dictPath) as? [String: String] {
Expand Down Expand Up @@ -148,7 +148,7 @@ final class PoiStringProvider {

if #available(OSX 10.12, *) {
// First we look in the Cache Folder for a locale directory
let cacheDirectory = VideoCache.cacheDirectory!
let cacheDirectory = VideoCache.appSupportDirectory!
var cacheResourcesString = cacheDirectory
cacheResourcesString.append(contentsOf: "/locale")
let cacheUrl = URL(fileURLWithPath: cacheResourcesString)
Expand Down
52 changes: 18 additions & 34 deletions Aerial/Source/Models/Cache/VideoCache.swift
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ final class VideoCache {

// MARK: - User Video cache directory
static var cacheDirectory: String? {

// We only process this once if successful
if computedCacheDirectory != nil {
return computedCacheDirectory
Expand All @@ -82,54 +81,39 @@ final class VideoCache {
if let customCacheDirectory = preferences.customCacheDirectory {
// We may have overriden the cache directory, but it may no longer exist !
if FileManager.default.fileExists(atPath: customCacheDirectory as String) {
debugLog("Using exiting customCacheDirectory : \(customCacheDirectory)")
cacheDirectory = customCacheDirectory
} else {
} /*else {
// If it doesn't we need to reset that preference
preferences.customCacheDirectory = nil
}
}*/
}

if cacheDirectory == nil {
let userCachePaths = NSSearchPathForDirectoriesInDomains(.cachesDirectory,
.userDomainMask,
true)
debugLog("userCachePath : \(userCachePaths)")
if userCachePaths.isEmpty {
errorLog("Couldn't find cache paths!")
return nil
}
let userCacheDirectory = userCachePaths[0] as NSString
if #available(OSX 10.15, *) {
} else {
// Still look for /Library for pre Catalina OS
let localCachePaths = NSSearchPathForDirectoriesInDomains(.cachesDirectory,
.localDomainMask,
true)
let localCachePaths = NSSearchPathForDirectoriesInDomains(.cachesDirectory,
.localDomainMask,
true)

if !localCachePaths.isEmpty {
let localCacheDirectory = localCachePaths[0] as NSString
if aerialFolderExists(at: localCacheDirectory) {
debugLog("local cache exists")
debugLog("Using existing local cache /Library/Caches/Aerial")
cacheDirectory = localCacheDirectory.appendingPathComponent("Aerial")
}
}

if cacheDirectory == nil && aerialFolderExists(at: userCacheDirectory) {
debugLog("user cache exists")
cacheDirectory = userCacheDirectory.appendingPathComponent("Aerial")
} else {
debugLog("create user cache")
// We create in user cache directory (~/Library/Caches)
cacheDirectory = userCacheDirectory.appendingPathComponent("Aerial")

let fileManager = FileManager.default
if fileManager.fileExists(atPath: cacheDirectory!) == false {
do {
try fileManager.createDirectory(atPath: cacheDirectory!,
withIntermediateDirectories: false, attributes: nil)
} catch let error {
errorLog("Couldn't create cache directory in User directory: \(error)")
errorLog("FATAL : There's nothing more we can do at this point")
return nil
}
if !userCachePaths.isEmpty {
let userCacheDirectory = userCachePaths[0] as NSString

if cacheDirectory == nil && aerialFolderExists(at: userCacheDirectory) {
debugLog("Using existing user cache ~/Library/Caches/Aerial")
cacheDirectory = userCacheDirectory.appendingPathComponent("Aerial")
} else {
debugLog("No local or user cache exists, using ~/Library/Application Support/Aerial")
cacheDirectory = appSupportDirectory
}
}
}
Expand Down
78 changes: 75 additions & 3 deletions Resources/PreferencesWindow.xib
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,11 @@
<outlet property="automaticallyCheckForUpdatesCheckbox" destination="eDw-MF-oVs" id="Mlh-Pm-oeY"/>
<outlet property="betaCheckFrequencyPopup" destination="pMN-gd-bVd" id="cV7-KK-ZwB"/>
<outlet property="cacheAerialsAsTheyPlayCheckbox" destination="7HM-tD-v0b" id="29n-iQ-L36"/>
<outlet property="cacheFolderTextField" destination="2Sb-ue-nWB" id="rwT-3q-q7Y"/>
<outlet property="cacheLocation" destination="XAJ-Se-rwG" id="Qm8-0v-eOq"/>
<outlet property="cacheSizeTextField" destination="L70-Vj-qPk" id="EIq-de-VmH"/>
<outlet property="calculateCoordinatesLabel" destination="YXF-Ei-ZTD" id="LEn-QN-uyy"/>
<outlet property="changeCacheFolderPanel" destination="sJe-1s-Rt2" id="z3v-IY-O6t"/>
<outlet property="changeCornerMargins" destination="VPG-cS-U1N" id="F9P-rV-FaD"/>
<outlet property="checkNowButton" destination="EeC-Lg-0GW" id="3zr-3y-AW9"/>
<outlet property="ciOverrideLanguagePopup" destination="Thy-6K-bQe" id="eGe-Iv-gxJ"/>
Expand Down Expand Up @@ -518,7 +520,7 @@ is disabled
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<buttonCell key="cell" type="roundRect" bezelStyle="roundedRect" image="NSBookmarksTemplate" imagePosition="only" alignment="center" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="kGs-X6-tPb">
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
<font key="font" metaFont="label" size="12"/>
<font key="font" metaFont="controlContent"/>
</buttonCell>
<connections>
<action selector="videoSetsButtonClick:" target="-2" id="aDh-Hf-5AD"/>
Expand All @@ -540,7 +542,7 @@ is disabled
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<buttonCell key="cell" type="roundRect" bezelStyle="roundedRect" image="NSActionTemplate" imagePosition="only" alignment="center" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="nxM-5Y-pQM">
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
<font key="font" metaFont="label" size="12"/>
<font key="font" metaFont="controlContent"/>
</buttonCell>
<connections>
<action selector="outlineViewSettingsClick:" target="-2" id="foF-Fr-895"/>
Expand Down Expand Up @@ -2798,7 +2800,77 @@ Gw
</button>
</subviews>
</view>
<point key="canvasLocation" x="192.5" y="924"/>
<point key="canvasLocation" x="847" y="1028"/>
</window>
<window title="Change cache folder" allowsToolTipsWhenApplicationIsInactive="NO" autorecalculatesKeyViewLoop="NO" hidesOnDeactivate="YES" releasedWhenClosed="NO" visibleAtLaunch="NO" frameAutosaveName="" animationBehavior="default" id="sJe-1s-Rt2" customClass="NSPanel">
<windowStyleMask key="styleMask" titled="YES" closable="YES" utility="YES"/>
<windowPositionMask key="initialPositionMask" leftStrut="YES" rightStrut="YES" topStrut="YES" bottomStrut="YES"/>
<rect key="contentRect" x="272" y="172" width="595" height="349"/>
<rect key="screenRect" x="0.0" y="0.0" width="2560" height="1417"/>
<view key="contentView" id="JEQ-kf-Kj0">
<rect key="frame" x="0.0" y="0.0" width="595" height="349"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<textField verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="2Sb-ue-nWB">
<rect key="frame" x="20" y="153" width="555" height="21"/>
<autoresizingMask key="autoresizingMask"/>
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" selectable="YES" editable="YES" sendsActionOnEndEditing="YES" borderStyle="bezel" drawsBackground="YES" id="vIu-gd-PGa">
<font key="font" usesAppearanceFont="YES"/>
<color key="textColor" name="controlTextColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
</textField>
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="fx9-wP-BAV">
<rect key="frame" x="74" y="281" width="503" height="40"/>
<autoresizingMask key="autoresizingMask"/>
<textFieldCell key="cell" alignment="justified" title="With macOS Catalina, Aerial has limited access (read only) to your local disk and now lives in a sandbox. " id="N0S-xL-ig4">
<font key="font" metaFont="system"/>
<color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
</textField>
<imageView horizontalHuggingPriority="251" verticalHuggingPriority="251" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="X9F-ik-oYu">
<rect key="frame" x="20" y="281" width="48" height="48"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<imageCell key="cell" refusesFirstResponder="YES" alignment="left" imageScaling="proportionallyUpOrDown" image="NSCaution" id="Xv7-LA-jpF"/>
</imageView>
<textField verticalHuggingPriority="750" horizontalCompressionResistancePriority="250" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="asM-kR-rgt">
<rect key="frame" x="18" y="43" width="559" height="90"/>
<autoresizingMask key="autoresizingMask"/>
<textFieldCell key="cell" selectable="YES" alignment="justified" id="JiG-Ah-D6O">
<font key="font" metaFont="system"/>
<string key="title">Your path must end without a / and must be fully formed. For example :
/Users/MyUser/Aerial (and not ~/Aerial)

After changing the folder, please close System Preferences for this to be taken into account.</string>
<color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
</textField>
<textField verticalHuggingPriority="750" horizontalCompressionResistancePriority="250" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="aI8-Vj-v9Y">
<rect key="frame" x="19" y="180" width="557" height="93"/>
<autoresizingMask key="autoresizingMask"/>
<textFieldCell key="cell" selectable="YES" alignment="justified" id="3kv-uO-49e">
<font key="font" metaFont="system"/>
<string key="title">You can specify an additional cache folder, outside of the sandbox container, where Aerial will look for videos. Please note that new videos will be downloaded in the container folder (you can use the Show in Finder button in Advanced tab to get to that directory). You can manually move videos from this directory to your own specified cache if you wish, but Aerial can no longer do this itself due to sandboxing limitations.</string>
<color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
</textField>
<button verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="8Nf-bM-7vo">
<rect key="frame" x="234" y="13" width="126" height="32"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<buttonCell key="cell" type="push" title="Change folder" bezelStyle="rounded" alignment="center" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="7gl-Zf-Wyo">
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
<font key="font" metaFont="system"/>
</buttonCell>
<connections>
<action selector="validateChangeFolderButton:" target="-2" id="Xrh-Fi-KDD"/>
</connections>
</button>
</subviews>
</view>
<point key="canvasLocation" x="1452.5" y="864.5"/>
</window>
</objects>
<resources>
Expand Down

0 comments on commit 32bf7b0

Please sign in to comment.