Skip to content

Commit

Permalink
feat!: initial switch to xib
Browse files Browse the repository at this point in the history
Co-authored-by: Josh <36625023+JoshuaBrest@users.noreply.github.com>
  • Loading branch information
blackxfiied and JoshuaBrest committed Nov 14, 2024
1 parent 22639be commit 2abd633
Show file tree
Hide file tree
Showing 22 changed files with 1,613 additions and 39 deletions.
128 changes: 113 additions & 15 deletions Mythic.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

58 changes: 58 additions & 0 deletions Mythic/App/AppDelegate.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
//
// AppDelegate.swift
// Mythic
//
// Created by Josh on 10/23/24.
//

import Foundation
import AppKit

public class AppDelegate: NSObject, NSApplicationDelegate {
public static let shared = AppDelegate()

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

private let setupWindowController = SetupWindowController()
private let mainWindowController = MainWindowController()

/// Show the setup window
private func showSetupWindow() {
setupWindowController.show()
}

/// Hide the setup window
private func hideSetupWindow() {
setupWindowController.hide()
}

/// Show the main window
private func showMainWindow() {
mainWindowController.show()
}

/// Hide the main window
private func hideMainWindow() {
mainWindowController.hide()
}

/// Set the onboarding state
public func setOnboardingState(inOnboarding: Bool) {
if inOnboarding {
logger.info("Showing onboarding window...")
showSetupWindow()
hideMainWindow()
} else {
logger.info("Showing main window...")
hideSetupWindow()
showMainWindow()
}
}

public func applicationDidFinishLaunching(_ notification: Notification) {
NSApplication.shared.setActivationPolicy(.regular)

// TODO: A lot of work...
setOnboardingState(inOnboarding: true)
}
}
80 changes: 80 additions & 0 deletions Mythic/App/AppLogger.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
//
// AppLogger.swift
// Mythic
//
// Created by Josh on 10/23/24.
//

import Foundation
import OSLog

public struct AppLogger {
static let subsystem = Bundle.main.bundleIdentifier ?? "Mythic"
#if DEBUG
static let logLevel = LogLevel.debug
#else
static let logLevel = LogLevel.info
#endif

enum LogLevel: Int {
case debug = 0
case info = 1
case warning = 2
case error = 3
}

#if !DEBUG
private var logger: Logger
#endif
private var category: String

/// The category should be Class.self
public init(category: Any) {
self.category = "\(category)"
#if !DEBUG
self.logger = Logger(subsystem: AppLogger.subsystem, category: String(describing: category))
#endif
}

#if DEBUG
private func log(_ message: String, level: LogLevel) {
if level.rawValue <= AppLogger.logLevel.rawValue { return }
switch level {
case .debug:
print("\033[0;1;34m[🐞DEBUG \(self.category)]\033[0;34m \(message)")
case .info:
print("\033[0;1;32m[ℹ️INFO \(self.category)]\033[0;32m \(message)")
case .warning:
print("\033[0;1;33m[⚠️WARNING \(self.category)]\033[0;33m \(message)")
case .error:
print("\033[0;1;31m[🚨ERROR \(self.category)]\033[0;31m \(message)")
}
}
#else
private func log(_ message: String, level: LogLevel) {
if level.rawValue < AppLogger.logLevel.rawValue { return }
switch level {
case .debug:
logger.debug("\(message)")
case .info:
logger.info("\(message)")
case .warning:
logger.warning("\(message)")
case .error:
logger.error("\(message)")
}
}
#endif

public func debug(_ message: String) {
log(message, level: .debug)
}

public func info(_ message: String) {
log(message, level: .info)
}

public func warning(_ message: String) {
log(message, level: .warning)
}
}
675 changes: 675 additions & 0 deletions Mythic/App/MainMenu.xib

Large diffs are not rendered by default.

16 changes: 16 additions & 0 deletions Mythic/App/main.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//
// main.swift
// Mythic
//
// Created by Josh on 10/23/24.
//

import Foundation
import Cocoa

let app = NSApplication.shared
let delegate = AppDelegate()

app.delegate = delegate

_ = NSApplicationMain(CommandLine.argc, CommandLine.unsafeArgv)
6 changes: 4 additions & 2 deletions Mythic/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,17 @@
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>NSApplicationCrashOnExceptions</key>
<true/>
<key>NSMainNibFile</key>
<string>MainMenu</string>
<key>GCSupportedGameControllers</key>
<array>
<dict>
<key>ProfileName</key>
<string>ExtendedGamepad</string>
</dict>
</array>
<key>NSApplicationCrashOnExceptions</key>
<true/>
<key>SUFeedURL</key>
<string>https://getmythic.app/appcast.xml</string>
<key>SUPublicEDKey</key>
Expand Down
12 changes: 7 additions & 5 deletions Mythic/AppDelegate.swift → Mythic/Legacy/AppDelegate.old.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import Firebase
import FirebaseCore
import FirebaseCrashlytics

class AppDelegate: NSObject, NSApplicationDelegate { // https://arc.net/l/quote/zyfjpzpn
class LegacyAppDelegate: NSObject, NSApplicationDelegate { // https://arc.net/l/quote/zyfjpzpn
func applicationDidFinishLaunching(_: Notification) {
// Use the Firebase library to configure APIs.
FirebaseApp.configure()
Expand Down Expand Up @@ -269,7 +269,9 @@ class AppDelegate: NSObject, NSApplicationDelegate { // https://arc.net/l/quote/
if case .alertFirstButtonReturn = response {
do {
try Engine.remove()
let app = MythicApp() // FIXME: is this dangerous or just stupid

// MARK: TODO: FIXME: overhaul
let app = LegacyMythicApp() // FIXME: is this dangerous or just stupid
app.onboardingPhase = .engineDisclaimer
app.isOnboardingPresented = true
} catch {
Expand Down Expand Up @@ -347,11 +349,11 @@ class AppDelegate: NSObject, NSApplicationDelegate { // https://arc.net/l/quote/
}
}

extension AppDelegate: UNUserNotificationCenterDelegate {}
extension LegacyAppDelegate: UNUserNotificationCenterDelegate { }

extension AppDelegate: SPUUpdaterDelegate {} // FIXME: nonfunctional
extension LegacyAppDelegate: SPUUpdaterDelegate { }

extension AppDelegate: SwordRPCDelegate {
extension LegacyAppDelegate: SwordRPCDelegate {
func swordRPCDidConnect(_ rpc: SwordRPC) {
rpc.setPresence({
var presence: RichPresence = .init()
Expand Down
12 changes: 6 additions & 6 deletions Mythic/MythicApp.swift → Mythic/Legacy/MythicApp.old.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,20 @@ import SwiftUI
import Sparkle
import WhatsNewKit

@main
struct MythicApp: App {
@NSApplicationDelegateAdaptor(AppDelegate.self) var appDelegate
// @main // MARK: TODO: FIXME: overhaul
struct LegacyMythicApp: App {
@NSApplicationDelegateAdaptor(LegacyAppDelegate.self) var appDelegate

@AppStorage("isOnboardingPresented") var isOnboardingPresented: Bool = true
@State var onboardingPhase: OnboardingR2.Phase = .allCases.first!
@State var onboardingPhase: LegacyOnboardingView.Phase = .allCases.first!

@StateObject private var networkMonitor: NetworkMonitor = .shared
@StateObject private var sparkleController: SparkleController = .init()

var body: some Scene {
Window("Mythic", id: "main") {
if isOnboardingPresented {
OnboardingR2(fromPhase: onboardingPhase)
LegacyOnboardingView(fromPhase: onboardingPhase)
.contentTransition(.opacity)
.onAppear {
if let window = NSApp.mainWindow {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
import WhatsNewKit
import SwiftUI

extension MythicApp: WhatsNewCollectionProvider {
// MARK: TODO: FIXME: overhaul
extension LegacyMythicApp: WhatsNewCollectionProvider {
var whatsNewCollection: WhatsNewCollection {
WhatsNew(
version: "0.4.1",
Expand Down Expand Up @@ -121,5 +122,5 @@ extension MythicApp: WhatsNewCollectionProvider {
}

#Preview {
WhatsNewView(whatsNew: MythicApp().whatsNewCollection.last ?? WhatsNew(title: "N/A", features: []))
WhatsNewView(whatsNew: LegacyMythicApp().whatsNewCollection.last ?? WhatsNew(title: "N/A", features: []))
}
16 changes: 16 additions & 0 deletions Mythic/Legacy/main.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//
// main.swift
// Mythic
//
// Created by Josh on 10/23/24.
//

import Foundation
import Cocoa

let app = NSApplication.shared
let delegate = AppDelegate()

app.delegate = delegate

_ = NSApplicationMain(CommandLine.argc, CommandLine.unsafeArgv)
Loading

0 comments on commit 2abd633

Please sign in to comment.