fix(ios): avoid blocking launch cleanup and unify NWC ambient track names
This commit is contained in:
@@ -0,0 +1,8 @@
|
||||
import Foundation
|
||||
|
||||
/// Single source of truth for bundled NWC ambient track display names.
|
||||
@objc final class NWCAmbientTracks: NSObject {
|
||||
@objc static func trackNames() -> [String] {
|
||||
["Fireplace", "White Noise", "Gentle Rain"]
|
||||
}
|
||||
}
|
||||
@@ -4,7 +4,7 @@ import Foundation
|
||||
/// Shared Live Activity display state (app group). Used by the main app and Live Activity intents.
|
||||
enum NWCLiveActivityShared {
|
||||
static let appGroupID = "group.com.zeusln.zeus"
|
||||
static let tracks = ["Fireplace", "White Noise", "Gentle Rain"]
|
||||
static var tracks: [String] { NWCAmbientTracks.trackNames() }
|
||||
|
||||
private static let keyTrackIndex = "nwc.trackIndex"
|
||||
private static let keyIsMuted = "nwc.isMuted"
|
||||
|
||||
@@ -230,6 +230,7 @@
|
||||
NWCLA000000000000000003 /* NWCActivityManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = NWCLA000000000000000009 /* NWCActivityManager.swift */; };
|
||||
NWCLIS000000000000000001 /* NWCLiveActivityShared.swift in Sources */ = {isa = PBXBuildFile; fileRef = NWCLIS000000000000000003 /* NWCLiveActivityShared.swift */; };
|
||||
NWCLIS000000000000000002 /* NWCWidgetIntent.swift in Sources */ = {isa = PBXBuildFile; fileRef = NWCLIS000000000000000004 /* NWCWidgetIntent.swift */; };
|
||||
NWCLIS000000000000000005 /* NWCAmbientTracks.swift in Sources */ = {isa = PBXBuildFile; fileRef = NWCLIS000000000000000006 /* NWCAmbientTracks.swift */; };
|
||||
NWCLA000000000000000005 /* NWCWidget.appex in Embed Foundation Extensions */ = {isa = PBXBuildFile; fileRef = NWCLA000000000000000006 /* NWCWidget.appex */; settings = {ATTRIBUTES = (RemoveHeadersOnCopy, ); }; };
|
||||
/* End PBXBuildFile section */
|
||||
|
||||
@@ -724,6 +725,7 @@
|
||||
NWCLA000000000000000009 /* NWCActivityManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = NWCActivityManager.swift; path = zeus/NWCActivityManager.swift; sourceTree = "<group>"; };
|
||||
NWCLIS000000000000000003 /* NWCLiveActivityShared.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = NWCLiveActivityShared.swift; path = NWCWidget/NWCLiveActivityShared.swift; sourceTree = "<group>"; };
|
||||
NWCLIS000000000000000004 /* NWCWidgetIntent.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = NWCWidgetIntent.swift; path = NWCWidget/NWCWidgetIntent.swift; sourceTree = "<group>"; };
|
||||
NWCLIS000000000000000006 /* NWCAmbientTracks.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = NWCAmbientTracks.swift; path = NWCWidget/NWCAmbientTracks.swift; sourceTree = "<group>"; };
|
||||
/* End PBXFileReference section */
|
||||
|
||||
/* Begin PBXFileSystemSynchronizedBuildFileExceptionSet section */
|
||||
@@ -916,6 +918,7 @@
|
||||
NWC1A2B3C4D5E6F700000002 /* NWCAudioKeepAlive.m */,
|
||||
NWCLA000000000000000009 /* NWCActivityManager.swift */,
|
||||
NWCLIS000000000000000003 /* NWCLiveActivityShared.swift */,
|
||||
NWCLIS000000000000000006 /* NWCAmbientTracks.swift */,
|
||||
NWCLIS000000000000000004 /* NWCWidgetIntent.swift */,
|
||||
NWCLA000000000000000007 /* NWCWidgetAttributes.swift */,
|
||||
NWCAUDIO0000000000000015 /* Fireplace.m4a */,
|
||||
@@ -2079,6 +2082,7 @@
|
||||
NWCLA000000000000000001 /* NWCWidgetAttributes.swift in Sources */,
|
||||
NWCLA000000000000000003 /* NWCActivityManager.swift in Sources */,
|
||||
NWCLIS000000000000000001 /* NWCLiveActivityShared.swift in Sources */,
|
||||
NWCLIS000000000000000005 /* NWCAmbientTracks.swift in Sources */,
|
||||
NWCLIS000000000000000002 /* NWCWidgetIntent.swift in Sources */,
|
||||
745388442A54C2B6000927CE /* lightning.pb.swift in Sources */,
|
||||
74B637822A5A350B00750202 /* LncModule.mm in Sources */,
|
||||
|
||||
@@ -12,7 +12,7 @@ import UIKit
|
||||
|
||||
override private init() {
|
||||
super.init()
|
||||
endAllActivitiesBlocking()
|
||||
scheduleStaleActivityCleanupOnLaunch()
|
||||
}
|
||||
|
||||
@objc func startActivity(trackName: String, isMuted: Bool) {
|
||||
@@ -34,7 +34,12 @@ import UIKit
|
||||
}
|
||||
|
||||
@objc func endAllActivitiesImmediately() {
|
||||
endAllActivitiesBlocking()
|
||||
stopRefreshTimer()
|
||||
activity = nil
|
||||
Task.detached(priority: .userInitiated) {
|
||||
await Self.endEveryNWCLiveActivity()
|
||||
NSLog("[NWCActivity] ended all (immediate)")
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Private
|
||||
@@ -190,17 +195,14 @@ import UIKit
|
||||
refreshTimer = nil
|
||||
}
|
||||
|
||||
private func endAllActivitiesBlocking() {
|
||||
stopRefreshTimer()
|
||||
let sem = DispatchSemaphore(value: 0)
|
||||
Task.detached(priority: .userInitiated) {
|
||||
private func scheduleStaleActivityCleanupOnLaunch() {
|
||||
Task.detached(priority: .utility) {
|
||||
await Self.endEveryNWCLiveActivity()
|
||||
await MainActor.run { [weak self] in
|
||||
self?.activity = nil
|
||||
}
|
||||
sem.signal()
|
||||
NSLog("[NWCActivity] launch cleanup finished")
|
||||
}
|
||||
_ = sem.wait(timeout: .now() + 5)
|
||||
}
|
||||
|
||||
private static func endEveryNWCLiveActivity() async {
|
||||
|
||||
@@ -19,10 +19,6 @@ static NSString *const kDarwinPrevTrack = @"com.zeusln.zeus.nwc.prevTrack";
|
||||
static NSString *const kDarwinToggleMute = @"com.zeusln.zeus.nwc.toggleMute";
|
||||
static NSString *const kDarwinStop = @"com.zeusln.zeus.nwc.stop";
|
||||
|
||||
static NSArray<NSString *> *kAvailableTracks(void) {
|
||||
return @[@"Fireplace", @"White Noise", @"Gentle Rain"];
|
||||
}
|
||||
|
||||
@interface NWCAudioKeepAlive () <AVAudioPlayerDelegate>
|
||||
|
||||
@property (nonatomic, strong) AVAudioPlayer *audioPlayer;
|
||||
@@ -123,7 +119,7 @@ RCT_EXPORT_MODULE();
|
||||
_isActive = NO;
|
||||
_hasListeners = NO;
|
||||
_disconnectCount = 0;
|
||||
_trackNames = kAvailableTracks();
|
||||
_trackNames = [NWCAmbientTracks trackNames];
|
||||
_currentTrackIndex = 0;
|
||||
_isMuted = NO;
|
||||
_iosVersion = [[UIDevice currentDevice] systemVersion];
|
||||
|
||||
Reference in New Issue
Block a user