Skip to content

Commit

Permalink
Improve emulator short version reading
Browse files Browse the repository at this point in the history
  • Loading branch information
Moonif committed May 6, 2023
1 parent e1ea6be commit cda1057
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 24 deletions.
4 changes: 2 additions & 2 deletions MacBox.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@
"@executable_path/../Frameworks",
);
MACOSX_DEPLOYMENT_TARGET = 10.14;
MARKETING_VERSION = 0.2.7;
MARKETING_VERSION = 0.2.8;
PRODUCT_BUNDLE_IDENTIFIER = Moonif.MacBox;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
Expand Down Expand Up @@ -414,7 +414,7 @@
"@executable_path/../Frameworks",
);
MACOSX_DEPLOYMENT_TARGET = 10.14;
MARKETING_VERSION = 0.2.7;
MARKETING_VERSION = 0.2.8;
PRODUCT_BUNDLE_IDENTIFIER = Moonif.MacBox;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
Expand Down
46 changes: 24 additions & 22 deletions MacBox/ViewControllers/MainViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ class MainViewController: NSViewController {
// Variables
private let userDefaults = UserDefaults.standard
private let homeDirURL = URL(fileURLWithPath: "MacBox", isDirectory: true, relativeTo: FileManager.default.homeDirectoryForCurrentUser)
private var emulatorUrl : URL?
var vmList: [VM] = []
private var currentSelectedVM: Int?
private var currentRunningVM: [RunningVMProcess] = []
Expand All @@ -39,6 +38,10 @@ class MainViewController: NSViewController {
private var currentVMConfigPath: String?
private let nameTextFieldMaxLimit: Int = 32
private var dragDropType = NSPasteboard.PasteboardType(rawValue: "private.table-row")
// 86Box emulator variables
private var emulatorUrl: URL?
private var emulatorAppVer: String = "0"
private var emulatorBuildVer: String = "0"

// View did load
override func viewDidLoad() {
Expand Down Expand Up @@ -193,24 +196,27 @@ class MainViewController: NSViewController {
// Check if 86Box is installed, and check for updated version
private func checkFor86Box() {
// Check if 86Box app is installed
var buildVer = "0"
if let bundleURL = NSWorkspace.shared.urlForApplication(withBundleIdentifier: "net.86Box.86Box") {
// Save 86Box emulator URL
emulatorUrl = bundleURL
// Get 86Box info.plist
if let bundle = Bundle(url: bundleURL) {
// Get the 86Box short version
if let shortVersion = bundle.infoDictionary?["CFBundleShortVersionString"] as? String {
emulatorAppVer = shortVersion
}
// Get the 86Box bundle version
if let bundleVersion = bundle.infoDictionary?["CFBundleVersion"] as? String {
buildVer = bundleVersion
emulatorBuildVer = String((bundleVersion).suffix(4))
}
}
}

fetch86BoxLatestBuildNumber(ver: buildVer)
fetch86BoxLatestBuildNumber()
}

// Fetch the latest stable 86Box build version from Jenkins
private func fetch86BoxLatestBuildNumber (ver: String) {
private func fetch86BoxLatestBuildNumber() {
// Check for internet connection
let monitor = NWPathMonitor()
let queue = DispatchQueue(label: "InternetConnectionMonitor")
Expand All @@ -223,52 +229,48 @@ class MainViewController: NSViewController {
guard let data = data else { return }
// Set status label
if let jenkinsBuildVer = String(data: data, encoding: .utf8) {
self.setVersionStatusLabel(localVer: ver, onlineVer: jenkinsBuildVer)
self.setVersionStatusLabel(onlineVer: jenkinsBuildVer)
}
else {
self.setVersionStatusLabel(localVer: ver, onlineVer: "0")
self.setVersionStatusLabel(onlineVer: "0")
}
}
task.resume()
}
}
else {
// We're offline, set status label to local version
self.setVersionStatusLabel(localVer: ver, onlineVer: "0")
self.setVersionStatusLabel(onlineVer: "0")
}
}

monitor.start(queue: queue)
}

// Set the 86Box version status label
private func setVersionStatusLabel (localVer: String, onlineVer: String) {
// Parse the app bundle version
let buildVer = String((localVer).suffix(4))
let appVer = String((localVer).prefix(3))

private func setVersionStatusLabel (onlineVer: String) {
DispatchQueue.main.async {
self.spinningProgressIndicator.stopAnimation(self)

// Check for local build
if buildVer == ".0.0" {
self.statusLabel.stringValue = "🟒 86Box \(appVer) (local build) is installed."
if self.emulatorBuildVer == ".0.0" {
self.statusLabel.stringValue = "🟒 86Box \(self.emulatorAppVer) (local build) is installed."
return
}

// Compare Jenkins version with local version
if onlineVer != buildVer {
if onlineVer != self.emulatorBuildVer {
// Version mismatch
self.statusLabel.stringValue = buildVer != "0" ? onlineVer != "0" ?
"🟠 86Box \(appVer) (build \(buildVer)) is installed. New update is available (build \(onlineVer))." :
"🟒 86Box \(appVer) (build \(buildVer)) is installed." :
self.statusLabel.stringValue = self.emulatorBuildVer != "0" ? onlineVer != "0" ?
"🟠 86Box \(self.emulatorAppVer) (build \(self.emulatorBuildVer)) is installed. New update is available (build \(onlineVer))." :
"🟒 86Box \(self.emulatorAppVer) (build \(self.emulatorBuildVer)) is installed." :
"πŸ”΄ 86Box is not installed."
}
else {
// Version match
self.statusLabel.stringValue = buildVer != "0" ? onlineVer != "0" ?
"🟒 86Box \(appVer) (build \(buildVer)) is installed and up-to-date." :
"🟒 86Box \(appVer) (build \(buildVer)) is installed." :
self.statusLabel.stringValue = self.emulatorBuildVer != "0" ? onlineVer != "0" ?
"🟒 86Box \(self.emulatorAppVer) (build \(self.emulatorBuildVer)) is installed and up-to-date." :
"🟒 86Box \(self.emulatorAppVer) (build \(self.emulatorBuildVer)) is installed." :
"πŸ”΄ 86Box is not installed."
}
}
Expand Down

0 comments on commit cda1057

Please sign in to comment.