Skip to content

Commit

Permalink
Fix hang bug with no videos
Browse files Browse the repository at this point in the history
  • Loading branch information
glouel committed Apr 23, 2022
1 parent c2a93e3 commit dde1f10
Show file tree
Hide file tree
Showing 12 changed files with 59 additions and 98 deletions.
12 changes: 6 additions & 6 deletions Aerial.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -3187,18 +3187,18 @@
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
CLANG_ALLOW_NON_MODULAR_INCLUDES_IN_FRAMEWORK_MODULES = NO;
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_IDENTITY = "Developer ID Application: Guillaume Louel (3L54M5L5KK)";
CODE_SIGN_IDENTITY = "Developer ID Application";
CODE_SIGN_STYLE = Manual;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 3.0.6;
CURRENT_PROJECT_VERSION = 3.0.9;
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.12;
MARKETING_VERSION = 3.0.6;
MARKETING_VERSION = 3.0.9;
PRODUCT_BUNDLE_IDENTIFIER = com.johncoates.Aerial;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
Expand All @@ -3215,18 +3215,18 @@
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
CLANG_ALLOW_NON_MODULAR_INCLUDES_IN_FRAMEWORK_MODULES = NO;
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_IDENTITY = "Developer ID Application: Guillaume Louel (3L54M5L5KK)";
CODE_SIGN_IDENTITY = "Developer ID Application";
CODE_SIGN_STYLE = Manual;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 3.0.6;
CURRENT_PROJECT_VERSION = 3.0.9;
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.12;
MARKETING_VERSION = 3.0.6;
MARKETING_VERSION = 3.0.9;
OTHER_CODE_SIGN_FLAGS = "--timestamp";
PRODUCT_BUNDLE_IDENTIFIER = com.johncoates.Aerial;
PRODUCT_NAME = "$(TARGET_NAME)";
Expand Down
6 changes: 3 additions & 3 deletions Aerial/App/Resources/Base.lproj/MainMenu.xib
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="19529" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="20037" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
<dependencies>
<deployment version="101202" identifier="macosx"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="19529"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="20037"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<objects>
Expand Down Expand Up @@ -333,7 +333,7 @@
<rect key="frame" x="0.0" y="0.0" width="1744" height="1125"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<customView fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="M0V-7R-ZSD" customClass="AerialView">
<customView fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="M0V-7R-ZSD">
<rect key="frame" x="0.0" y="0.0" width="1744" height="1125"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
</customView>
Expand Down
11 changes: 11 additions & 0 deletions Aerial/Source/Models/ErrorLog.swift
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,21 @@ func Log(level: ErrorLevel, message: String) {

// Log to disk
if preferences.debugMode {
//logToConsole(message)
logToDisk(message)
}
}

func logToConsole(_ message: String) {
if #available(OSX 10.12, *) {
// This is faster when available
let log = OSLog(subsystem: Bundle.main.bundleIdentifier!, category: "Screensaver")
os_log("Aerial: %{public}@", log: log, type: .default, message)
} else {
NSLog("Aerial: \(message)")
}

}
func logToDisk(_ message: String) {
DispatchQueue.main.async {
// Prefix message with date
Expand Down
2 changes: 1 addition & 1 deletion Aerial/Source/Models/Prefs/Preferences.swift
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ final class Preferences {
defaultValues[.showDescriptionsMode] = DescriptionMode.fade10seconds
defaultValues[.multiMonitorMode] = MultiMonitorMode.mainOnly
defaultValues[.descriptionCorner] = DescriptionCorner.bottomLeft
defaultValues[.debugMode] = true
defaultValues[.debugMode] = false
defaultValues[.versionCheck] = VersionCheck.weekly
defaultValues[.alsoVersionCheckBeta] = false
defaultValues[.dimBrightness] = false
Expand Down
60 changes: 0 additions & 60 deletions Aerial/Source/Models/Sources/Sidebar.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@ import Cocoa

class Sidebar {
var modern: [Any] = []
var videos: [Any] = []
var settings: [Any] = []
var infos: [Any] = []

struct Header {
let name: String
Expand All @@ -27,9 +24,6 @@ class Sidebar {

init() {
makeModern()
/*makeSettings()
makeInfos()
refreshVideos()*/
}

// The new modern menu in 3.0
Expand Down Expand Up @@ -59,60 +53,6 @@ class Sidebar {
]
}

// This is where we maintain the list of the Sidebar content, this will need to be
// updated periodically unlike the other sidebars that are static
/*func refreshVideos() {
// At the very top, the current rotation
let onRotation = MenuEntry(name: "Currently playing", path: "videos:rotation:0")

// Favs
let fav = MenuEntry(name: "Favorites", path: "videos:favorites:0")

// All videos
let all = MenuEntry(name: "All videos", path: "videos:all")

// Cached/uncached
let cache = Header(name: "Cache",
entries: makeEntriesFor(sources: VideoList.instance.getSources(mode: .cache),
path: "videos:cache"))

// Locations
let locations = Header(name: "Location",
entries: makeEntriesFor(sources: VideoList.instance.getSources(mode: .location),
path: "videos:location"))

// Times
let time = Header(name: "Time",
entries: makeEntriesFor(sources: VideoList.instance.getSources(mode: .time),
path: "videos:time"))
// Scenes
let scene = Header(name: "Scene",
entries: makeEntriesFor(sources: VideoList.instance.getSources(mode: .scene),
path: "videos:scene"))

// Sources
let source = Header(name: "Source",
entries: makeEntriesFor(sources: VideoList.instance.getSources(mode: .source),
path: "videos:source"))

// Hidden
let hidden = MenuEntry(name: "Hidden", path: "videos:hidden:0")

videos = [onRotation, fav, all, cache, locations, time, scene, source, hidden]
}*/

func makeEntriesFor(sources: [String], path: String) -> [MenuEntry] {
var entries: [MenuEntry] = []
var index = 0

for source in sources {
entries.append(MenuEntry(name: source, path: path + ":\(index)"))
index += 1
}

return entries
}

// Helper to get the various icons for the sidebar
// swiftlint:disable:next cyclomatic_complexity
static func iconFor(_ path: String, name: String) -> NSImage? {
Expand Down
8 changes: 1 addition & 7 deletions Aerial/Source/Models/Sources/Source.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,12 @@ struct Source: Codable {
var license: String
var more: String

// TODO
func isEnabled() -> Bool {
// tvOS is always enabled
/*if name.starts(with: "tvOS") {
return true
}*/

if PrefsVideos.enabledSources.keys.contains(name) {
return PrefsVideos.enabledSources[name]!
}

// Unknown sources are enabled
// Unknown sources are enabled by default
return true
}

Expand Down
20 changes: 16 additions & 4 deletions Aerial/Source/Views/AerialView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -367,13 +367,17 @@ final class AerialView: ScreenSaverView, CAAnimationDelegate {
}

override func stopAnimation() {
super.stopAnimation()
//super.stopAnimation()
wasStopped = true
debugLog("\(self.description) stopAnimation")
if !isDisabled {
player?.pause()
player?.rate = 0
layerManager.removeAllLayers()
playerLayer.removeAllAnimations()
player?.replaceCurrentItem(with: nil)

isDisabled = true
}

let preferences = Preferences.sharedInstance
Expand Down Expand Up @@ -427,7 +431,7 @@ final class AerialView: ScreenSaverView, CAAnimationDelegate {

notificationCenter.removeObserver(self)
}

func setNotifications(_ currentItem: AVPlayerItem) {
let notificationCenter = NotificationCenter.default

Expand Down Expand Up @@ -459,6 +463,11 @@ final class AerialView: ScreenSaverView, CAAnimationDelegate {
Music.instance.setup()
}

func sendNotification(video: AerialVideo) {
DistributedNotificationCenter.default.post(name: Notification.Name("com.glouel.aerial.nextvideo"), object: "aerialtest : " + video.name)
}


@objc func willStart(_ aNotification: Notification) {
if Aerial.underCompanion {
debugLog("############ willStart")
Expand Down Expand Up @@ -575,7 +584,8 @@ final class AerialView: ScreenSaverView, CAAnimationDelegate {
observerWasSet = true
playerLayer.addObserver(self, forKeyPath: "readyForDisplay", options: .initial, context: nil)
}


sendNotification(video: video)
setNotifications(currentItem)

player.actionAtItemEnd = AVPlayer.ActionAtItemEnd.none
Expand Down Expand Up @@ -611,6 +621,7 @@ final class AerialView: ScreenSaverView, CAAnimationDelegate {
playerLayer.addObserver(self, forKeyPath: "readyForDisplay", options: .initial, context: nil)
}

sendNotification(video: video)
setNotifications(currentItem)

player.actionAtItemEnd = AVPlayer.ActionAtItemEnd.none
Expand All @@ -621,7 +632,6 @@ final class AerialView: ScreenSaverView, CAAnimationDelegate {
}
}
}

}

// Is the current screen vertical?
Expand Down Expand Up @@ -653,6 +663,8 @@ final class AerialView: ScreenSaverView, CAAnimationDelegate {
} else {
debugLog("Right arrow key currently locked")
}
} else if event.keyCode == 125 {
stopAnimation()
} else {
self.nextResponder!.keyDown(with: event)
// super.keyDown(with: event)
Expand Down
1 change: 0 additions & 1 deletion Aerial/Source/Views/Layers/AnimationTextLayer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ class AnimationTextLayer: CATextLayer, AnimatableLayer {
self.string = string
self.isWrapped = true

debugLog("string : " + string)
// This is the rect resized to our string
let newCorner = getCorner()
frame = calculateRect(string: string, font: font as! NSFont, newCorner: newCorner)
Expand Down
9 changes: 9 additions & 0 deletions Aerial/Source/Views/Layers/LayerManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -129,10 +129,19 @@ class LayerManager {
// Called before starting a new video
func clearLayerAnimations(player: AVPlayer) {
for layer in additionalLayers {
print(layer)
layer.clear(player: player)
layer.removeAllAnimations()
}
}

func removeAllLayers() {
for layer in additionalLayers {
print(layer)
layer.removeAllAnimations()
layer.removeFromSuperlayer()
}
}

// Called at each new video
func setupLayersForVideo(video: AerialVideo, player: AVPlayer) {
Expand Down
3 changes: 1 addition & 2 deletions Resources/MainUI/PanelWindowController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,8 @@ import Cocoa
Aerial.windowController = self

// Create all the view items for the right panel
videoViewItem = NSSplitViewItem(viewController: videosVC!)

nowPlayingItem = NSSplitViewItem(viewController: nowPlayingVC)
videoViewItem = NSSplitViewItem(viewController: videosVC!)

// Infos
infoViewItem = NSSplitViewItem(viewController: infoVC)
Expand Down
16 changes: 6 additions & 10 deletions Resources/MainUI/SidebarViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,7 @@ class SidebarViewController: NSViewController {
}

override func viewDidAppear() {
// When we are really there, we can look for the data
// This will trigger the refresh of the VideosViewController
VideoList.instance.addCallback {
print("reload")
self.reloadSidebar()
}
self.reloadSidebar()
}

private func updateSidebarMenu(_ menu: SidebarMenus) {
Expand Down Expand Up @@ -144,7 +139,7 @@ extension SidebarViewController: NSOutlineViewDataSource {
if let header = item as? Sidebar.Header {
return header.entries.count
}

debugLog("child count \(Sidebar.instance.modern.count)")
return Sidebar.instance.modern.count
}

Expand Down Expand Up @@ -260,6 +255,7 @@ extension SidebarViewController: SidebarOutlineViewDelegate {
}

guard !videos.isEmpty else {
debugLog("empty videos")
return nil
}

Expand Down Expand Up @@ -405,17 +401,17 @@ extension SidebarViewController: SidebarOutlineViewDelegate {
func reloadSidebar() {
// We need to reload our sidebar
// Sidebar.instance.refreshVideos()
print("reload sidebar")
debugLog("reload sidebar")
let set = sidebarOutlineView.selectedRowIndexes

sidebarOutlineView.reloadData()
sidebarOutlineView.expandItem(nil, expandChildren: true)

if set.isEmpty {
print("empty set")
debugLog("empty set")
sidebarOutlineView.selectRowIndexes([1], byExtendingSelection: false)
} else {
print("re set ing")
debugLog("re set ing")
sidebarOutlineView.selectRowIndexes(set, byExtendingSelection: false)

}
Expand Down
9 changes: 5 additions & 4 deletions Resources/MainUI/VideosViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,6 @@ class VideosViewController: NSViewController {
var filter: VideoList.FilterMode

filter = VideoList.instance.modeFromPath(mode!) ?? .location
print("ursm : \(mode) \(filter)")
rotationSecondaryPopup.removeAllItems()

// Very unswift
Expand Down Expand Up @@ -574,9 +573,11 @@ class VideosViewController: NSViewController {
}
} else {
// all
return VideoList.instance.videos
.filter({ !PrefsVideos.hidden.contains($0.id) })
.sorted { $0.secondaryName < $1.secondaryName }[videoListTableView.selectedRow]
if VideoList.instance.videos.count > 0 {
return VideoList.instance.videos
.filter({ !PrefsVideos.hidden.contains($0.id) })
.sorted { $0.secondaryName < $1.secondaryName }[videoListTableView.selectedRow]
}
}
}

Expand Down

0 comments on commit dde1f10

Please sign in to comment.