1
1
mirror of https://github.com/danbee/persephone synced 2025-03-04 08:39:11 +00:00

Handle server connection on backgrounding

This commit is contained in:
Daniel Barber 2020-04-02 23:00:56 -04:00 committed by Dan Barber
parent f385d853ed
commit 71f2545972
Signed by: danbarber
GPG Key ID: 931D8112E0103DD8
5 changed files with 20 additions and 11 deletions

View File

@ -35,19 +35,21 @@ extension MPDClient {
self.delegate?.willDisconnect(mpdClient: self)
mpd_connection_free(self.connection)
self.isConnected = false
mpd_connection_free(self.connection)
self.isConnected = false
}
func connect(host: String, port: Int) {
let commandOperation = BlockOperation() { [unowned self] in
self.sendCommand(command: .connect, userData: ["host": host, "port": port])
if !isConnected {
let commandOperation = BlockOperation() { [unowned self] in
self.sendCommand(command: .connect, userData: ["host": host, "port": port])
if self.isConnected {
self.idle()
if self.isConnected {
self.idle()
}
}
commandQueue.addOperation(commandOperation)
}
commandQueue.addOperation(commandOperation)
}
func disconnect() {

View File

@ -11,7 +11,6 @@ import ReSwift
struct App {
static let store = Store<AppState>(reducer: appReducer, state: nil)
static let trackTimer = TrackTimer()
//static let userNotificationsController = UserNotificationsController()
static let mpdServerDelegate = MPDServerDelegate()
static let mpdServerController = MPDServerController(delegate: mpdServerDelegate)
static var mpdClient: MPDClient!

View File

@ -40,9 +40,6 @@ class AlbumViewController: UICollectionViewController {
}
@objc func willDisconnect() {
DispatchQueue.main.async {
App.store.dispatch(UpdateAlbumListAction(albums: []))
}
}
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {

View File

@ -0,0 +1,9 @@
//
// AlbumDetailFooterView.swift
// Persephone
//
// Created by Daniel Barber on 2020-4-2.
// Copyright © 2020 Dan Barber. All rights reserved.
//
import Foundation

View File

@ -29,11 +29,13 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate {
// This occurs shortly after the scene enters the background, or when its session is discarded.
// Release any resources associated with this scene that can be re-created the next time the scene connects.
// The scene may re-connect later, as its session was not neccessarily discarded (see `application:didDiscardSceneSessions` instead).
App.mpdServerController.disconnect()
}
func sceneDidBecomeActive(_ scene: UIScene) {
// Called when the scene has moved from an inactive state to an active state.
// Use this method to restart any tasks that were paused (or not yet started) when the scene was inactive.
App.mpdServerController.connect()
}
func sceneWillResignActive(_ scene: UIScene) {