mirror of
https://github.com/Ranchero-Software/NetNewsWire
synced 2025-08-12 06:26:36 +00:00
Add a Debug menu option to clear the image caches
This commit is contained in:
@@ -771,6 +771,25 @@ extension AppDelegate {
|
||||
#endif
|
||||
}
|
||||
|
||||
@IBAction func debugClearImageCaches(_ sender: Any?) {
|
||||
let alert = NSAlert()
|
||||
alert.alertStyle = .warning
|
||||
|
||||
let localizedMessageText = NSLocalizedString("Install theme “%@” by %@?", comment: "Theme message text")
|
||||
alert.messageText = NSLocalizedString("Are you sure you want to clear the image caches? This will restart NetNewsWire to begin reloading the remote images.",
|
||||
comment: "Clear and restart confirmation message.")
|
||||
alert.addButton(withTitle: NSLocalizedString("Clear & Restart", comment: "Clear & Restart"))
|
||||
alert.addButton(withTitle: NSLocalizedString("Cancel", comment: "Cancel"))
|
||||
|
||||
let userChoice = alert.runModal()
|
||||
if userChoice == .alertFirstButtonReturn {
|
||||
CacheCleaner.purge()
|
||||
|
||||
Process.launchedProcess(launchPath: "/usr/bin/open", arguments: ["-b", Bundle.main.bundleIdentifier!])
|
||||
NSApp.terminate(self)
|
||||
}
|
||||
}
|
||||
|
||||
@IBAction func debugTestCrashReporterWindow(_ sender: Any?) {
|
||||
#if DEBUG
|
||||
crashReportWindowController = CrashReportWindowController(crashLogText: "This is a test crash log.")
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<document type="com.apple.InterfaceBuilder3.Cocoa.Storyboard.XIB" version="3.0" toolsVersion="21225" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES">
|
||||
<document type="com.apple.InterfaceBuilder3.Cocoa.Storyboard.XIB" version="3.0" toolsVersion="21507" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES">
|
||||
<dependencies>
|
||||
<deployment identifier="macosx"/>
|
||||
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="21225"/>
|
||||
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="21507"/>
|
||||
</dependencies>
|
||||
<scenes>
|
||||
<!--Application-->
|
||||
@@ -539,6 +539,12 @@
|
||||
<action selector="debugDropConditionalGetInfo:" target="Voe-Tx-rLC" id="X24-9X-rwG"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem title="Clear Image Caches" id="o1k-E6-ctu">
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
<connections>
|
||||
<action selector="debugClearImageCaches:" target="Voe-Tx-rLC" id="5kp-89-U92"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem isSeparatorItem="YES" id="Dij-Nu-eot"/>
|
||||
<menuItem title="Test Crash Reporter Window" id="gVd-kQ-efj">
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
|
||||
@@ -23,23 +23,7 @@ struct CacheCleaner: Logging {
|
||||
if flushDate.addingTimeInterval(3600 * 24 * 3) < Date() {
|
||||
if let reachability = try? Reachability(hostname: "apple.com") {
|
||||
if reachability.connection != .unavailable {
|
||||
|
||||
let tempDir = FileManager.default.urls(for: .cachesDirectory, in: .userDomainMask).first!
|
||||
let faviconsFolderURL = tempDir.appendingPathComponent("Favicons")
|
||||
let imagesFolderURL = tempDir.appendingPathComponent("Images")
|
||||
let feedURLToIconURL = tempDir.appendingPathComponent("FeedURLToIconURLCache.plist")
|
||||
let homePageToIconURL = tempDir.appendingPathComponent("HomePageToIconURLCache.plist")
|
||||
let homePagesWithNoIconURL = tempDir.appendingPathComponent("HomePagesWithNoIconURLCache.plist")
|
||||
|
||||
for tempItem in [faviconsFolderURL, imagesFolderURL, feedURLToIconURL, homePageToIconURL, homePagesWithNoIconURL] {
|
||||
do {
|
||||
CacheCleaner.logger.info("Removing cache file: \(tempItem.absoluteString, privacy: .public)")
|
||||
try FileManager.default.removeItem(at: tempItem)
|
||||
} catch {
|
||||
CacheCleaner.logger.error("Could not delete cache file: \(error.localizedDescription, privacy: .public)")
|
||||
}
|
||||
}
|
||||
|
||||
purge()
|
||||
AppDefaults.shared.lastImageCacheFlushDate = Date()
|
||||
|
||||
}
|
||||
@@ -48,4 +32,22 @@ struct CacheCleaner: Logging {
|
||||
|
||||
}
|
||||
|
||||
static func purge() {
|
||||
let tempDir = FileManager.default.urls(for: .cachesDirectory, in: .userDomainMask).first!
|
||||
let faviconsFolderURL = tempDir.appendingPathComponent("Favicons")
|
||||
let imagesFolderURL = tempDir.appendingPathComponent("Images")
|
||||
let feedURLToIconURL = tempDir.appendingPathComponent("FeedURLToIconURLCache.plist")
|
||||
let homePageToIconURL = tempDir.appendingPathComponent("HomePageToIconURLCache.plist")
|
||||
let homePagesWithNoIconURL = tempDir.appendingPathComponent("HomePagesWithNoIconURLCache.plist")
|
||||
|
||||
for tempItem in [faviconsFolderURL, imagesFolderURL, feedURLToIconURL, homePageToIconURL, homePagesWithNoIconURL] {
|
||||
do {
|
||||
CacheCleaner.logger.info("Removing cache file: \(tempItem.absoluteString, privacy: .public)")
|
||||
try FileManager.default.removeItem(at: tempItem)
|
||||
} catch {
|
||||
CacheCleaner.logger.error("Could not delete cache file: \(error.localizedDescription, privacy: .public)")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user