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() {}
|
||||
|
||||
@@ -12,7 +12,6 @@ public enum SharedPreferences {
|
||||
public static let alwaysOn = Preference<Bool>("always_on", defaultValue: false)
|
||||
|
||||
public static let ignoreMemoryLimit = Preference<Bool>("ignore_memory_limit", defaultValue: ignoreMemoryLimitByDefault)
|
||||
public static let ignoreDeviceSleep = Preference<Bool>("ignore_device_sleep", defaultValue: false)
|
||||
|
||||
#if os(iOS)
|
||||
public static let excludeLocalNetworksByDefault = true
|
||||
@@ -31,7 +30,6 @@ public enum SharedPreferences {
|
||||
|
||||
public static func resetPacketTunnel() async {
|
||||
await ignoreMemoryLimit.set(nil)
|
||||
await ignoreDeviceSleep.set(nil)
|
||||
#if !os(tvOS)
|
||||
await includeAllNetworks.set(nil)
|
||||
await excludeAPNs.set(nil)
|
||||
|
||||
@@ -6,7 +6,6 @@ open class ExtensionProvider: NEPacketTunnelProvider {
|
||||
public var username: String? = nil
|
||||
private var commandServer: LibboxCommandServer!
|
||||
private var boxService: LibboxBoxService!
|
||||
private var ignoreDeviceSleep = false
|
||||
private var systemProxyAvailable = false
|
||||
private var systemProxyEnabled = false
|
||||
private var platformInterface: ExtensionPlatformInterface!
|
||||
@@ -36,7 +35,6 @@ open class ExtensionProvider: NEPacketTunnelProvider {
|
||||
}
|
||||
|
||||
await LibboxSetMemoryLimit(!SharedPreferences.ignoreMemoryLimit.get())
|
||||
ignoreDeviceSleep = await SharedPreferences.ignoreDeviceSleep.get()
|
||||
|
||||
if platformInterface == nil {
|
||||
platformInterface = ExtensionPlatformInterface(self)
|
||||
@@ -161,18 +159,12 @@ open class ExtensionProvider: NEPacketTunnelProvider {
|
||||
}
|
||||
|
||||
override open func sleep() async {
|
||||
if ignoreDeviceSleep {
|
||||
return
|
||||
}
|
||||
if let boxService {
|
||||
boxService.sleep()
|
||||
boxService.pause()
|
||||
}
|
||||
}
|
||||
|
||||
override open func wake() {
|
||||
if ignoreDeviceSleep {
|
||||
return
|
||||
}
|
||||
if let boxService {
|
||||
boxService.wake()
|
||||
}
|
||||
|
||||
@@ -98,6 +98,7 @@
|
||||
3AC729F02A75D9D000FE8EC1 /* Profile+Transferable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3AC729EF2A75D9D000FE8EC1 /* Profile+Transferable.swift */; };
|
||||
3AC729F22A76088E00FE8EC1 /* ShareButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3AC729F12A76088E00FE8EC1 /* ShareButton.swift */; };
|
||||
3AC8CF9B2A736C750002AF3C /* ImportProfileView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3AC8CF9A2A736C750002AF3C /* ImportProfileView.swift */; };
|
||||
3ACA8B332B7E037800B7238F /* DeleteButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3ACA8B322B7E037800B7238F /* DeleteButton.swift */; };
|
||||
3ACE6DE32ACADF55009D9A8A /* Binding+Setter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3ACE6DE22ACADF55009D9A8A /* Binding+Setter.swift */; };
|
||||
3AD0953D2A70EB310052764E /* Profile+Share.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3AD0953C2A70EB310052764E /* Profile+Share.swift */; };
|
||||
3ADBB4252A7389640041D44F /* ProfileServer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3ADBB4242A7389640041D44F /* ProfileServer.swift */; };
|
||||
@@ -510,6 +511,7 @@
|
||||
3AC729EF2A75D9D000FE8EC1 /* Profile+Transferable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Profile+Transferable.swift"; sourceTree = "<group>"; };
|
||||
3AC729F12A76088E00FE8EC1 /* ShareButton.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ShareButton.swift; sourceTree = "<group>"; };
|
||||
3AC8CF9A2A736C750002AF3C /* ImportProfileView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ImportProfileView.swift; sourceTree = "<group>"; };
|
||||
3ACA8B322B7E037800B7238F /* DeleteButton.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DeleteButton.swift; sourceTree = "<group>"; };
|
||||
3ACE6DE22ACADF55009D9A8A /* Binding+Setter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Binding+Setter.swift"; sourceTree = "<group>"; };
|
||||
3AD0953C2A70EB310052764E /* Profile+Share.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Profile+Share.swift"; sourceTree = "<group>"; };
|
||||
3ADBB4242A7389640041D44F /* ProfileServer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProfileServer.swift; sourceTree = "<group>"; };
|
||||
@@ -1029,6 +1031,7 @@
|
||||
3AC729F12A76088E00FE8EC1 /* ShareButton.swift */,
|
||||
3ACE6DE22ACADF55009D9A8A /* Binding+Setter.swift */,
|
||||
3A3AB2A82B70C5F1001815AE /* RequestReviewButton.swift */,
|
||||
3ACA8B322B7E037800B7238F /* DeleteButton.swift */,
|
||||
);
|
||||
path = Abstract;
|
||||
sourceTree = "<group>";
|
||||
@@ -1510,6 +1513,7 @@
|
||||
3A99B42E2A752ABB0010D4B0 /* NavigationDestinationCompat.swift in Sources */,
|
||||
3AC729F22A76088E00FE8EC1 /* ShareButton.swift in Sources */,
|
||||
3A0C6D3C2A79D46500A4DF2B /* OverviewView.swift in Sources */,
|
||||
3ACA8B332B7E037800B7238F /* DeleteButton.swift in Sources */,
|
||||
3ACE6DE32ACADF55009D9A8A /* Binding+Setter.swift in Sources */,
|
||||
3A4EAD262A4FEB65005435B3 /* ExtensionStatusView.swift in Sources */,
|
||||
3A4EAD252A4FEB65005435B3 /* StartStopButton.swift in Sources */,
|
||||
@@ -2543,7 +2547,7 @@
|
||||
"@executable_path/../../../../Frameworks",
|
||||
);
|
||||
MACOSX_DEPLOYMENT_TARGET = 13.0;
|
||||
MARKETING_VERSION = 1.9.0-alpha.1;
|
||||
MARKETING_VERSION = "1.9.0-alpha.8";
|
||||
PRODUCT_BUNDLE_IDENTIFIER = io.nekohasekai.sfa.system;
|
||||
PRODUCT_NAME = "$(inherited)";
|
||||
PROVISIONING_PROFILE_SPECIFIER = "";
|
||||
@@ -2579,7 +2583,7 @@
|
||||
"@executable_path/../../../../Frameworks",
|
||||
);
|
||||
MACOSX_DEPLOYMENT_TARGET = 13.0;
|
||||
MARKETING_VERSION = 1.9.0-alpha.1;
|
||||
MARKETING_VERSION = "1.9.0-alpha.8";
|
||||
PRODUCT_BUNDLE_IDENTIFIER = io.nekohasekai.sfa.system;
|
||||
PRODUCT_NAME = "$(inherited)";
|
||||
PROVISIONING_PROFILE_SPECIFIER = "";
|
||||
@@ -2619,7 +2623,7 @@
|
||||
"@executable_path/../Frameworks",
|
||||
);
|
||||
MACOSX_DEPLOYMENT_TARGET = 13.0;
|
||||
MARKETING_VERSION = 1.9.0-alpha.1;
|
||||
MARKETING_VERSION = "1.9.0-alpha.8";
|
||||
PRODUCT_BUNDLE_IDENTIFIER = io.nekohasekai.sfa.independent;
|
||||
PRODUCT_NAME = SFM;
|
||||
PROVISIONING_PROFILE_SPECIFIER = "";
|
||||
@@ -2658,7 +2662,7 @@
|
||||
"@executable_path/../Frameworks",
|
||||
);
|
||||
MACOSX_DEPLOYMENT_TARGET = 13.0;
|
||||
MARKETING_VERSION = 1.9.0-alpha.1;
|
||||
MARKETING_VERSION = "1.9.0-alpha.8";
|
||||
PRODUCT_BUNDLE_IDENTIFIER = io.nekohasekai.sfa.independent;
|
||||
PRODUCT_NAME = SFM;
|
||||
PROVISIONING_PROFILE_SPECIFIER = "";
|
||||
|
||||
Reference in New Issue
Block a user