Skip to content

Commit

Permalink
Merge pull request #110 from marcusziade/improve-settings-view
Browse files Browse the repository at this point in the history
Integrate updater settings into `SettingsView`
  • Loading branch information
vapidinfinity authored Jun 24, 2024
2 parents 5940904 + 4cac4a6 commit b4320ac
Show file tree
Hide file tree
Showing 8 changed files with 61 additions and 86 deletions.
8 changes: 4 additions & 4 deletions Mythic.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
objects = {

/* Begin PBXBuildFile section */
5A059CF82C2875D5004A19BF /* SparkleController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5A059CF72C2875D5004A19BF /* SparkleController.swift */; };
5A62AE982C27DB1200BA31D2 /* GameListEvoVM.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5A62AE972C27DB1200BA31D2 /* GameListEvoVM.swift */; };
5A62AE9C2C27E1C400BA31D2 /* GameList.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5A62AE9B2C27E1C400BA31D2 /* GameList.swift */; };
6A0C66852ABC4092004B0755 /* CachedAsyncImage in Frameworks */ = {isa = PBXBuildFile; productRef = 6A0C66842ABC4092004B0755 /* CachedAsyncImage */; };
Expand Down Expand Up @@ -61,7 +62,6 @@
6A2935622BFCFAFD0035CE4B /* NotImplementedView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6A2934EA2BFCFAFD0035CE4B /* NotImplementedView.swift */; };
6A2935632BFCFAFD0035CE4B /* WebView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6A2934EB2BFCFAFD0035CE4B /* WebView.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 @@ -96,6 +96,7 @@
/* End PBXCopyFilesBuildPhase section */

/* Begin PBXFileReference section */
5A059CF72C2875D5004A19BF /* SparkleController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SparkleController.swift; sourceTree = "<group>"; };
5A62AE972C27DB1200BA31D2 /* GameListEvoVM.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GameListEvoVM.swift; sourceTree = "<group>"; };
5A62AE9B2C27E1C400BA31D2 /* GameList.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GameList.swift; sourceTree = "<group>"; };
6A2934AE2BFCFAFD0035CE4B /* Preview Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = "Preview Assets.xcassets"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -148,7 +149,6 @@
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 /* 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 @@ -249,6 +249,7 @@
6A496A722C1AF75600FD637B /* Game.swift */,
6A2934C62BFCFAFD0035CE4B /* Global.swift */,
6A2934C72BFCFAFD0035CE4B /* NetworkMonitor.swift */,
5A059CF72C2875D5004A19BF /* SparkleController.swift */,
6A2934C82BFCFAFD0035CE4B /* Rosetta.swift */,
6A2934C92BFCFAFD0035CE4B /* VariableManager.swift */,
);
Expand Down Expand Up @@ -338,7 +339,6 @@
6A2934DA2BFCFAFD0035CE4B /* Navigation */,
6A2934EC2BFCFAFD0035CE4B /* Unified */,
6A2934ED2BFCFAFD0035CE4B /* OnboardingViewR2.swift */,
6A2934EE2BFCFAFD0035CE4B /* UpdaterSettingsView.swift */,
);
path = Views;
sourceTree = "<group>";
Expand Down Expand Up @@ -528,7 +528,6 @@
5A62AE982C27DB1200BA31D2 /* GameListEvoVM.swift in Sources */,
6A29354C2BFCFAFD0035CE4B /* Library.swift in Sources */,
6A2935472BFCFAFD0035CE4B /* VariableManager.swift in Sources */,
6A2935652BFCFAFD0035CE4B /* UpdaterSettingsView.swift in Sources */,
6A2935332BFCFAFD0035CE4B /* Engine.swift in Sources */,
6A2935462BFCFAFD0035CE4B /* Rosetta.swift in Sources */,
6A2935532BFCFAFD0035CE4B /* Store.swift in Sources */,
Expand All @@ -548,6 +547,7 @@
6A29355B2BFCFAFD0035CE4B /* GameSettingsView.swift in Sources */,
6A2935442BFCFAFD0035CE4B /* Global.swift in Sources */,
6A2935632BFCFAFD0035CE4B /* WebView.swift in Sources */,
5A059CF82C2875D5004A19BF /* SparkleController.swift in Sources */,
6A2935582BFCFAFD0035CE4B /* SubscriptedTextView.swift in Sources */,
6A2935542BFCFAFD0035CE4B /* Support.swift in Sources */,
6A29354E2BFCFAFD0035CE4B /* Bottles.swift in Sources */,
Expand Down
3 changes: 3 additions & 0 deletions Mythic/Localizable.xcstrings
Original file line number Diff line number Diff line change
Expand Up @@ -36369,6 +36369,9 @@
}
}
}
},
"Updater Settings" : {

},
"Verify File Integrity" : {

Expand Down
62 changes: 31 additions & 31 deletions Mythic/MythicApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,13 @@ struct MythicApp: App {
// MARK: - State Properties
@AppStorage("isOnboardingPresented") var isOnboardingPresented: Bool = true
@State var onboardingPhase: OnboardingR2.Phase = .allCases.first!
@StateObject var networkMonitor: NetworkMonitor = .init()
@StateObject private var networkMonitor: NetworkMonitor = .init()
@StateObject private var sparkleController: SparkleController = .init()

@State private var bootError: Error?

// MARK: - Updater Controller
private let updaterController: SPUStandardUpdaterController

// MARK: - Initialization
init() {
updaterController = SPUStandardUpdaterController(
startingUpdater: true,
updaterDelegate: nil,
userDriverDelegate: nil
)
}
@State private var automaticallyChecksForUpdates: Bool = false
@State private var automaticallyDownloadsUpdates: Bool = false

func toggleTitleBar(_ value: Bool) {
if let window = NSApp.windows.first {
Expand All @@ -52,30 +44,37 @@ struct MythicApp: App {
// MARK: - App Body
var body: some Scene {
Window("Mythic", id: "main") {
if isOnboardingPresented {
OnboardingR2(fromPhase: onboardingPhase)
.onAppear {
toggleTitleBar(false)

// Bring to front
if let window = NSApp.mainWindow {
window.makeKeyAndOrderFront(nil)
NSApp.activate(ignoringOtherApps: true)
Group {
if isOnboardingPresented {
OnboardingR2(fromPhase: onboardingPhase)
.onAppear {
toggleTitleBar(false)

// Bring to front
if let window = NSApp.mainWindow {
window.makeKeyAndOrderFront(nil)
NSApp.activate(ignoringOtherApps: true)
}
}
}
} else {
MainView()
.transition(.opacity)
.environmentObject(networkMonitor)
.frame(minWidth: 750, minHeight: 390)
.onAppear { toggleTitleBar(true) }
} else {
MainView()
.transition(.opacity)
.environmentObject(networkMonitor)
.environmentObject(sparkleController)
.frame(minWidth: 750, minHeight: 390)
.onAppear { toggleTitleBar(true) }
}
}
.onAppear {
automaticallyChecksForUpdates = sparkleController.updater.automaticallyChecksForUpdates
automaticallyDownloadsUpdates = sparkleController.updater.automaticallyDownloadsUpdates
}
}

.commands {
CommandGroup(after: .appInfo) {
Button("Check for Updates...", action: updaterController.updater.checkForUpdates)
.disabled(!updaterController.updater.canCheckForUpdates)
Button("Check for Updates...", action: sparkleController.updater.checkForUpdates)
.disabled(!sparkleController.updater.canCheckForUpdates)

if !isOnboardingPresented {
Button("Restart Onboarding...") {
Expand All @@ -89,12 +88,13 @@ struct MythicApp: App {

// MARK: - Settings View
Settings {
UpdaterSettingsView(updater: updaterController.updater)
SettingsView()
}
}
}

#Preview {
MainView()
.environmentObject(NetworkMonitor())
.environmentObject(SparkleController())
}
1 change: 1 addition & 0 deletions Mythic/Utilities/NetworkMonitor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,5 @@ final class NetworkMonitor: ObservableObject {
#Preview {
MainView()
.environmentObject(NetworkMonitor())
.environmentObject(SparkleController())
}
1 change: 1 addition & 0 deletions Mythic/Views/Navigation/Library/Library.swift
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,5 @@ struct LibraryView: View {
#Preview {
MainView()
.environmentObject(NetworkMonitor())
.environmentObject(SparkleController())
}
2 changes: 2 additions & 0 deletions Mythic/Views/Navigation/Main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import Combine
struct MainView: View {

@EnvironmentObject var networkMonitor: NetworkMonitor
@EnvironmentObject var sparkle: SparkleController
@ObservedObject private var variables: VariableManager = .shared
@ObservedObject private var operation: GameOperation = .shared

Expand Down Expand Up @@ -159,4 +160,5 @@ struct MainView: View {
#Preview {
MainView()
.environmentObject(NetworkMonitor())
.environmentObject(SparkleController())
}
19 changes: 19 additions & 0 deletions Mythic/Views/Navigation/Settings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ struct SettingsView: View {
@State private var isEpicSectionExpanded: Bool = true
@State private var isMythicSectionExpanded: Bool = true
@State private var isDefaultBottleSectionExpanded: Bool = true
@State private var isUpdaterSettingsExpanded: Bool = true

@EnvironmentObject var sparkle: SparkleController

@AppStorage("minimiseOnGameLaunch") private var minimize: Bool = false
@AppStorage("installBaseURL") private var installBaseURL: URL = Bundle.appGames!
@AppStorage("quitOnAppClose") private var quitOnClose: Bool = false
Expand Down Expand Up @@ -221,12 +224,27 @@ struct SettingsView: View {
}
}

Section("Updater Settings", isExpanded: $isUpdaterSettingsExpanded) {
VStack {
Toggle("Automatically check for updates", isOn: Binding(
get: { sparkle.updater.automaticallyChecksForUpdates },
set: { sparkle.updater.automaticallyChecksForUpdates = $0 }
))
Divider()
Toggle("Automatically download updates", isOn: Binding(
get: { sparkle.updater.automaticallyDownloadsUpdates },
set: { sparkle.updater.automaticallyDownloadsUpdates = $0 }
))
}
}

/* FIXME: TODO: Temporarily disabled; awaiting view that directly edits Wine.defaultBottleSettings.
Section("Default Bottle Settings", isExpanded: $isDefaultBottleSectionExpanded) {
// BottleSettingsView something
}
*/
}
.frame(minHeight: 750)
.task(priority: .background) {
discordRPC.setPresence({
var presence: RichPresence = .init()
Expand All @@ -245,4 +263,5 @@ struct SettingsView: View {

#Preview {
SettingsView()
.environmentObject(SparkleController())
}
51 changes: 0 additions & 51 deletions Mythic/Views/UpdaterSettingsView.swift

This file was deleted.

0 comments on commit b4320ac

Please sign in to comment.