Skip to content

Commit

Permalink
fix: make window switches work properly.
Browse files Browse the repository at this point in the history
  • Loading branch information
JoshuaBrest committed Nov 12, 2024
1 parent 4e08b65 commit e7bbcec
Show file tree
Hide file tree
Showing 13 changed files with 123 additions and 83 deletions.
32 changes: 14 additions & 18 deletions Mythic.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@
EB7D07A22CC9C1550072D64E /* SetupWindow.xib in Resources */ = {isa = PBXBuildFile; fileRef = EB7D07A12CC9C1550072D64E /* SetupWindow.xib */; };
EB7D07A42CC9C1D90072D64E /* SetupWindowController.swift in Sources */ = {isa = PBXBuildFile; fileRef = EB7D07A32CC9C1D90072D64E /* SetupWindowController.swift */; };
EB7D07A72CC9C6980072D64E /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = EB7D07A62CC9C6980072D64E /* AppDelegate.swift */; };
EB7D07AA2CC9C6EB0072D64E /* MainWindow.xib in Resources */ = {isa = PBXBuildFile; fileRef = EB7D07A92CC9C6EB0072D64E /* MainWindow.xib */; };
EB7D07AC2CC9C7030072D64E /* MainWindowController.swift in Sources */ = {isa = PBXBuildFile; fileRef = EB7D07AB2CC9C7030072D64E /* MainWindowController.swift */; };
EB7D07AA2CC9C6EB0072D64E /* HubWindow.xib in Resources */ = {isa = PBXBuildFile; fileRef = EB7D07A92CC9C6EB0072D64E /* HubWindow.xib */; };
EB7D07AC2CC9C7030072D64E /* HubWindowController.swift in Sources */ = {isa = PBXBuildFile; fileRef = EB7D07AB2CC9C7030072D64E /* HubWindowController.swift */; };
EB7D07B82CC9E25F0072D64E /* main.swift in Sources */ = {isa = PBXBuildFile; fileRef = EB7D07B72CC9E25F0072D64E /* main.swift */; };
EB7D07C32CCAB5EF0072D64E /* EngineInstallerModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = EB7D07C22CCAB5EF0072D64E /* EngineInstallerModel.swift */; };
EB7D07C52CCAC28D0072D64E /* DirectoriesUtility.swift in Sources */ = {isa = PBXBuildFile; fileRef = EB7D07C42CCAC28D0072D64E /* DirectoriesUtility.swift */; };
Expand Down Expand Up @@ -206,8 +206,8 @@
EB7D07A12CC9C1550072D64E /* SetupWindow.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = SetupWindow.xib; sourceTree = "<group>"; };
EB7D07A32CC9C1D90072D64E /* SetupWindowController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SetupWindowController.swift; sourceTree = "<group>"; };
EB7D07A62CC9C6980072D64E /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
EB7D07A92CC9C6EB0072D64E /* MainWindow.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = MainWindow.xib; sourceTree = "<group>"; };
EB7D07AB2CC9C7030072D64E /* MainWindowController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MainWindowController.swift; sourceTree = "<group>"; };
EB7D07A92CC9C6EB0072D64E /* HubWindow.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = HubWindow.xib; sourceTree = "<group>"; };
EB7D07AB2CC9C7030072D64E /* HubWindowController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HubWindowController.swift; sourceTree = "<group>"; };
EB7D07B72CC9E25F0072D64E /* main.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = main.swift; sourceTree = "<group>"; };
EB7D07C22CCAB5EF0072D64E /* EngineInstallerModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EngineInstallerModel.swift; sourceTree = "<group>"; };
EB7D07C42CCAC28D0072D64E /* DirectoriesUtility.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DirectoriesUtility.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -494,7 +494,7 @@
EB7D079F2CC9C11C0072D64E /* Windows */ = {
isa = PBXGroup;
children = (
EB7D07A82CC9C6D60072D64E /* Main */,
EB7D07A82CC9C6D60072D64E /* Hub */,
EB7D07A02CC9C13B0072D64E /* Setup */,
);
path = Windows;
Expand All @@ -520,13 +520,13 @@
path = App;
sourceTree = "<group>";
};
EB7D07A82CC9C6D60072D64E /* Main */ = {
EB7D07A82CC9C6D60072D64E /* Hub */ = {
isa = PBXGroup;
children = (
EB7D07A92CC9C6EB0072D64E /* MainWindow.xib */,
EB7D07AB2CC9C7030072D64E /* MainWindowController.swift */,
EB7D07A92CC9C6EB0072D64E /* HubWindow.xib */,
EB7D07AB2CC9C7030072D64E /* HubWindowController.swift */,
);
path = Main;
path = Hub;
sourceTree = "<group>";
};
EB7D07C12CCAB5CE0072D64E /* Models */ = {
Expand Down Expand Up @@ -610,7 +610,7 @@
attributes = {
BuildIndependentTargetsInParallel = 1;
LastSwiftUpdateCheck = 1500;
LastUpgradeCheck = 1540;
LastUpgradeCheck = 1610;
TargetAttributes = {
6AB474942AACBBE900AB9C63 = {
CreatedOnToolsVersion = 15.0;
Expand Down Expand Up @@ -657,7 +657,7 @@
6A29356A2BFCFAFD0035CE4B /* Localizable.xcstrings in Resources */,
6A71D3D92BFD01AB00A2C74D /* legendary in Resources */,
6A2935682BFCFAFD0035CE4B /* Credits.rtf in Resources */,
EB7D07AA2CC9C6EB0072D64E /* MainWindow.xib in Resources */,
EB7D07AA2CC9C6EB0072D64E /* HubWindow.xib in Resources */,
EB7D07A22CC9C1550072D64E /* SetupWindow.xib in Resources */,
EBB8DBA62CE2F65A0005D181 /* exeIcon.icns in Resources */,
EBB8DBA82CE2F66B0005D181 /* GoogleService-Info.plist in Resources */,
Expand Down Expand Up @@ -740,19 +740,17 @@
6A2935662BFCFAFD0035CE4B /* AppDelegate1.swift in Sources */,
6A29355D2BFCFAFD0035CE4B /* InstallStatusView.swift in Sources */,
EB7D079A2CC982B10072D64E /* OnboardingView.swift in Sources */,
EB7D07AC2CC9C7030072D64E /* MainWindowController.swift in Sources */,
EB7D07AC2CC9C7030072D64E /* HubWindowController.swift in Sources */,
5A62AE982C27DB1200BA31D2 /* GameListEvoVM.swift in Sources */,
6A29354C2BFCFAFD0035CE4B /* LibraryView.swift in Sources */,
EB90A36E2CD982BB001F0871 /* OnboardingEpicGamesWelcomeStepView.swift in Sources */,
6A29354C2BFCFAFD0035CE4B /* LibraryView.swift in Sources */,
6A2935472BFCFAFD0035CE4B /* VariableManager.swift in Sources */,
EB90A3682CD9422B001F0871 /* OnboardingIntroStepView.swift in Sources */,
6A2935332BFCFAFD0035CE4B /* Engine.swift in Sources */,
6A0688442C2BCE8B004DF10F /* DownloadCard.swift in Sources */,
6A2935462BFCFAFD0035CE4B /* Rosetta.swift in Sources */,
6A2935532BFCFAFD0035CE4B /* StoreView.swift in Sources */,
EB90A3642CD941AB001F0871 /* OnboardingRosettaInstallationStepView.swift in Sources */,
6A2935532BFCFAFD0035CE4B /* StoreView.swift in Sources */,
6A29355F2BFCFAFD0035CE4B /* UninstallGameView.swift in Sources */,
EB90A3662CD941EF001F0871 /* OnboardingEpicGamesLoginStepView.swift in Sources */,
6A29355A2BFCFAFD0035CE4B /* ContainerSettingsView.swift in Sources */,
Expand Down Expand Up @@ -784,8 +782,6 @@
6A2935362BFCFAFD0035CE4B /* Color.swift in Sources */,
6A2935512BFCFAFD0035CE4B /* MainView.swift in Sources */,
EB7D07C92CCC52A80072D64E /* AppLoggerModel.swift in Sources */,
EB7D07C92CCC52A80072D64E /* AppLoggerModel.swift in Sources */,
6A2935512BFCFAFD0035CE4B /* MainView.swift in Sources */,
6A29353E2BFCFAFD0035CE4B /* LegendaryInterfaceExt.swift in Sources */,
6A71D3DD2BFD024D00A2C74D /* Auth.swift in Sources */,
6A29354B2BFCFAFD0035CE4B /* LocalImport.swift in Sources */,
Expand Down Expand Up @@ -949,7 +945,7 @@
"CODE_SIGN_IDENTITY[sdk=macosx*]" = "-";
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 3240;
CURRENT_PROJECT_VERSION = 3259;
DEAD_CODE_STRIPPING = YES;
DEVELOPMENT_ASSET_PATHS = "\"Sources/Preview Content\"";
DEVELOPMENT_TEAM = "";
Expand Down Expand Up @@ -996,7 +992,7 @@
"CODE_SIGN_IDENTITY[sdk=macosx*]" = "-";
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 3240;
CURRENT_PROJECT_VERSION = 3259;
DEAD_CODE_STRIPPING = YES;
DEVELOPMENT_ASSET_PATHS = "\"Sources/Preview Content\"";
DEVELOPMENT_TEAM = "";
Expand Down
2 changes: 1 addition & 1 deletion Mythic.xcodeproj/xcshareddata/xcschemes/Mythic.xcscheme
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1540"
LastUpgradeVersion = "1610"
version = "1.7">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
51 changes: 33 additions & 18 deletions Sources/App/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import Foundation
import AppKit
import Combine

public class AppDelegate: NSObject, NSApplicationDelegate {
public static let shared = AppDelegate()
Expand All @@ -14,19 +15,41 @@ public class AppDelegate: NSObject, NSApplicationDelegate {

private let logger = AppLoggerModel(category: AppDelegate.self)

private var cancellables: Set<AnyCancellable> = []

private let appMenuController = AppMenuController()

private enum RootWindowController {
case none
case setup(SetupWindowController)
case main(MainWindowController)
case hub(HubWindowController)
}
private var rootWindowController: RootWindowController = .none

override init() {
super.init()
}

/// Listen for events
private func listenEvents() {
// Flush old cancellables
let _ = cancellables.map({ $0.cancel() })
cancellables.removeAll()

// Listen for onboarding state changes
AppSettingsPersistentStateModel.shared.$store.map(\.inOnboarding).sink(receiveValue: { [self] inOnboarding in
if inOnboarding {
logger.info("Onboarding state active; switching to setup window.")
setupWindowController().show()
appMenuController.setRestartOnboardingVisibility(false)
} else {
logger.info("Onboarding state inactive; switching to main window.")
hubWindowController().show()
appMenuController.setRestartOnboardingVisibility(true)
}
}).store(in: &cancellables)
}

/// Get the setup window or switch to it.
private func setupWindowController() -> SetupWindowController {
switch rootWindowController {
Expand All @@ -40,21 +63,21 @@ public class AppDelegate: NSObject, NSApplicationDelegate {
}

/// Get the main window or switch to it.
private func mainWindowController() -> MainWindowController {
private func hubWindowController() -> HubWindowController {
switch rootWindowController {
case .main(let controller):
case .hub(let controller):
return controller
default:
let mainWindowController = MainWindowController()
rootWindowController = .main(mainWindowController)
return mainWindowController
let hubWindowController = HubWindowController()
rootWindowController = .hub(hubWindowController)
return hubWindowController
}
}

/// Restore the active main window.
private func restoreActiveRootWindow() {
switch rootWindowController {
case .main(let controller):
case .hub(let controller):
controller.show()
case .setup(let controller):
controller.show()
Expand All @@ -65,17 +88,9 @@ public class AppDelegate: NSObject, NSApplicationDelegate {
public func applicationDidFinishLaunching(_ notification: Notification) {
NSApplication.shared.setActivationPolicy(.regular)

// Listen for changes to AppSettingsPersistentStateModel.shared.store.inOnboarding
let onboardingListener = AppSettingsPersistentStateModel.shared.$store
.map(\.inOnboarding)
.sink { [weak self] inOnboarding in
self?.logger.info("Onboarding state changed to \(inOnboarding ? "in onboarding" : "not in onboarding").")
if inOnboarding {
self?.setupWindowController().show()
} else {
self?.mainWindowController().show()
}
}
Task {
listenEvents()
}
}

public func applicationWillFinishLaunching(_ notification: Notification) {
Expand Down
24 changes: 24 additions & 0 deletions Sources/App/AppMenuController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ public class AppMenuController {
/// The app delegate.
private var delegate: AppDelegate?
private var appMenu = NSMenu()
private var restartOnboardingMenuItem: NSMenuItem?

@objc protocol AppMenuControllerEditActions {
func undo(_ sender: Any?)
Expand Down Expand Up @@ -72,6 +73,7 @@ public class AppMenuController {
}
case about
case sparkleUpdater
case restartOnboarding
case preferences
case services
case hide
Expand All @@ -82,6 +84,7 @@ public class AppMenuController {
private static let localizedTitles: [AppNameMenuItems: LocalizedStringResource] = [
.about: "appMenu.app.about",
.sparkleUpdater: "appMenu.app.checkForUpdates",
.restartOnboarding: "appMenu.app.restartOnboarding",
.preferences: "appMenu.app.preferences",
.services: "appMenu.app.services",
.hide: "appMenu.app.hide",
Expand Down Expand Up @@ -221,10 +224,24 @@ public class AppMenuController {
@objc private func checkForUpdates() {
// todo
}

@objc private func restartOnboarding() {
AppSettingsPersistentStateModel.shared.store.inOnboarding = true
}

@objc private func openPreferences() {
// todo
}

/// Show or hide the `restartOnboarding` option.
public func setRestartOnboardingVisibility(_ visible: Bool) {
guard let restartOnboardingMenuItem = restartOnboardingMenuItem else {
return
}

restartOnboardingMenuItem.isHidden = !visible
restartOnboardingMenuItem.isEnabled = visible
}

/// Create the app menu
public func create(delegate: AppDelegate, app: NSApplication) -> NSMenu {
Expand All @@ -235,15 +252,22 @@ public class AppMenuController {
let appNameSubmenu = NSMenu()
let appMenuSelectors: [AppNameMenuItems: Selector] = [
.sparkleUpdater: #selector(checkForUpdates),
.restartOnboarding: #selector(restartOnboarding),
.preferences: #selector(openPreferences)
]
appMenu.addItem(appNameMenu)
for item in AppNameMenuItems.allCases {
let menuItem = item.create(appMenuSelectors[item])
if appMenuSelectors[item] != nil {
menuItem.target = self
}
appNameSubmenu.addItem(menuItem)
if AppNameMenuItems.dividerAfter.contains(item) {
appNameSubmenu.addItem(.separator())
}
if item == .restartOnboarding {
restartOnboardingMenuItem = menuItem
}
if item == .services {
let servicesMenu = NSMenu()
menuItem.submenu = servicesMenu
Expand Down
5 changes: 3 additions & 2 deletions Sources/App/MainMenu.xib
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="23094" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="23504" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="23094"/>
<deployment identifier="macosx"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="23504"/>
</dependencies>
<objects>
<customObject id="-2" userLabel="File's Owner" customClass="NSApplication"/>
Expand Down
37 changes: 21 additions & 16 deletions Sources/Localizable.xcstrings
Original file line number Diff line number Diff line change
Expand Up @@ -5661,6 +5661,9 @@
}
}
}
},
"appMenu.app.restartOnboarding" : {

},
"appMenu.app.services" : {
"localizations" : {
Expand Down Expand Up @@ -36386,6 +36389,7 @@
}
},
"onboardingEpicGamesLoginStepView.authCode" : {
"extractionState" : "stale",
"localizations" : {
"en" : {
"stringUnit" : {
Expand Down Expand Up @@ -36448,6 +36452,7 @@
}
},
"onboardingEpicGamesLoginStepView.getCode" : {
"extractionState" : "stale",
"localizations" : {
"en" : {
"stringUnit" : {
Expand Down Expand Up @@ -36495,6 +36500,22 @@
}
}
},
"onboardingIntroStepView.welcomeText" : {
"localizations" : {
"en" : {
"stringUnit" : {
"state" : "translated",
"value" : "Welcome to Mythic!"
}
},
"zh-Hans" : {
"stringUnit" : {
"state" : "translated",
"value" : "欢迎来到 Mythic!"
}
}
}
},
"onboardingRosettaInstallationStepView.description" : {
"localizations" : {
"en" : {
Expand Down Expand Up @@ -36573,22 +36594,6 @@
}
}
},
"onboardingView.introStep.welcomeText" : {
"localizations" : {
"en" : {
"stringUnit" : {
"state" : "translated",
"value" : "Welcome to Mythic!"
}
},
"zh-Hans" : {
"stringUnit" : {
"state" : "translated",
"value" : "欢迎来到 Mythic!"
}
}
}
},
"onboardingView.steps.engineSetup" : {
"localizations" : {
"en" : {
Expand Down
1 change: 1 addition & 0 deletions Sources/Views/Navigation/MainView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ struct MainView: View {
HomeView()
}
)

// .whatsNewSheet()
// .toolbar {
// ToolbarItem(placement: .automatic) {
Expand Down
Loading

0 comments on commit e7bbcec

Please sign in to comment.