refactor: Fix macOS standalone application
This commit is contained in:
@@ -39,10 +39,10 @@ public final class EditProfileContentViewModel: BaseViewModel {
|
||||
|
||||
private nonisolated func loadContentBackground() async throws {
|
||||
guard let profileID else {
|
||||
throw NSError(domain: "Context destroyed", code: 0)
|
||||
throw NSError(domain: "EditProfileContentViewModel", code: 0, userInfo: [NSLocalizedDescriptionKey: String(localized: "Context destroyed")])
|
||||
}
|
||||
guard let profile = try await ProfileManager.get(profileID) else {
|
||||
throw NSError(domain: "Profile missing", code: 0)
|
||||
throw NSError(domain: "EditProfileContentViewModel", code: 0, userInfo: [NSLocalizedDescriptionKey: String(localized: "Profile missing")])
|
||||
}
|
||||
let profileContent = try profile.read()
|
||||
await MainActor.run {
|
||||
|
||||
@@ -61,7 +61,7 @@
|
||||
do {
|
||||
message = try socket.read()
|
||||
} catch {
|
||||
throw NSError(domain: "read from connection: \(error.localizedDescription)", code: 0)
|
||||
throw NSError(domain: "ImportProfileViewModel", code: 0, userInfo: [NSLocalizedDescriptionKey: String(localized: "Read from connection: \(error.localizedDescription)")])
|
||||
}
|
||||
var error: NSError?
|
||||
switch Int64(message[0]) {
|
||||
@@ -71,7 +71,7 @@
|
||||
throw error
|
||||
}
|
||||
if let message {
|
||||
throw NSError(domain: "remote error: \(message.message)", code: 0)
|
||||
throw NSError(domain: "ImportProfileViewModel", code: 0, userInfo: [NSLocalizedDescriptionKey: String(localized: "Remote error: \(message.message)")])
|
||||
}
|
||||
case LibboxMessageTypeProfileList:
|
||||
let decoder = LibboxProfileDecoder()
|
||||
@@ -97,7 +97,7 @@
|
||||
try await importProfile(content!, environments: environments)
|
||||
return
|
||||
default:
|
||||
throw NSError(domain: "unknown message type \(message[0])", code: 0)
|
||||
throw NSError(domain: "ImportProfileViewModel", code: 0, userInfo: [NSLocalizedDescriptionKey: String(localized: "Unknown message type \(message[0])")])
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -243,17 +243,11 @@ public struct NewProfileMenuView: View {
|
||||
var error: NSError?
|
||||
let remoteProfile = LibboxParseRemoteProfileImportLink(string, &error)
|
||||
if let error {
|
||||
alert = AlertState(
|
||||
title: String(localized: "Invalid QR Code"),
|
||||
message: error.localizedDescription
|
||||
)
|
||||
alert = AlertState(error: error)
|
||||
return
|
||||
}
|
||||
guard let remoteProfile else {
|
||||
alert = AlertState(
|
||||
title: String(localized: "Invalid QR Code"),
|
||||
message: String(localized: "The QR code does not contain a valid profile import link.")
|
||||
)
|
||||
alert = AlertState(errorMessage: String(localized: "The QR code does not contain a valid profile import link."))
|
||||
return
|
||||
}
|
||||
importRequest = NewProfileView.ImportRequest(name: remoteProfile.name, url: remoteProfile.url)
|
||||
|
||||
@@ -111,10 +111,10 @@ public final class NewProfileViewModel: BaseViewModel {
|
||||
let profileConfig = profileConfigDirectory.appendingPathComponent("config_\(nextProfileID).json")
|
||||
if fileImport {
|
||||
guard let fileURL else {
|
||||
throw NSError(domain: "Missing file", code: 0)
|
||||
throw NSError(domain: "NewProfileViewModel", code: 0, userInfo: [NSLocalizedDescriptionKey: String(localized: "Missing file")])
|
||||
}
|
||||
if !fileURL.startAccessingSecurityScopedResource() {
|
||||
throw NSError(domain: "Missing access to selected file", code: 0)
|
||||
throw NSError(domain: "NewProfileViewModel", code: 0, userInfo: [NSLocalizedDescriptionKey: String(localized: "Missing access to selected file")])
|
||||
}
|
||||
defer {
|
||||
fileURL.stopAccessingSecurityScopedResource()
|
||||
|
||||
@@ -48,54 +48,54 @@ public struct QRSDisplayView: View {
|
||||
Text(String(localized: "FPS"))
|
||||
Spacer()
|
||||
#if os(tvOS)
|
||||
Button {
|
||||
fps = max(1, fps - 1)
|
||||
} label: {
|
||||
Image(systemName: "minus")
|
||||
}
|
||||
Text(verbatim: "\(Int(fps))")
|
||||
.foregroundStyle(.secondary)
|
||||
.frame(minWidth: 50)
|
||||
Button {
|
||||
fps = min(60, fps + 1)
|
||||
} label: {
|
||||
Image(systemName: "plus")
|
||||
}
|
||||
Button {
|
||||
fps = max(1, fps - 1)
|
||||
} label: {
|
||||
Image(systemName: "minus")
|
||||
}
|
||||
Text(verbatim: "\(Int(fps))")
|
||||
.foregroundStyle(.secondary)
|
||||
.frame(minWidth: 50)
|
||||
Button {
|
||||
fps = min(60, fps + 1)
|
||||
} label: {
|
||||
Image(systemName: "plus")
|
||||
}
|
||||
#else
|
||||
Text(verbatim: "\(Int(fps))")
|
||||
.foregroundStyle(.secondary)
|
||||
Text(verbatim: "\(Int(fps))")
|
||||
.foregroundStyle(.secondary)
|
||||
#endif
|
||||
}
|
||||
|
||||
#if !os(tvOS)
|
||||
Slider(value: $fps, in: 1 ... 60, step: 1)
|
||||
Slider(value: $fps, in: 1 ... 60, step: 1)
|
||||
#endif
|
||||
|
||||
HStack {
|
||||
Text(String(localized: "Slice Size"))
|
||||
Spacer()
|
||||
#if os(tvOS)
|
||||
Button {
|
||||
sliceSize = max(100, sliceSize - 100)
|
||||
} label: {
|
||||
Image(systemName: "minus")
|
||||
}
|
||||
Text("\(Int(sliceSize))")
|
||||
.foregroundStyle(.secondary)
|
||||
.frame(minWidth: 50)
|
||||
Button {
|
||||
sliceSize = min(1500, sliceSize + 100)
|
||||
} label: {
|
||||
Image(systemName: "plus")
|
||||
}
|
||||
Button {
|
||||
sliceSize = max(100, sliceSize - 100)
|
||||
} label: {
|
||||
Image(systemName: "minus")
|
||||
}
|
||||
Text("\(Int(sliceSize))")
|
||||
.foregroundStyle(.secondary)
|
||||
.frame(minWidth: 50)
|
||||
Button {
|
||||
sliceSize = min(1500, sliceSize + 100)
|
||||
} label: {
|
||||
Image(systemName: "plus")
|
||||
}
|
||||
#else
|
||||
Text("\(Int(sliceSize))")
|
||||
.foregroundStyle(.secondary)
|
||||
Text("\(Int(sliceSize))")
|
||||
.foregroundStyle(.secondary)
|
||||
#endif
|
||||
}
|
||||
|
||||
#if !os(tvOS)
|
||||
Slider(value: $sliceSize, in: 100 ... 1500, step: 100)
|
||||
Slider(value: $sliceSize, in: 100 ... 1500, step: 100)
|
||||
#endif
|
||||
}
|
||||
.padding(.horizontal)
|
||||
@@ -130,9 +130,9 @@ public struct QRSDisplayView: View {
|
||||
.padding(.horizontal)
|
||||
}
|
||||
#if os(macOS)
|
||||
.padding()
|
||||
.padding()
|
||||
#else
|
||||
.padding([.horizontal, .bottom])
|
||||
.padding([.horizontal, .bottom])
|
||||
#endif
|
||||
.onAppear {
|
||||
setupGenerator()
|
||||
|
||||
Reference in New Issue
Block a user