Skip to content

Commit

Permalink
Merge pull request #32 from sitomani/stability-fixes
Browse files Browse the repository at this point in the history
Stability fixes - addressing crash reports + deprecations
  • Loading branch information
sitomani committed Feb 17, 2024
2 parents b1e36a0 + adf3f70 commit a02d3d1
Show file tree
Hide file tree
Showing 12 changed files with 75 additions and 36 deletions.
19 changes: 12 additions & 7 deletions 4champ/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -100,20 +100,25 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
}

if components.path == "/mod", let idString = components.queryItems?.first?.value, let modId = Int(idString) {
dlController.rootViewController = UIApplication.shared.windows[0].rootViewController
guard let windowScene = UIApplication.shared.connectedScenes.first as? UIWindowScene,
let window = windowScene.windows.first else {
return false
}
dlController.rootViewController = window.rootViewController
dlController.show(modId: modId)
}

return true
}

func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey: Any] = [:]) -> Bool {
if url.scheme == "fourchamp" && url.host == "modules" {
if let idString = url.path.split(separator: "/").first, let modId = Int(idString) {
dlController.show(modId: modId)
DispatchQueue.main.async {
if url.scheme == "fourchamp" && url.host == "modules" {
if let idString = url.path.split(separator: "/").first, let modId = Int(idString) {
self.dlController.show(modId: modId)
}
} else {
self.dlController.showImport(for: [url])
}
} else {
dlController.showImport(for: [url])
}
return true
}
Expand Down
2 changes: 1 addition & 1 deletion 4champ/Replay/OpenMPT/MPTReplayer.m
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ - (NSArray*) getSamples
}
return sampleArray;
}

- (NSArray<NSString*>*) getInstruments
{
if (!currentOMPTFile) {
Expand Down
8 changes: 4 additions & 4 deletions 4champ/Replay/Replay.m
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ -(id)init
-(void) initAudio
{
//set up audio buffers for rendering
bufLeft = malloc(maxFrameSize * 2 * sizeof(UInt16));
bufRight = malloc(maxFrameSize * 2 * sizeof(UInt16));
bufLeft = malloc(maxFrameSize * 2 * sizeof(SInt16));
bufRight = malloc(maxFrameSize * 2 * sizeof(SInt16));

OSStatus status;

// Describe audio component
Expand All @@ -78,7 +78,7 @@ -(void) initAudio

// Get audio units
status = AudioComponentInstanceNew(inputComponent, &audioUnit);
//checkStatus(status);
checkStatus(status);

UInt32 flag = 1;
const int kOutputBus = 0;
Expand Down
2 changes: 1 addition & 1 deletion 4champ/Replay/UADE/UADEReplayer.m
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ - (int)currentPosition {
- (int)moduleLength {
if(ustate) {
const struct uade_song_info *info = uade_get_song_info(ustate);
return ustate->song.info.duration;
return info->duration;
}
return 0;
}
Expand Down
17 changes: 11 additions & 6 deletions 4champ/Scenes/About/AboutViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,16 @@ class AboutViewController: UIViewController, AboutDisplayLogic {
UIUtils.roundCornersInView(tableView)
navigationItem.title = "AboutView_Title".l13n().uppercased()

toggleNowPlaying(modulePlayer.status.rawValue > PlayerStatus.stopped.rawValue)

let img = UIImage(named: "favestar-grey")?.withRenderingMode(.alwaysTemplate)
let buttonItem = UIBarButtonItem.init(image: img, landscapeImagePhone: img, style: .plain, target: self, action: #selector(reviewNow))
self.navigationItem.leftBarButtonItem = buttonItem
}

override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
toggleNowPlaying(modulePlayer.status.rawValue > PlayerStatus.stopped.rawValue)
}

// MARK: Display Logic
func displayNowPlaying(_ viewModel: About.Status.ViewModel) {
}
Expand All @@ -88,12 +91,14 @@ class AboutViewController: UIViewController, AboutDisplayLogic {
}

extension AboutViewController: NowPlayingContainer {

func toggleNowPlaying(_ value: Bool) {
guard view.window != nil else { return }
log.debug("")
if value {
bottomAnchor?.constant = -(50.0 + 10.0)
} else {
bottomAnchor?.constant = -10.0
if value {
bottomAnchor?.constant = -(50.0 + 10.0)
} else {
bottomAnchor?.constant = -10.0
}
view.layoutIfNeeded()
}
Expand Down
10 changes: 9 additions & 1 deletion 4champ/Scenes/DownloadView/DownloadHostingController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import Foundation
import SwiftUI
import UniformTypeIdentifiers

enum ImportResultType {
case importSuccess
Expand Down Expand Up @@ -55,7 +56,14 @@ class DownloadController: NSObject, ObservableObject {
func selectImportModules(addToPlaylist: Bool = false) {
self.addToCurrentPlaylist = addToPlaylist
if documentPickerVC == nil {
documentPickerVC = UIDocumentPickerViewController(documentTypes: ["public.item"], in: .import)

if #available(iOS 14, *) {
let supportedTypes: [UTType] = [UTType.item]
documentPickerVC = UIDocumentPickerViewController(forOpeningContentTypes: supportedTypes)
} else {
let supportedTypes: [String] = ["public.item"]
documentPickerVC = UIDocumentPickerViewController(documentTypes: supportedTypes, in: .import)
}
documentPickerVC?.delegate = self
documentPickerVC?.modalPresentationStyle = .formSheet
documentPickerVC?.allowsMultipleSelection = true
Expand Down
2 changes: 1 addition & 1 deletion 4champ/Scenes/DownloadView/DownloadView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ struct ProgressBar: View {

Rectangle().frame(width: min(CGFloat(self.value)*geometry.size.width, geometry.size.width), height: geometry.size.height)
.foregroundColor(Color(UIColor.systemBlue))
.animation(.linear)
.animation(value > 0.01 ? .linear : nil, value: value)
}.cornerRadius(2)
}
}
Expand Down
2 changes: 1 addition & 1 deletion 4champ/Scenes/MainViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ extension MainViewController: UNUserNotificationCenterDelegate {
func userNotificationCenter(_ center: UNUserNotificationCenter,
willPresent notification: UNNotification,
withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
completionHandler([.alert, .badge, .sound])
completionHandler([.badge, .sound])
}

func userNotificationCenter(_ center: UNUserNotificationCenter,
Expand Down
8 changes: 6 additions & 2 deletions 4champ/Scenes/Playlists/PlaylistPresenter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,14 @@ class PlaylistPresenter: PlaylistPresentationLogic {
}

let vm = Playlists.Select.ViewModel(playlistName: name, shuffle: shuffle, modules: mods)
viewController?.displayPlaylist(viewModel: vm)
DispatchQueue.main.async {
self.viewController?.displayPlaylist(viewModel: vm)
}
}

func presentModeChange(shuffled: Bool) {
viewController?.displayModeChange(shuffled: shuffled)
DispatchQueue.main.async {
self.viewController?.displayModeChange(shuffled: shuffled)
}
}
}
4 changes: 3 additions & 1 deletion 4champ/Scenes/Radio/RadioPresenter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@ class RadioPresenter: RadioPresentationLogic {
}

func presentSessionHistoryInsert() {
self.viewController?.displaySessionHistoryInsert()
DispatchQueue.main.async {
self.viewController?.displaySessionHistoryInsert()
}
}

func presentPlaybackTime(length: Int, elapsed: Int) {
Expand Down
25 changes: 15 additions & 10 deletions 4champ/Utils/ModuleSharing.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ class ShareUtility: NSObject, UIActivityItemSource {
}

var sourceView: UIView?
if let mainVC = UIApplication.shared.windows[0].rootViewController as? MainViewController {
if let windowScene = UIApplication.shared.connectedScenes.first as? UIWindowScene,
let window = windowScene.windows.first, let mainVC = window.rootViewController as? MainViewController {
sourceView = mainVC.tabBar
}

Expand All @@ -64,17 +65,21 @@ class ShareUtility: NSObject, UIActivityItemSource {
}

static func topMostController() -> UIViewController? {
let window = UIApplication.shared.windows[0]
guard let rootViewController = window.rootViewController else {
return nil
}
guard let windowScene = UIApplication.shared.connectedScenes.first as? UIWindowScene,
let window = windowScene.windows.first else {
return nil
}

guard let rootViewController = window.rootViewController else {
return nil
}

var topController = rootViewController
var topController = rootViewController

while let newTopController = topController.presentedViewController {
topController = newTopController
}
while let newTopController = topController.presentedViewController {
topController = newTopController
}

return topController
return topController
}
}
12 changes: 11 additions & 1 deletion 4champ/Utils/ReviewActions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,16 @@
import Foundation
import StoreKit

extension SKStoreReviewController {
public static func requestReviewInCurrentScene() {
if let scene = UIApplication.shared.connectedScenes.first(where: { $0.activationState == .foregroundActive }) as? UIWindowScene {
DispatchQueue.main.async {
requestReview(in: scene)
}
}
}
}

/// Enumeration used to trigger AppStore review requests
enum ReviewActions: String {

Expand Down Expand Up @@ -46,7 +56,7 @@ enum ReviewActions: String {
return
}

SKStoreReviewController.requestReview()
SKStoreReviewController.requestReviewInCurrentScene()

// Reset the defaults
defaults.set(0, forKey: ReviewActions.noteworthyActionCount.rawValue)
Expand Down

0 comments on commit a02d3d1

Please sign in to comment.