Skip to content

Commit

Permalink
Fix crash adding new server with scene actions (#1943)
Browse files Browse the repository at this point in the history
Fixes regression from #1941.

## Summary
The default value of `.max` isn't adjusted to a real one until after onboarding is finished, but we do a model fetch _during_ onboarding to test that it works.
  • Loading branch information
zacwest authored Nov 28, 2021
1 parent 8a6a48f commit a165444
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
4 changes: 3 additions & 1 deletion Sources/Shared/API/Server.swift
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public struct ServerInfo: Codable, Equatable {
version: Version
) {
self.name = name
self.sortOrder = .max
self.sortOrder = Self.defaultSortOrder
self.connection = connection
self.token = token
self.version = version
Expand All @@ -78,6 +78,8 @@ public struct ServerInfo: Codable, Equatable {
L10n.Settings.StatusSection.LocationNameRow.placeholder
}

public static var defaultSortOrder: Int { -1 }

public mutating func setSetting<T>(value: T?, for key: ServerSettingKey<T>) {
settings[key.rawValue] = value
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/Shared/API/ServerManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ internal final class ServerManagerImpl: ServerManager {
@discardableResult
public func add(identifier: Identifier<Server>, serverInfo: ServerInfo) -> Server {
let setValue = with(serverInfo) {
if $0.sortOrder == .max {
if $0.sortOrder == ServerInfo.defaultSortOrder {
$0.sortOrder = all.map(\.info.sortOrder).max().map { $0 + 1000 } ?? 0
}
}
Expand Down

0 comments on commit a165444

Please sign in to comment.