Skip to content

Commit

Permalink
Code refactor dump #1
Browse files Browse the repository at this point in the history
  • Loading branch information
vapidinfinity committed May 22, 2024
1 parent c4f75c8 commit 6d3890a
Show file tree
Hide file tree
Showing 17 changed files with 65 additions and 94 deletions.
22 changes: 11 additions & 11 deletions Mythic.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@
6A2935612BFCFAFD0035CE4B /* GameListEvoView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6A2934E92BFCFAFD0035CE4B /* GameListEvoView.swift */; };
6A2935622BFCFAFD0035CE4B /* NotImplementedView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6A2934EA2BFCFAFD0035CE4B /* NotImplementedView.swift */; };
6A2935632BFCFAFD0035CE4B /* WebView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6A2934EB2BFCFAFD0035CE4B /* WebView.swift */; };
6A2935642BFCFAFD0035CE4B /* OnboardingView+.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6A2934ED2BFCFAFD0035CE4B /* OnboardingView+.swift */; };
6A2935652BFCFAFD0035CE4B /* UpdaterSettings [TEMP].swift in Sources */ = {isa = PBXBuildFile; fileRef = 6A2934EE2BFCFAFD0035CE4B /* UpdaterSettings [TEMP].swift */; };
6A2935642BFCFAFD0035CE4B /* OnboardingViewR2.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6A2934ED2BFCFAFD0035CE4B /* OnboardingViewR2.swift */; };
6A2935652BFCFAFD0035CE4B /* UpdaterSettingsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6A2934EE2BFCFAFD0035CE4B /* UpdaterSettingsView.swift */; };
6A2935662BFCFAFD0035CE4B /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6A2934F02BFCFAFD0035CE4B /* AppDelegate.swift */; };
6A2935672BFCFAFD0035CE4B /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 6A2934F12BFCFAFD0035CE4B /* Assets.xcassets */; };
6A2935682BFCFAFD0035CE4B /* Credits.rtf in Resources */ = {isa = PBXBuildFile; fileRef = 6A2934F22BFCFAFD0035CE4B /* Credits.rtf */; };
Expand Down Expand Up @@ -140,8 +140,8 @@
6A2934E92BFCFAFD0035CE4B /* GameListEvoView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = GameListEvoView.swift; sourceTree = "<group>"; };
6A2934EA2BFCFAFD0035CE4B /* NotImplementedView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NotImplementedView.swift; sourceTree = "<group>"; };
6A2934EB2BFCFAFD0035CE4B /* WebView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = WebView.swift; sourceTree = "<group>"; };
6A2934ED2BFCFAFD0035CE4B /* OnboardingView+.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "OnboardingView+.swift"; sourceTree = "<group>"; };
6A2934EE2BFCFAFD0035CE4B /* UpdaterSettings [TEMP].swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UpdaterSettings [TEMP].swift"; sourceTree = "<group>"; };
6A2934ED2BFCFAFD0035CE4B /* OnboardingViewR2.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = OnboardingViewR2.swift; sourceTree = "<group>"; };
6A2934EE2BFCFAFD0035CE4B /* UpdaterSettingsView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UpdaterSettingsView.swift; sourceTree = "<group>"; };
6A2934F02BFCFAFD0035CE4B /* AppDelegate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
6A2934F12BFCFAFD0035CE4B /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
6A2934F22BFCFAFD0035CE4B /* Credits.rtf */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.rtf; path = Credits.rtf; sourceTree = "<group>"; };
Expand Down Expand Up @@ -292,6 +292,7 @@
6A2934DC2BFCFAFD0035CE4B /* GameCard.swift */,
6A2934DD2BFCFAFD0035CE4B /* GameInstallProgressView.swift */,
6A2934DE2BFCFAFD0035CE4B /* SubscriptedTextView.swift */,
6A2934EB2BFCFAFD0035CE4B /* WebView.swift */,
);
path = Models;
sourceTree = "<group>";
Expand Down Expand Up @@ -319,7 +320,6 @@
6A2934E82BFCFAFD0035CE4B /* BottleListView.swift */,
6A2934E92BFCFAFD0035CE4B /* GameListEvoView.swift */,
6A2934EA2BFCFAFD0035CE4B /* NotImplementedView.swift */,
6A2934EB2BFCFAFD0035CE4B /* WebView.swift */,
);
path = Unified;
sourceTree = "<group>";
Expand All @@ -329,8 +329,8 @@
children = (
6A2934DA2BFCFAFD0035CE4B /* Navigation */,
6A2934EC2BFCFAFD0035CE4B /* Unified */,
6A2934ED2BFCFAFD0035CE4B /* OnboardingView+.swift */,
6A2934EE2BFCFAFD0035CE4B /* UpdaterSettings [TEMP].swift */,
6A2934ED2BFCFAFD0035CE4B /* OnboardingViewR2.swift */,
6A2934EE2BFCFAFD0035CE4B /* UpdaterSettingsView.swift */,
);
path = Views;
sourceTree = "<group>";
Expand Down Expand Up @@ -501,14 +501,14 @@
6A29355D2BFCFAFD0035CE4B /* InstallStatusView.swift in Sources */,
6A29354C2BFCFAFD0035CE4B /* Library.swift in Sources */,
6A2935472BFCFAFD0035CE4B /* VariableManager.swift in Sources */,
6A2935652BFCFAFD0035CE4B /* UpdaterSettings [TEMP].swift in Sources */,
6A2935652BFCFAFD0035CE4B /* UpdaterSettingsView.swift in Sources */,
6A2935332BFCFAFD0035CE4B /* Engine.swift in Sources */,
6A2935462BFCFAFD0035CE4B /* Rosetta.swift in Sources */,
6A2935532BFCFAFD0035CE4B /* Store.swift in Sources */,
6A29355F2BFCFAFD0035CE4B /* UninstallGameView.swift in Sources */,
6A29355A2BFCFAFD0035CE4B /* BottleSettingsView.swift in Sources */,
6A2935572BFCFAFD0035CE4B /* GameInstallProgressView.swift in Sources */,
6A2935642BFCFAFD0035CE4B /* OnboardingView+.swift in Sources */,
6A2935642BFCFAFD0035CE4B /* OnboardingViewR2.swift in Sources */,
6A29353B2BFCFAFD0035CE4B /* URL.swift in Sources */,
6A2935382BFCFAFD0035CE4B /* Logger.swift in Sources */,
6A2935372BFCFAFD0035CE4B /* Data.swift in Sources */,
Expand Down Expand Up @@ -681,7 +681,7 @@
"CODE_SIGN_IDENTITY[sdk=macosx*]" = "Apple Development";
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 2639;
CURRENT_PROJECT_VERSION = 2642;
DEAD_CODE_STRIPPING = YES;
DEVELOPMENT_ASSET_PATHS = "\"Mythic/Preview Content\"";
DEVELOPMENT_TEAM = 67ZBY275P8;
Expand Down Expand Up @@ -726,7 +726,7 @@
"CODE_SIGN_IDENTITY[sdk=macosx*]" = "Apple Development";
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 2639;
CURRENT_PROJECT_VERSION = 2642;
DEAD_CODE_STRIPPING = YES;
DEVELOPMENT_ASSET_PATHS = "\"Mythic/Preview Content\"";
DEVELOPMENT_TEAM = 67ZBY275P8;
Expand Down
3 changes: 2 additions & 1 deletion Mythic/Localizable.xcstrings
Original file line number Diff line number Diff line change
Expand Up @@ -14359,6 +14359,7 @@
}
},
"Error launching %@." : {
"extractionState" : "stale",
"localizations" : {
"af" : {
"stringUnit" : {
Expand Down Expand Up @@ -39192,4 +39193,4 @@
}
},
"version" : "1.0"
}
}
2 changes: 1 addition & 1 deletion Mythic/Utilities/Engine/Engine.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import UserNotifications

// MARK: - Engine Class
/// Manages the installation, removal, and versioning of Mythic Engine.
class Engine {
final class Engine {
private static let log = Logger(
subsystem: Bundle.main.bundleIdentifier!,
category: "Engine"
Expand Down
2 changes: 1 addition & 1 deletion Mythic/Utilities/FileLocations.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import Foundation
import OSLog

// MARK: - File Locations Class
class FileLocations {
final class FileLocations {

// MARK: - Functions

Expand Down
17 changes: 9 additions & 8 deletions Mythic/Utilities/Legendary/LegendaryInterface.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,19 @@ import RegexBuilder

[Legendary GitHub Repository](https://github.com/derrod/legendary)
*/
class Legendary {
final class Legendary {

// MARK: - Properties

/// The file location for legendary's configuration files.
static let configLocation = Bundle.appHome!.appending(path: "Config").path

/// Logger instance for legendary.
public static let log = Logger(subsystem: Bundle.main.bundleIdentifier!, category: "legendaryInterface")
static let log = Logger(subsystem: Bundle.main.bundleIdentifier!, category: "legendaryInterface")

/// Cache for storing command outputs.
private static var commandCache: [String: (stderr: Data, stdout: Data)] = .init()

// MARK: runningCommands
private static var _runningCommands: [String: Process] = .init()
private static let _runningCommandsQueue = DispatchQueue(label: "legendaryRunningCommands", attributes: .concurrent)

Expand Down Expand Up @@ -75,7 +74,6 @@ class Legendary {
This function executes a command-line process with the specified arguments and waits for it to complete if `waits` is `true`.
It handles the process's standard input, standard output, and standard error, as well as any interactions based on the output provided by the `input` closure.
*/
@available(*, message: "Revamped recently")
static func command(arguments args: [String], identifier: String, waits: Bool = true, input: ((String) -> String?)? = nil, environment: [String: String]? = nil, completion: @escaping (CommandOutput) -> Void) async throws {
let task = Process()
task.executableURL = URL(filePath: Bundle.main.path(forResource: "legendary/cli", ofType: nil)!)
Expand Down Expand Up @@ -153,7 +151,11 @@ class Legendary {
}

/// Stops the execution of all commands.
static func stopAllCommands(forced: Bool) { runningCommands.keys.forEach { stopCommand(identifier: $0, forced: forced) } }
static func stopAllCommands(forced: Bool) {
runningCommands.keys.forEach {
stopCommand(identifier: $0, forced: forced)
}
}

// MARK: Install Method
/**
Expand Down Expand Up @@ -317,7 +319,7 @@ class Legendary {

static func signIn(authKey: String) async throws -> Bool {
return try await withCheckedThrowingContinuation { continuation in
Task.sync {
Task {
do {
var isLoggedIn = false

Expand All @@ -342,15 +344,14 @@ class Legendary {

- Parameters:
- game: The game to launch.
- bottle: The
*/
static func launch(game: Mythic.Game, online: Bool) async throws {
guard try Legendary.getInstalledGames().contains(game) else {
log.error("Unable to launch game, not installed or missing") // TODO: add alert in unified alert system
throw GameDoesNotExistError(game)
}

guard Engine.exists else { throw Engine.NotInstalledError() }
guard game.platform == .windows && Engine.exists else { throw Engine.NotInstalledError() }
guard let bottle = Wine.allBottles?[game.bottleName] else { throw Wine.BottleDoesNotExistError() }

DispatchQueue.main.async {
Expand Down
2 changes: 1 addition & 1 deletion Mythic/Utilities/Legendary/LegendaryInterfaceExt.swift
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ extension Legendary {
let stderr: (String) -> Void
}

class CommandOutput {
final class CommandOutput {
var stdout: String = .init()
var stderr: String = .init()
}
Expand Down
2 changes: 1 addition & 1 deletion Mythic/Utilities/Local/LocalGames.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import Foundation
import SwiftUI
import OSLog

class LocalGames {
final class LocalGames {
public static let log = Logger(subsystem: Bundle.main.bundleIdentifier!, category: "localGames")

// TODO: DocC
Expand Down
3 changes: 1 addition & 2 deletions Mythic/Utilities/NetworkMonitor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import Network
import SwiftUI

@Observable
class NetworkMonitor: ObservableObject {
final class NetworkMonitor: ObservableObject {
private let networkMonitor = NWPathMonitor()
private let queue = DispatchQueue(label: "NetworkMonitor")

Expand Down Expand Up @@ -51,7 +51,6 @@ class NetworkMonitor: ObservableObject {
guard error == nil, let httpResponse = response as? HTTPURLResponse else { self.updateAccessibility(false); return }
self.updateAccessibility((200...299) ~= httpResponse.statusCode)
}.resume()

}
}
networkMonitor.start(queue: queue)
Expand Down
2 changes: 1 addition & 1 deletion Mythic/Utilities/Rosetta.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import Foundation

class Rosetta {
final class Rosetta {
static var exists: Bool { files.fileExists(atPath: "/Library/Apple/usr/share/rosetta") }

struct AgreementFailure: LocalizedError {
Expand Down
33 changes: 16 additions & 17 deletions Mythic/Utilities/Wine/WineInterface.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import Foundation
import OSLog

class Wine { // TODO: https://forum.winehq.org/viewtopic.php?t=15416
final class Wine { // TODO: https://forum.winehq.org/viewtopic.php?t=15416
// FIXME: TODO: all funcs should take urls as params not bottles
// MARK: - Variables

Expand Down Expand Up @@ -89,7 +89,7 @@ class Wine { // TODO: https://forum.winehq.org/viewtopic.php?t=15416
}

static var defaultBottleSettings: BottleSettings {
get { return defaults.object(forKey: "defaultBottleSettings") as? BottleSettings ?? .init(metalHUD: false, msync: true, retinaMode: true) }
get { return defaults.object(forKey: "defaultBottleSettings") as? BottleSettings ?? .init(metalHUD: false, msync: true, retinaMode: true, windowsVersion: .win11) }
set { defaults.set(newValue, forKey: "defaultBottleSettings") }
}

Expand Down Expand Up @@ -151,7 +151,6 @@ class Wine { // TODO: https://forum.winehq.org/viewtopic.php?t=15416
This function executes a command-line process with the specified arguments and waits for it to complete if `waits` is `true`.
It handles the process's standard input, standard output, and standard error, as well as any interactions based on the output provided by the `input` closure.
*/
@available(*, message: "Revamped recently")
static func command(arguments args: [String], identifier: String, waits: Bool = true, bottleURL: URL?, input: ((String) -> String?)? = nil, environment: [String: String]? = nil, completion: @escaping (Legendary.CommandOutput) -> Void) async throws {
let task = Process()
task.executableURL = Engine.directory.appending(path: "wine/bin/wine64")
Expand Down Expand Up @@ -352,11 +351,7 @@ class Wine { // TODO: https://forum.winehq.org/viewtopic.php?t=15416
task.waitUntilExit()

var error: NSDictionary?
if let scriptObject = NSAppleScript(
source: """
do shell script \"sudo rm -rf \(d3dmcache)\" with administrator privileges
""") {

if let scriptObject = NSAppleScript(source: "do shell script \"sudo rm -rf \(d3dmcache)\" with administrator privileges") {
let output = scriptObject.executeAndReturnError(&error)
Logger.app.debug("output from shader cache purge: \(output.stringValue ?? "none")")

Expand Down Expand Up @@ -407,15 +402,19 @@ class Wine { // TODO: https://forum.winehq.org/viewtopic.php?t=15416
}
}

static func getRetinaMode(bottleURL: URL, completion: @escaping (Result<Bool, Error>) -> Void) async {
await Wine.queryRegistryKey(
bottleURL: bottleURL, key: RegistryKey.macDriver.rawValue, name: "RetinaMode", type: .string
) { result in
switch result {
case .success(let value):
completion(.success(value == "y"))
case .failure(let error):
completion(.failure(error))
static func getRetinaMode(bottleURL: URL) async throws -> Bool {
return try await withCheckedThrowingContinuation { continuation in
Task {
await Wine.queryRegistryKey(
bottleURL: bottleURL, key: RegistryKey.macDriver.rawValue, name: "RetinaMode", type: .string
) { result in
switch result {
case .success(let value):
continuation.resume(returning: value == "y")
case .failure(let error):
continuation.resume(throwing: error)
}
}
}
}
}
Expand Down
11 changes: 5 additions & 6 deletions Mythic/Utilities/Wine/WineInterfaceExt.swift
Original file line number Diff line number Diff line change
Expand Up @@ -70,20 +70,19 @@ extension Wine {
struct BottleSettings: Codable, Hashable {
var metalHUD: Bool
var msync: Bool
var retinaMode: Bool // TODO: FIXME: turn into func
// var windowsVersion: WindowsVersion
var retinaMode: Bool
var windowsVersion: WindowsVersion
}

enum WindowsVersion: String, Codable {
case win11 = "11"
case win10 = "10"
case win8_1 = "8.1" // swiftlint:disable:this identifier_name
case win81 = "8.1"
case win8 = "8"
case win7 = "7"
case win2008 = "2008"
case winvista = "Vista"
case win2003 = "2003"
case vista = "Vista"
case winxp = "XP"
case win98 = "98"
}

enum BottleScope: String, CaseIterable {
Expand Down
20 changes: 0 additions & 20 deletions Mythic/Views/Navigation/Home.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,6 @@ import SwordRPC
The main view displaying the home screen of the Mythic app.
*/
struct HomeView: View {
enum ActiveAlert {
case launchError
}

struct LaunchError {
static var message: String = .init()
static var game: Game? = nil // swiftlint:disable:this redundant_optional_initialization
}

// MARK: - State Variables
@ObservedObject private var variables: VariableManager = .shared
@EnvironmentObject var networkMonitor: NetworkMonitor
@AppStorage("minimiseOnGameLaunch") private var minimizeOnGameLaunch: Bool = false
Expand All @@ -47,7 +37,6 @@ struct HomeView: View {
@State private var urlString = "https://store.epicgames.com/"

@State private var isAlertPresented: Bool = false
@State private var activeAlert: ActiveAlert = .launchError

@Environment(\.colorScheme) var colorScheme

Expand Down Expand Up @@ -96,15 +85,6 @@ struct HomeView: View {
}
.navigationTitle("Home")
.padding()
.alert(isPresented: $isAlertPresented) {
switch activeAlert {
case .launchError:
Alert(
title: Text("Error launching \(LaunchError.game?.title ?? "game")."),
message: Text(LaunchError.message)
)
}
}
.task(priority: .background) {
discordRPC.setPresence({
var presence: RichPresence = .init()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import ColorfulX
import SwordRPC
import UserNotifications

struct OnboardingR2: View {
struct OnboardingR2: View { // TODO: ViewModel

init(fromPhase: Phase = .logo) {
self.currentPhase = fromPhase
Expand Down
Loading

0 comments on commit 6d3890a

Please sign in to comment.