Remove ignoreDeviceSleep && Improve delete button on macOS
This commit is contained in:
@@ -20,11 +20,11 @@ public enum ProfileUpdateTask {
|
||||
if updateInterval < minUpdateInterval {
|
||||
updateInterval = minUpdateInterval
|
||||
}
|
||||
timer = Timer(fire: calculateEarliestBeginDate(profiles), interval: updateInterval, repeats: true, block: { _ in
|
||||
timer = Timer(fire: calculateEarliestBeginDate(profiles), interval: updateInterval, repeats: true) { _ in
|
||||
Task {
|
||||
await getAndupdateProfiles()
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
static func calculateEarliestBeginDate(_ profiles: [Profile]) -> Date {
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
import Foundation
|
||||
import SwiftUI
|
||||
|
||||
public struct DeleteButton<Label>: View where Label: View {
|
||||
private let action: () async -> Void
|
||||
private let label: Label
|
||||
|
||||
@State private var performDelete = false
|
||||
@State private var timer: Timer?
|
||||
@State private var isLoading = false
|
||||
|
||||
public init(action: @escaping () async -> Void, @ViewBuilder label: () -> Label) {
|
||||
self.action = action
|
||||
self.label = label()
|
||||
}
|
||||
|
||||
public var body: some View {
|
||||
Button(role: .destructive) {
|
||||
isLoading = true
|
||||
if let timer {
|
||||
timer.invalidate()
|
||||
}
|
||||
if !performDelete {
|
||||
performDelete = true
|
||||
timer = Timer.scheduledTimer(withTimeInterval: 3, repeats: false) { _ in
|
||||
timer = nil
|
||||
performDelete = false
|
||||
}
|
||||
isLoading = true
|
||||
} else {
|
||||
Task {
|
||||
await action()
|
||||
isLoading = false
|
||||
performDelete = false
|
||||
}
|
||||
}
|
||||
} label: {
|
||||
if !performDelete {
|
||||
label
|
||||
} else {
|
||||
label.foregroundStyle(.red)
|
||||
}
|
||||
}
|
||||
.disabled(isLoading)
|
||||
}
|
||||
}
|
||||
@@ -22,7 +22,7 @@
|
||||
|
||||
@State private var isLoading = true
|
||||
@State private var profile: Profile!
|
||||
@State private var profileContent: String = ""
|
||||
@State private var profileContent = ""
|
||||
@State private var isChanged = false
|
||||
@State private var alert: Alert?
|
||||
|
||||
@@ -70,9 +70,15 @@
|
||||
await saveContent()
|
||||
}
|
||||
} label: {
|
||||
Image("save", label: Text("Save"))
|
||||
Label("Save", image: "save")
|
||||
}
|
||||
.disabled(!isChanged)
|
||||
} else {
|
||||
Button {
|
||||
NSPasteboard.general.setString(profileContent, forType: .fileContents)
|
||||
} label: {
|
||||
Label("Copy", systemImage: "clipboard.fill")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -85,6 +91,10 @@
|
||||
await saveContent()
|
||||
}
|
||||
}.disabled(!isChanged)
|
||||
} else {
|
||||
Button("Copy") {
|
||||
UIPasteboard.general.string = profileContent
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -324,7 +324,6 @@ public struct ProfileView: View {
|
||||
}
|
||||
} label: {
|
||||
Label("Delete", systemImage: "trash.fill")
|
||||
.foregroundColor(.red)
|
||||
}
|
||||
}
|
||||
#else
|
||||
|
||||
@@ -31,7 +31,7 @@ public struct CoreView: View {
|
||||
Label("Open", systemImage: "macwindow.and.cursorarrow")
|
||||
}
|
||||
#endif
|
||||
FormButton {
|
||||
FormButton(role: .destructive) {
|
||||
Task {
|
||||
await destroyWorkingDirectory()
|
||||
}
|
||||
|
||||
@@ -64,7 +64,7 @@
|
||||
} label: {
|
||||
Label("Update", systemImage: "arrow.down.doc.fill")
|
||||
}
|
||||
FormButton {
|
||||
FormButton(role: .destructive) {
|
||||
Task {
|
||||
await uninstallSystemExtension()
|
||||
}
|
||||
|
||||
@@ -9,7 +9,6 @@ struct PacketTunnelView: View {
|
||||
@State private var isLoading = true
|
||||
|
||||
@State private var ignoreMemoryLimit = false
|
||||
@State private var ignoreDeviceSleep = false
|
||||
|
||||
@State private var includeAllNetworks = false
|
||||
@State private var excludeAPNs = false
|
||||
@@ -39,17 +38,6 @@ struct PacketTunnelView: View {
|
||||
Text("Do not enforce memory limits on sing-box. Will cause OOM on non-jailbroken iOS and tvOS devices.")
|
||||
}
|
||||
|
||||
FormSection {
|
||||
Toggle("Ignore Device Sleep", isOn: $ignoreDeviceSleep)
|
||||
.onChangeCompat(of: ignoreDeviceSleep) { newValue in
|
||||
Task {
|
||||
await SharedPreferences.ignoreDeviceSleep.set(newValue)
|
||||
}
|
||||
}
|
||||
} footer: {
|
||||
Text("Ignore system `sleep()` and `wake()` events. May cause increased power usage, only enable if you encounter unexpected `rejected ... while device paused` errors.")
|
||||
}
|
||||
|
||||
#if !os(tvOS)
|
||||
|
||||
FormSection {
|
||||
@@ -152,7 +140,6 @@ struct PacketTunnelView: View {
|
||||
|
||||
private func loadSettings() async {
|
||||
ignoreMemoryLimit = await SharedPreferences.ignoreMemoryLimit.get()
|
||||
ignoreDeviceSleep = await SharedPreferences.ignoreDeviceSleep.get()
|
||||
#if !os(tvOS)
|
||||
includeAllNetworks = await SharedPreferences.includeAllNetworks.get()
|
||||
excludeAPNs = await SharedPreferences.excludeAPNs.get()
|
||||
|
||||
@@ -86,7 +86,7 @@ public struct SettingView: View {
|
||||
}
|
||||
}
|
||||
|
||||
@State private var isLoading = false
|
||||
@State private var isLoading = true
|
||||
@State private var taiwanFlagAvailable = false
|
||||
|
||||
public init() {}
|
||||
|
||||
Reference in New Issue
Block a user