Skip to content

Commit

Permalink
Merge branch 'main' into l10n_main
Browse files Browse the repository at this point in the history
  • Loading branch information
blackxfiied committed Jun 28, 2024
2 parents 4fa9918 + f7d30b2 commit 3321e0a
Show file tree
Hide file tree
Showing 64 changed files with 2,532 additions and 1,562 deletions.
70 changes: 46 additions & 24 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,33 +1,55 @@
name: Build

on:
push:
paths:
- '.github/workflows/build.yml'
- 'Mythic.xcodeproj/**'
- 'Mythic/**'
pull_request:
paths:
- '.github/workflows/build.yml'
- 'Mythic.xcodeproj/**'
- 'Mythic/**'
workflow_dispatch:
push:
paths:
- '.github/workflows/build.yml'
- 'Mythic.xcodeproj/**'
- 'Mythic/**'
pull_request:
paths:
- '.github/workflows/build.yml'
- 'Mythic.xcodeproj/**'
- 'Mythic/**'
workflow_dispatch:

jobs:
build:
build:
runs-on: macos-14

steps:
- uses: actions/checkout@v4

- name: Checkout repository
uses: actions/checkout@v4

- name: Debug - List directory contents
run: ls -R

- name: Debug - Print environment variables
run: env

- name: Install Command Line Tools for Xcode (if it's not installed)
run: |
if xcode-select --version >/dev/null 2>&1; then
echo "Xcode Command Line Tools is installed, skipping."
else
echo "Xcode Command Line Tools is not installed, installing."
xcode-select --install
fi
echo "Checking Xcode Command Line Tools..."
if xcode-select --version >/dev/null 2>&1; then
echo "Xcode Command Line Tools is installed, skipping."
else
echo "Xcode Command Line Tools is not installed, installing."
xcode-select --install
fi
- name: Debug - Xcode version
run: xcodebuild -version

- name: Debug - Available Xcode schemes
run: xcodebuild -list -project Mythic.xcodeproj

- name: Build
run: xcodebuild -scheme Mythic CODE_SIGNING_ALLOWED=NO SWIFTLINT=NO
run: |
echo "Starting build process..."
set -x # Enable command echoing
xcodebuild -scheme Mythic CODE_SIGNING_ALLOWED=NO SWIFTLINT=NO -verbose
set +x # Disable command echoing
- name: Debug - Build artifacts
if: failure()
run: |
echo "Listing build artifacts..."
ls -R ~/Library/Developer/Xcode/DerivedData
1 change: 1 addition & 0 deletions .swiftlint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ disabled_rules:
- cyclomatic_complexity
- trailing_whitespace
- todo
- opening_brace

opt_in_rules:
- toggle_bool
Expand Down
120 changes: 83 additions & 37 deletions Mythic.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

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 = "1520"
LastUpgradeVersion = "1540"
version = "1.7">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
166 changes: 127 additions & 39 deletions Mythic/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,54 +21,90 @@ import UserNotifications
import OSLog

class AppDelegate: NSObject, NSApplicationDelegate { // https://arc.net/l/quote/zyfjpzpn
var updaterController: SPUStandardUpdaterController?
var networkMonitor: NetworkMonitor?
var window: NSWindow!

func applicationDidFinishLaunching(_: Notification) {
setenv("CX_ROOT", Bundle.main.bundlePath, 1)

// MARK: initialize default UserDefaults Values
UserDefaults.standard.register(
defaults: [
"discordRPC": true
]
)
defaults.register(defaults: [
"discordRPC": true
])

// MARK: Bottle removal if folder was deleted externally
if let bottles = Wine.allBottles {
for (key, value) in bottles where !files.fileExists(atPath: value.url.path(percentEncoded: false)) {
Wine.allBottles?.removeValue(forKey: key)
// MARK: Bottle cleanup in the event of external deletion
Wine.bottleURLs = Wine.bottleURLs.filter { files.fileExists(atPath: $0.path(percentEncoded: false)) }

// MARK: 0.1.x bottle migration
if let data = defaults.data(forKey: "allBottles"),
let decodedData = try? PropertyListSerialization.propertyList(from: data, format: nil) as? [String: [String: Any]] {

Logger.app.log("Older bottle format detected, commencing bottle management system migration")

var iterations = 0
var convertedBottles: [Wine.Bottle] = .init()

for (name, bottle) in decodedData {
guard let urlArray = bottle["url"] as? [String: String], // unable to cast directly to URL
let relativeURL = urlArray["relative"],
let url: URL = .init(string: relativeURL.removingPercentEncoding ?? relativeURL) else {
return
}

var settings = Wine.defaultBottleSettings
guard let oldSettings = bottle["settings"] as? [String: Bool] else { Logger.file.warning("Unable to read old bottle settings; using default"); continue }
settings.metalHUD = oldSettings["metalHUD"] ?? settings.metalHUD
settings.msync = oldSettings["msync"] ?? settings.msync
settings.retinaMode = oldSettings["retinaMode"] ?? settings.retinaMode

DispatchQueue.main.async {
convertedBottles.append(.init(name: name, url: url, settings: settings))
Wine.bottleURLs.insert(url)
}

iterations += 1

Logger.app.log("converted \(url.prettyPath()) (\(iterations)/\(decodedData.count))")
}

Logger.file.notice("Bottle management system migration complete.")
defaults.removeObject(forKey: "allBottles")
}

if Engine.exists { _ = Wine.allBottles } // creates default bottle automatically because of custom getter
// MARK: DiscordRPC Connection and Delegation Setting
discordRPC.delegate = self
if defaults.bool(forKey: "discordRPC") { _ = discordRPC.connect() }

// MARK: Applications folder disclaimer
// TODO: possibly turn this into an onboarding-style message.
#if !DEBUG
let appURL = Bundle.main.bundleURL
let currentAppURL = Bundle.main.bundleURL
let optimalAppURL = FileLocations.globalApplications?.appendingPathComponent(currentAppURL.lastPathComponent)

// MARK: Move to Applications
if !appURL.pathComponents.contains("Applications") {
if !currentAppURL.pathComponents.contains("Applications") {
let alert = NSAlert()
alert.messageText = "Move Mythic to the Applications folder?"
alert.informativeText = "Mythic has detected it's running outside of the applications folder."
alert.addButton(withTitle: "Move")
alert.addButton(withTitle: "Cancel")

if alert.runModal() == .alertFirstButtonReturn, let globalApps = FileLocations.globalApplications {
do {
_ = try files.replaceItemAt(appURL, withItemAt: globalApps)
workspace.open(globalApps.appending(path: "Mythic.app")
)
} catch {
Logger.file.error("Unable to move Mythic to Applications: \(error)")

let error = NSAlert()
error.messageText = "Unable to move Mythic to \"\(globalApps.prettyPath())\"."
error.addButton(withTitle: "Quit")

if error.runModal() == .alertFirstButtonReturn {
exit(1)
if let window = NSApp.windows.first, let optimalAppURL = optimalAppURL {
alert.beginSheetModal(for: window) { response in
if case .alertFirstButtonReturn = response {
do {
_ = try files.replaceItemAt(optimalAppURL, withItemAt: currentAppURL)
workspace.open(optimalAppURL)
} catch {
Logger.file.error("Unable to move Mythic to Applications: \(error)")

let error = NSAlert()
error.messageText = "Unable to move Mythic to \"\(optimalAppURL.deletingLastPathComponent().prettyPath())\"."
error.addButton(withTitle: "Quit")

error.beginSheetModal(for: window) { response in
if case .alertFirstButtonReturn = response {
exit(1)
}
}
}
}
}
}
Expand All @@ -88,30 +124,78 @@ class AppDelegate: NSObject, NSApplicationDelegate { // https://arc.net/l/quote/
}
}

// MARK: DiscordRPC Connection and Delegation Setting
discordRPC.delegate = self
if defaults.bool(forKey: "discordRPC") { _ = discordRPC.connect() }
if Engine.needsUpdate() == true {
let alert = NSAlert()
alert.messageText = "Time for an update!"
alert.informativeText = "A new Mythic Engine update has released."
alert.addButton(withTitle: "Update")
alert.addButton(withTitle: "Cancel")

alert.showsHelp = true

if let window = NSApp.windows.first { // no alternative ATM, swift compiler is clueless.
alert.beginSheetModal(for: window) { response in
if case .alertFirstButtonReturn = response {
let confirmation = NSAlert()
confirmation.messageText = "Are you sure you want to update now?"
confirmation.informativeText = "Updating will remove the current version of Mythic Engine before installing the new one."
confirmation.addButton(withTitle: "Update")
confirmation.addButton(withTitle: "Cancel")

confirmation.beginSheetModal(for: window) { response in
if case .alertFirstButtonReturn = response {
do {
try Engine.remove()
let app = MythicApp() // FIXME: is this dangerous or just stupid
app.onboardingPhase = .engineDisclaimer
app.isOnboardingPresented = true
} catch {
let error = NSAlert()
error.alertStyle = .critical
error.messageText = "Unable to remove Mythic Engine."
error.addButton(withTitle: "Quit")

error.beginSheetModal(for: window) { response in
if case .OK = response {
exit(1)
}
}
}
}
}
}
}
}
}
}

func applicationShouldTerminate(_: NSApplication) -> NSApplication.TerminateReply {
var terminateReply: NSApplication.TerminateReply = .terminateNow

if GameOperation.shared.current != nil || !GameOperation.shared.queue.isEmpty {
let alert = NSAlert()
alert.messageText = "Are you sure you want to quit?"
alert.informativeText = "Mythic is still modifying games."
alert.alertStyle = .warning
alert.addButton(withTitle: "Quit")
alert.addButton(withTitle: "Cancel")
if alert.runModal() == .alertFirstButtonReturn {
return .terminateNow
} else {
return .terminateCancel

if let window = NSApp.windows.first {
alert.beginSheetModal(for: window) { response in
if case .alertFirstButtonReturn = response {
terminateReply = .terminateNow
} else {
terminateReply = .terminateLater
}
}
}
}

return .terminateNow
return terminateReply
}

func applicationWillTerminate(_: Notification) {
if defaults.bool(forKey: "quitOnAppClose") { Wine.killAll() }
if defaults.bool(forKey: "quitOnAppClose") { try? Wine.killAll() }
Legendary.stopAllCommands(forced: true)
}
}
Expand All @@ -120,6 +204,10 @@ extension AppDelegate: UNUserNotificationCenterDelegate {

}

extension AppDelegate: SPUUpdaterDelegate {

}

extension AppDelegate: SwordRPCDelegate {
func swordRPCDidConnect(_ rpc: SwordRPC) {
rpc.setPresence({
Expand Down
4 changes: 3 additions & 1 deletion Mythic/Assets.xcassets/EngineIcon.imageset/Contents.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
{
"images" : [
{
"filename" : "Engine Icon.png",
"filename" : "Engine-GPTKv2.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "[email protected]",
"idiom" : "universal",
"scale" : "2x"
},
{
"filename" : "[email protected]",
"idiom" : "universal",
"scale" : "3x"
}
Expand Down
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 3321e0a

Please sign in to comment.