Add support for tvOS

This commit is contained in:
世界
2023-07-29 09:44:31 +08:00
parent 5a8f3a770f
commit bb0385f53c
63 changed files with 1542 additions and 389 deletions
@@ -33,11 +33,13 @@ public struct ActiveDashboardView: View {
Text("Empty profiles")
} else {
VStack {
#if os(iOS)
#if os(iOS) || os(tvOS)
if ApplicationLibrary.inPreview || profile.status.isConnected {
ExtensionStatusView()
.listStyle(.automatic)
#if os(iOS)
.navigationBarTitleDisplayMode(.inline)
#endif
}
FormView {
StartStopButton()
@@ -50,7 +52,7 @@ public struct ActiveDashboardView: View {
.pickerStyle(.inline)
}
}
#else
#elseif os(macOS)
if ApplicationLibrary.inPreview || profile.status.isConnected {
ExtensionStatusView()
}
@@ -77,36 +79,48 @@ public struct ActiveDashboardView: View {
}
}
.alertBinding($alert)
#if os(iOS)
.onChange(of: scenePhase, perform: { newValue in
if newValue == .active {
Task.detached {
await doReload()
}
}
})
.onChange(of: selection.wrappedValue, perform: { newValue in
if newValue == .dashboard {
Task.detached {
await doReload()
}
}
})
#elseif os(macOS)
.onAppear {
if observer == nil {
observer = NotificationCenter.default.addObserver(forName: ActiveDashboardView.NotificationUpdateSelectedProfile, object: nil, queue: nil, using: { _ in
Task.detached {
await doReload()
.onChange(of: profile.status, perform: { newValue in
if newValue == .disconnecting || newValue == .connected {
Task.detached {
if let serviceError = try? String(contentsOf: ExtensionProvider.errorFile) {
DispatchQueue.main.async {
alert = Alert(errorMessage: serviceError)
}
})
try? FileManager.default.removeItem(at: ExtensionProvider.errorFile)
}
}
}
.onDisappear {
if let observer {
NotificationCenter.default.removeObserver(observer)
})
#if os(iOS) || os(tvOS)
.onChange(of: scenePhase, perform: { newValue in
if newValue == .active {
Task.detached {
await doReload()
}
}
})
.onChange(of: selection.wrappedValue, perform: { newValue in
if newValue == .dashboard {
Task.detached {
await doReload()
}
}
})
#elseif os(macOS)
.onAppear {
if observer == nil {
observer = NotificationCenter.default.addObserver(forName: ActiveDashboardView.NotificationUpdateSelectedProfile, object: nil, queue: nil, using: { _ in
Task.detached {
await doReload()
}
})
}
}
.onDisappear {
if let observer {
NotificationCenter.default.removeObserver(observer)
}
}
#endif
}
@@ -147,7 +161,7 @@ public struct ActiveDashboardView: View {
NotificationCenter.default.post(name: ActiveDashboardView.NotificationUpdateSelectedProfile, object: nil)
if profile.status.isConnected {
do {
try LibboxNewStandaloneCommandClient(FilePath.sharedDirectory.relativePath)?.serviceReload()
try LibboxNewStandaloneCommandClient()!.serviceReload()
} catch {
alert = Alert(error)
}
@@ -116,7 +116,7 @@ public struct ExtensionStatusView: View {
private func closeConnections() {
do {
try LibboxNewStandaloneCommandClient(FilePath.sharedDirectory.relativePath)?.closeConnections()
try LibboxNewStandaloneCommandClient()!.closeConnections()
} catch {
alert = Alert(error)
}
@@ -162,9 +162,13 @@ public struct ExtensionStatusView: View {
.font(.system(size: 16))
}
.frame(minWidth: 125)
.padding(EdgeInsets(top: 10, leading: 13, bottom: 10, trailing: 13))
.background(backgroundColor)
.cornerRadius(10)
#if os(tvOS)
.padding(EdgeInsets(top: 20, leading: 26, bottom: 20, trailing: 26))
#else
.padding(EdgeInsets(top: 10, leading: 13, bottom: 10, trailing: 13))
#endif
.background(backgroundColor)
.cornerRadius(10)
}
private var backgroundColor: Color {
@@ -172,6 +176,8 @@ public struct ExtensionStatusView: View {
return Color(uiColor: .secondarySystemGroupedBackground)
#elseif os(macOS)
return Color(nsColor: .textBackgroundColor)
#elseif os(tvOS)
return Color(uiColor: .black)
#endif
}
}
@@ -10,7 +10,7 @@ public struct StartStopButton: View {
public var body: some View {
viewBuilder {
if ApplicationLibrary.inPreview {
#if os(iOS)
#if os(iOS) || os(tvOS)
Toggle(isOn: .constant(true)) {
Text("Enabled")
}
@@ -23,7 +23,7 @@ public struct StartStopButton: View {
} else if let profile = extensionProfile.wrappedValue {
Button0(profile)
} else {
#if os(iOS)
#if os(iOS) || os(tvOS)
Toggle(isOn: .constant(false)) {
Text("Enabled")
}
@@ -49,7 +49,7 @@ public struct StartStopButton: View {
var body: some View {
viewBuilder {
#if os(iOS)
#if os(iOS) || os(tvOS)
Toggle(isOn: Binding(get: {
profile.status.isConnected
}, set: { newValue, _ in