mirror of
https://github.com/SideStore/SideStore.git
synced 2026-02-20 20:23:25 +01:00
[AltStore] Extends background fetch time until finished refreshing apps
Plays silent audio in background
This commit is contained in:
@@ -94,6 +94,8 @@
|
|||||||
BF770E5422BC044E002A40FE /* AppOperationContext.swift in Sources */ = {isa = PBXBuildFile; fileRef = BF770E5322BC044E002A40FE /* AppOperationContext.swift */; };
|
BF770E5422BC044E002A40FE /* AppOperationContext.swift in Sources */ = {isa = PBXBuildFile; fileRef = BF770E5322BC044E002A40FE /* AppOperationContext.swift */; };
|
||||||
BF770E5622BC3C03002A40FE /* Server.swift in Sources */ = {isa = PBXBuildFile; fileRef = BF770E5522BC3C02002A40FE /* Server.swift */; };
|
BF770E5622BC3C03002A40FE /* Server.swift in Sources */ = {isa = PBXBuildFile; fileRef = BF770E5522BC3C02002A40FE /* Server.swift */; };
|
||||||
BF770E5822BC3D0F002A40FE /* OperationGroup.swift in Sources */ = {isa = PBXBuildFile; fileRef = BF770E5722BC3D0F002A40FE /* OperationGroup.swift */; };
|
BF770E5822BC3D0F002A40FE /* OperationGroup.swift in Sources */ = {isa = PBXBuildFile; fileRef = BF770E5722BC3D0F002A40FE /* OperationGroup.swift */; };
|
||||||
|
BF770E6722BD57C4002A40FE /* BackgroundTaskManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = BF770E6622BD57C3002A40FE /* BackgroundTaskManager.swift */; };
|
||||||
|
BF770E6922BD57DD002A40FE /* Silence.m4a in Resources */ = {isa = PBXBuildFile; fileRef = BF770E6822BD57DD002A40FE /* Silence.m4a */; };
|
||||||
BF7B9EF322B82B1F0042C873 /* FetchAppsOperation.swift in Sources */ = {isa = PBXBuildFile; fileRef = BF7B9EF222B82B1F0042C873 /* FetchAppsOperation.swift */; };
|
BF7B9EF322B82B1F0042C873 /* FetchAppsOperation.swift in Sources */ = {isa = PBXBuildFile; fileRef = BF7B9EF222B82B1F0042C873 /* FetchAppsOperation.swift */; };
|
||||||
BF9B63C6229DD44E002F0A62 /* AltSign.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = BF9B63C5229DD44D002F0A62 /* AltSign.framework */; };
|
BF9B63C6229DD44E002F0A62 /* AltSign.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = BF9B63C5229DD44D002F0A62 /* AltSign.framework */; };
|
||||||
BFB11692229322E400BB457C /* DatabaseManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = BFB11691229322E400BB457C /* DatabaseManager.swift */; };
|
BFB11692229322E400BB457C /* DatabaseManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = BFB11691229322E400BB457C /* DatabaseManager.swift */; };
|
||||||
@@ -319,6 +321,8 @@
|
|||||||
BF770E5322BC044E002A40FE /* AppOperationContext.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppOperationContext.swift; sourceTree = "<group>"; };
|
BF770E5322BC044E002A40FE /* AppOperationContext.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppOperationContext.swift; sourceTree = "<group>"; };
|
||||||
BF770E5522BC3C02002A40FE /* Server.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Server.swift; sourceTree = "<group>"; };
|
BF770E5522BC3C02002A40FE /* Server.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Server.swift; sourceTree = "<group>"; };
|
||||||
BF770E5722BC3D0F002A40FE /* OperationGroup.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OperationGroup.swift; sourceTree = "<group>"; };
|
BF770E5722BC3D0F002A40FE /* OperationGroup.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OperationGroup.swift; sourceTree = "<group>"; };
|
||||||
|
BF770E6622BD57C3002A40FE /* BackgroundTaskManager.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BackgroundTaskManager.swift; sourceTree = "<group>"; };
|
||||||
|
BF770E6822BD57DD002A40FE /* Silence.m4a */ = {isa = PBXFileReference; lastKnownFileType = file; path = Silence.m4a; sourceTree = "<group>"; };
|
||||||
BF7B9EF222B82B1F0042C873 /* FetchAppsOperation.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FetchAppsOperation.swift; sourceTree = "<group>"; };
|
BF7B9EF222B82B1F0042C873 /* FetchAppsOperation.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FetchAppsOperation.swift; sourceTree = "<group>"; };
|
||||||
BF9B63C5229DD44D002F0A62 /* AltSign.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = AltSign.framework; sourceTree = BUILT_PRODUCTS_DIR; };
|
BF9B63C5229DD44D002F0A62 /* AltSign.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = AltSign.framework; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||||
BFB11691229322E400BB457C /* DatabaseManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DatabaseManager.swift; sourceTree = "<group>"; };
|
BFB11691229322E400BB457C /* DatabaseManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DatabaseManager.swift; sourceTree = "<group>"; };
|
||||||
@@ -742,6 +746,7 @@
|
|||||||
BFD2478B2284C4C300981D42 /* AppIconImageView.swift */,
|
BFD2478B2284C4C300981D42 /* AppIconImageView.swift */,
|
||||||
BFD2478E2284C8F900981D42 /* Button.swift */,
|
BFD2478E2284C8F900981D42 /* Button.swift */,
|
||||||
BF43002D22A714AF0051E2BC /* Keychain.swift */,
|
BF43002D22A714AF0051E2BC /* Keychain.swift */,
|
||||||
|
BF770E6622BD57C3002A40FE /* BackgroundTaskManager.swift */,
|
||||||
);
|
);
|
||||||
path = Components;
|
path = Components;
|
||||||
sourceTree = "<group>";
|
sourceTree = "<group>";
|
||||||
@@ -751,6 +756,7 @@
|
|||||||
children = (
|
children = (
|
||||||
BFB1169C22932DB100BB457C /* Apps.json */,
|
BFB1169C22932DB100BB457C /* Apps.json */,
|
||||||
BFD247762284B9A700981D42 /* Assets.xcassets */,
|
BFD247762284B9A700981D42 /* Assets.xcassets */,
|
||||||
|
BF770E6822BD57DD002A40FE /* Silence.m4a */,
|
||||||
);
|
);
|
||||||
path = Resources;
|
path = Resources;
|
||||||
sourceTree = "<group>";
|
sourceTree = "<group>";
|
||||||
@@ -1040,6 +1046,7 @@
|
|||||||
files = (
|
files = (
|
||||||
BFB1169D22932DB100BB457C /* Apps.json in Resources */,
|
BFB1169D22932DB100BB457C /* Apps.json in Resources */,
|
||||||
BFD2477A2284B9A700981D42 /* LaunchScreen.storyboard in Resources */,
|
BFD2477A2284B9A700981D42 /* LaunchScreen.storyboard in Resources */,
|
||||||
|
BF770E6922BD57DD002A40FE /* Silence.m4a in Resources */,
|
||||||
BFD247772284B9A700981D42 /* Assets.xcassets in Resources */,
|
BFD247772284B9A700981D42 /* Assets.xcassets in Resources */,
|
||||||
BFD247752284B9A500981D42 /* Main.storyboard in Resources */,
|
BFD247752284B9A500981D42 /* Main.storyboard in Resources */,
|
||||||
BFE6325A22A83BEB00F30809 /* Authentication.storyboard in Resources */,
|
BFE6325A22A83BEB00F30809 /* Authentication.storyboard in Resources */,
|
||||||
@@ -1205,6 +1212,7 @@
|
|||||||
BFD247702284B9A500981D42 /* AppsViewController.swift in Sources */,
|
BFD247702284B9A500981D42 /* AppsViewController.swift in Sources */,
|
||||||
BFDB6A0B22AAEDB7007EA6D6 /* Operation.swift in Sources */,
|
BFDB6A0B22AAEDB7007EA6D6 /* Operation.swift in Sources */,
|
||||||
BFB116A022933DEB00BB457C /* UpdatesViewController.swift in Sources */,
|
BFB116A022933DEB00BB457C /* UpdatesViewController.swift in Sources */,
|
||||||
|
BF770E6722BD57C4002A40FE /* BackgroundTaskManager.swift in Sources */,
|
||||||
BFBBE2DD22931B20002097FA /* AltStore.xcdatamodeld in Sources */,
|
BFBBE2DD22931B20002097FA /* AltStore.xcdatamodeld in Sources */,
|
||||||
BFE6325C22A83C0100F30809 /* AuthenticationViewController.swift in Sources */,
|
BFE6325C22A83C0100F30809 /* AuthenticationViewController.swift in Sources */,
|
||||||
BFB1169B2293274D00BB457C /* JSONDecoder+ManagedObjectContext.swift in Sources */,
|
BFB1169B2293274D00BB457C /* JSONDecoder+ManagedObjectContext.swift in Sources */,
|
||||||
|
|||||||
@@ -91,6 +91,12 @@ extension AppDelegate
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
BackgroundTaskManager.shared.performExtendedBackgroundTask { (taskResult, taskCompletionHandler) in
|
||||||
|
if let error = taskResult.error
|
||||||
|
{
|
||||||
|
print("Error starting extended background task.", error)
|
||||||
|
}
|
||||||
|
|
||||||
// Wait a few seconds so we have a chance to discover nearby AltServers.
|
// Wait a few seconds so we have a chance to discover nearby AltServers.
|
||||||
DispatchQueue.main.asyncAfter(deadline: .now() + 3.0) {
|
DispatchQueue.main.asyncAfter(deadline: .now() + 3.0) {
|
||||||
|
|
||||||
@@ -142,6 +148,8 @@ extension AppDelegate
|
|||||||
case .failure: completionHandler(.failed)
|
case .failure: completionHandler(.failed)
|
||||||
case .success: completionHandler(.newData)
|
case .success: completionHandler(.newData)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
taskCompletionHandler()
|
||||||
}
|
}
|
||||||
|
|
||||||
let group = AppManager.shared.refresh(installedApps, presentingViewController: nil)
|
let group = AppManager.shared.refresh(installedApps, presentingViewController: nil)
|
||||||
@@ -170,3 +178,4 @@ extension AppDelegate
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|||||||
102
AltStore/Components/BackgroundTaskManager.swift
Normal file
102
AltStore/Components/BackgroundTaskManager.swift
Normal file
@@ -0,0 +1,102 @@
|
|||||||
|
//
|
||||||
|
// BackgroundTaskManager.swift
|
||||||
|
// AltStore
|
||||||
|
//
|
||||||
|
// Created by Riley Testut on 6/19/19.
|
||||||
|
// Copyright © 2019 Riley Testut. All rights reserved.
|
||||||
|
//
|
||||||
|
|
||||||
|
import AVFoundation
|
||||||
|
|
||||||
|
class BackgroundTaskManager
|
||||||
|
{
|
||||||
|
static let shared = BackgroundTaskManager()
|
||||||
|
|
||||||
|
private var isPlaying = false
|
||||||
|
|
||||||
|
private let audioEngine: AVAudioEngine
|
||||||
|
private let player: AVAudioPlayerNode
|
||||||
|
private let audioFile: AVAudioFile
|
||||||
|
|
||||||
|
private let audioEngineQueue: DispatchQueue
|
||||||
|
|
||||||
|
private init()
|
||||||
|
{
|
||||||
|
self.audioEngine = AVAudioEngine()
|
||||||
|
self.audioEngine.mainMixerNode.outputVolume = 0.0
|
||||||
|
|
||||||
|
self.player = AVAudioPlayerNode()
|
||||||
|
self.audioEngine.attach(self.player)
|
||||||
|
|
||||||
|
do
|
||||||
|
{
|
||||||
|
let audioFileURL = Bundle.main.url(forResource: "Silence", withExtension: "m4a")!
|
||||||
|
|
||||||
|
self.audioFile = try AVAudioFile(forReading: audioFileURL)
|
||||||
|
self.audioEngine.connect(self.player, to: self.audioEngine.mainMixerNode, format: self.audioFile.processingFormat)
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
fatalError("Error. \(error)")
|
||||||
|
}
|
||||||
|
|
||||||
|
self.audioEngineQueue = DispatchQueue(label: "com.altstore.BackgroundTaskManager")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
extension BackgroundTaskManager
|
||||||
|
{
|
||||||
|
func performExtendedBackgroundTask(taskHandler: @escaping ((Result<Void, Error>, @escaping () -> Void) -> Void))
|
||||||
|
{
|
||||||
|
func finish()
|
||||||
|
{
|
||||||
|
self.player.stop()
|
||||||
|
self.audioEngine.stop()
|
||||||
|
|
||||||
|
self.isPlaying = false
|
||||||
|
}
|
||||||
|
|
||||||
|
self.audioEngineQueue.async {
|
||||||
|
do
|
||||||
|
{
|
||||||
|
try AVAudioSession.sharedInstance().setCategory(.playback, options: .mixWithOthers)
|
||||||
|
try AVAudioSession.sharedInstance().setActive(true)
|
||||||
|
|
||||||
|
// Schedule audio file buffers.
|
||||||
|
self.scheduleAudioFile()
|
||||||
|
self.scheduleAudioFile()
|
||||||
|
|
||||||
|
let outputFormat = self.audioEngine.outputNode.outputFormat(forBus: 0)
|
||||||
|
self.audioEngine.connect(self.audioEngine.mainMixerNode, to: self.audioEngine.outputNode, format: outputFormat)
|
||||||
|
|
||||||
|
try self.audioEngine.start()
|
||||||
|
self.player.play()
|
||||||
|
|
||||||
|
self.isPlaying = true
|
||||||
|
|
||||||
|
taskHandler(.success(())) {
|
||||||
|
finish()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
taskHandler(.failure(error)) {
|
||||||
|
finish()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private extension BackgroundTaskManager
|
||||||
|
{
|
||||||
|
func scheduleAudioFile()
|
||||||
|
{
|
||||||
|
self.player.scheduleFile(self.audioFile, at: nil) {
|
||||||
|
self.audioEngineQueue.async {
|
||||||
|
guard self.isPlaying else { return }
|
||||||
|
self.scheduleAudioFile()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -43,6 +43,7 @@
|
|||||||
<true/>
|
<true/>
|
||||||
<key>UIBackgroundModes</key>
|
<key>UIBackgroundModes</key>
|
||||||
<array>
|
<array>
|
||||||
|
<string>audio</string>
|
||||||
<string>fetch</string>
|
<string>fetch</string>
|
||||||
</array>
|
</array>
|
||||||
<key>UILaunchStoryboardName</key>
|
<key>UILaunchStoryboardName</key>
|
||||||
|
|||||||
BIN
AltStore/Resources/Silence.m4a
Normal file
BIN
AltStore/Resources/Silence.m4a
Normal file
Binary file not shown.
Reference in New Issue
Block a user