Skip to content

Commit

Permalink
Fix local sources custom data being erased at startup
Browse files Browse the repository at this point in the history
  • Loading branch information
glouel committed Jul 17, 2023
1 parent 724d25c commit 037c614
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 30 deletions.
8 changes: 4 additions & 4 deletions Aerial.xcodeproj/project.pbxproj
Expand Up @@ -3241,15 +3241,15 @@
CODE_SIGN_IDENTITY = "Developer ID Application";
CODE_SIGN_STYLE = Manual;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 3.2.7beta3;
CURRENT_PROJECT_VERSION = 3.2.7beta4;
DEFINES_MODULE = YES;
DEVELOPMENT_TEAM = 3L54M5L5KK;
ENABLE_HARDENED_RUNTIME = YES;
INFOPLIST_FILE = "$(SRCROOT)/Resources/Old stuff/Info.plist";
INSTALL_PATH = "$(HOME)/Library/Screen Savers";
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks";
MACOSX_DEPLOYMENT_TARGET = 10.13;
MARKETING_VERSION = 3.2.7beta3;
MARKETING_VERSION = 3.2.7beta4;
PRODUCT_BUNDLE_IDENTIFIER = com.johncoates.Aerial;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
Expand All @@ -3270,15 +3270,15 @@
CODE_SIGN_IDENTITY = "Developer ID Application";
CODE_SIGN_STYLE = Manual;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 3.2.7beta3;
CURRENT_PROJECT_VERSION = 3.2.7beta4;
DEFINES_MODULE = YES;
DEVELOPMENT_TEAM = 3L54M5L5KK;
ENABLE_HARDENED_RUNTIME = YES;
INFOPLIST_FILE = "$(SRCROOT)/Resources/Old stuff/Info.plist";
INSTALL_PATH = "$(HOME)/Library/Screen Savers";
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks";
MACOSX_DEPLOYMENT_TARGET = 10.13;
MARKETING_VERSION = 3.2.7beta3;
MARKETING_VERSION = 3.2.7beta4;
OTHER_CODE_SIGN_FLAGS = "--timestamp";
PRODUCT_BUNDLE_IDENTIFIER = com.johncoates.Aerial;
PRODUCT_NAME = "$(TARGET_NAME)";
Expand Down
24 changes: 24 additions & 0 deletions Aerial/Source/Models/Sources/Source.swift
Expand Up @@ -86,6 +86,30 @@ struct Source: Codable {
return ""
}

// Read local entries.json and return the video assets as an array
// This is used to update in place the entries.json at startup when updating local sources
func getUnprocessedAssets() -> [VideoAsset] {
if isCached() {
do {
let cacheFileUrl = URL(fileURLWithPath: Cache.supportPath.appending("/" + name + "/entries.json"))
let jsondata = try Data(contentsOf: cacheFileUrl)

if let videoManifest = try? newJSONDecoder().decode(VideoManifest.self, from: jsondata) {
return videoManifest.assets
}

errorLog("### Could not parse manifest data")
return []
} catch {
errorLog("\(name) could not be opened")
return []
}
} else {
debugLog("\(name) is not cached")
return []
}
}

func getUnprocessedVideos() -> [AerialVideo] {
if isCached() {
do {
Expand Down
49 changes: 32 additions & 17 deletions Aerial/Source/Models/Sources/SourceList.swift
Expand Up @@ -234,39 +234,54 @@ struct SourceList {
static func updateLocalSource(source: Source, reload: Bool) {
// We need the raw manifest to find the path inside
let videos = source.getUnprocessedVideos()
let originalAssets = source.getUnprocessedAssets()

var updatedAssets = [VideoAsset]()

if videos.count >= 1 {
let url = videos.first!.url.deletingLastPathComponent()
let folderName = url.lastPathComponent
debugLog("processing url for videos : \(url)")

do {
let urls = try FileManager.default.contentsOfDirectory(at: url, includingPropertiesForKeys: nil, options: [.skipsHiddenFiles])
var assets = [VideoAsset]()
// var assets = [VideoAsset]()



for lurl in urls {
if lurl.path.lowercased().hasSuffix(".mp4") || lurl.path.lowercased().hasSuffix(".mov") {
assets.append(VideoAsset(accessibilityLabel: folderName,
id: NSUUID().uuidString,
title: lurl.lastPathComponent,
timeOfDay: "day",
scene: "",
pointsOfInterest: [:],
url4KHDR: "",
url4KSDR: lurl.path,
url1080H264: "",
url1080HDR: "",
url4KSDR120FPS: "",
url4KSDR240FPS: "",
url1080SDR: "",
url: "",
type: "nature"))

// Check if the asset was there previously
let foundAssets = originalAssets.filter { $0.url4KSDR == lurl.path }

if let foundAsset = foundAssets.first {
// Just add the asset to the new array
updatedAssets.append(foundAsset)
} else {
// Create a new entry
updatedAssets.append(VideoAsset(accessibilityLabel: folderName,
id: NSUUID().uuidString,
title: lurl.lastPathComponent,
timeOfDay: "day",
scene: "",
pointsOfInterest: [:],
url4KHDR: "",
url4KSDR: lurl.path,
url1080H264: "",
url1080HDR: "",
url4KSDR120FPS: "",
url4KSDR240FPS: "",
url1080SDR: "",
url: "",
type: "nature"))
}
}
}

debugLog("Updating manifest \(url.lastPathComponent)")

let videoManifest = VideoManifest(assets: assets, initialAssetCount: 1, version: 1)
let videoManifest = VideoManifest(assets: updatedAssets, initialAssetCount: 1, version: 1)

SourceList.saveEntries(source: source, manifest: videoManifest)

Expand Down
23 changes: 14 additions & 9 deletions Aerial/Source/Views/AerialView.swift
Expand Up @@ -427,25 +427,28 @@ final class AerialView: ScreenSaverView, CAAnimationDelegate {
}

func teardown() {
debugLog("🖼️ \(self.description) teardown")

// Remove notifications observer
debugLog("🖼️ \(self.description) clear notif")
clearNotifications()
// Clear layer animations
debugLog("🖼️ \(self.description) clear anims")
clearAllLayerAnimations()

guard let player = self.player else {
return
}
// Remove from player index
let indexMaybe = AerialView.players.firstIndex(of: player)
if let player = player {
// Remove from player index
let indexMaybe = AerialView.players.firstIndex(of: player)

guard let index = indexMaybe else {
return
guard let index = indexMaybe else {
return
}
AerialView.players.remove(at: index)
}
AerialView.players.remove(at: index)

// Remove any download
VideoManager.sharedInstance.cancelAll()

debugLog("🖼️ end teardown")
}

Expand Down Expand Up @@ -558,6 +561,7 @@ final class AerialView: ScreenSaverView, CAAnimationDelegate {
debugLog("🖼️ 📢📢📢 ☢️sonoma☢️ workaround screenIsUnlocked")
if !Aerial.helper.underCompanion {
if let player = player {
layerManager.removeAllLayers()
player.pause()
}
self.stopAnimation()
Expand All @@ -578,6 +582,7 @@ final class AerialView: ScreenSaverView, CAAnimationDelegate {
player.pause()
}
self.stopAnimation()

} else {
player?.play()
player?.rate = globalSpeed
Expand Down

0 comments on commit 037c614

Please sign in to comment.