Skip to content

Commit

Permalink
Hot fix
Browse files Browse the repository at this point in the history
  • Loading branch information
jordanbaird committed Jul 9, 2024
1 parent 0b49df3 commit 715bd3a
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 2 deletions.
1 change: 1 addition & 0 deletions Ice/Utilities/Defaults.swift
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ extension Defaults {

case hasMigrated0_8_0 = "hasMigrated0_8_0"
case hasMigrated0_10_0 = "hasMigrated0_10_0"
case hasMigrated0_10_1 = "hasMigrated0_10_1"

// MARK: Deprecated

Expand Down
81 changes: 79 additions & 2 deletions Ice/Utilities/MigrationManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// Ice
//

import Foundation
import Cocoa
import OSLog

@MainActor
Expand All @@ -22,8 +22,27 @@ extension MigrationManager {
migrate0_10_0,
])
} catch {
Logger.migration.error("Migration failed with error: \(error)")
logError(error)
}

let results = [
migrate0_10_1(),
]

for result in results {
switch result {
case .success:
break
case .successButShowAlert(let alert):
alert.runModal()
case .failureLoggingError(let error):
logError(error)
}
}
}

private func logError(_ error: any Error) {
Logger.migration.error("Migration failed with error: \(error)")
}
}

Expand Down Expand Up @@ -181,6 +200,54 @@ extension MigrationManager {
}
}

// MARK: - Migrate 0.10.1

extension MigrationManager {
/// Performs all migrations for the `0.10.1` release.
private func migrate0_10_1() -> MigrationResult {
guard !Defaults.bool(forKey: .hasMigrated0_10_1) else {
return .success
}
let result = migrateControlItems0_10_1()
switch result {
case .success, .successButShowAlert:
Defaults.set(true, forKey: .hasMigrated0_10_1)
Logger.migration.info("Successfully migrated to 0.10.1 settings")
case .failureLoggingError:
break
}
return result
}

private func migrateControlItems0_10_1() -> MigrationResult {
var needsResetPreferredPositions = false

for identifier in ControlItem.Identifier.allCases {
if
StatusItemDefaults[.isVisible, identifier.rawValue] == false,
StatusItemDefaults[.preferredPosition, identifier.rawValue] == nil
{
needsResetPreferredPositions = true
}
StatusItemDefaults[.isVisible, identifier.rawValue] = nil
}

if needsResetPreferredPositions {
for identifier in ControlItem.Identifier.allCases {
StatusItemDefaults[.preferredPosition, identifier.rawValue] = nil
}

let alert = NSAlert()
alert.messageText = "Due to a bug in the 0.10.0 release, the data for Ice's menu bar items was corrupted and their positions had to be reset."
alert.informativeText = "Our sincerest apologies for the inconvenience."

return .successButShowAlert(alert)
}

return .success
}
}

// MARK: - Helpers

extension MigrationManager {
Expand Down Expand Up @@ -215,6 +282,16 @@ extension MigrationManager {
}
}

// MARK: - MigrationResult

extension MigrationManager {
enum MigrationResult {
case success
case successButShowAlert(NSAlert)
case failureLoggingError(MigrationError)
}
}

// MARK: - MigrationError

extension MigrationManager {
Expand Down

0 comments on commit 715bd3a

Please sign in to comment.