-
Notifications
You must be signed in to change notification settings - Fork 223
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
75a79c9
commit d60b2b5
Showing
13 changed files
with
321 additions
and
223 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import AppIntents | ||
import Library | ||
import SwiftUI | ||
import WidgetKit | ||
|
||
struct ServiceToggleControl: ControlWidget { | ||
var body: some ControlWidgetConfiguration { | ||
StaticControlConfiguration( | ||
kind: ExtensionProfile.controlKind, | ||
provider: Provider() | ||
) { value in | ||
ControlWidgetToggle( | ||
"sing-box", | ||
isOn: value, | ||
action: ToggleServiceIntent() | ||
) { isOn in | ||
Label(isOn ? "Running" : "Stopped", systemImage: "shippingbox.fill") | ||
} | ||
.tint(.init(red: CGFloat(Double(69) / 255), green: CGFloat(Double(90) / 255), blue: CGFloat(Double(100) / 255))) | ||
} | ||
.displayName("Toggle") | ||
.description("Start or stop sing-box service.") | ||
} | ||
} | ||
|
||
extension ServiceToggleControl { | ||
struct Provider: ControlValueProvider { | ||
var previewValue: Bool { | ||
false | ||
} | ||
|
||
func currentValue() async throws -> Bool { | ||
guard let extensionProfile = try await (ExtensionProfile.load()) else { | ||
return false | ||
} | ||
return extensionProfile.status.isStarted | ||
} | ||
} | ||
} | ||
|
||
struct ToggleServiceIntent: SetValueIntent { | ||
static var title: LocalizedStringResource = "Toggle sing-box" | ||
|
||
static var description = | ||
IntentDescription("Toggle sing-box service") | ||
|
||
static var parameterSummary: some ParameterSummary { | ||
Summary("Toggle sing-box service") | ||
} | ||
|
||
@Parameter(title: "Service status") | ||
var value: Bool | ||
|
||
func perform() async throws -> some IntentResult & ReturnsValue<Bool> { | ||
guard let extensionProfile = try await (ExtensionProfile.load()) else { | ||
return .result(value: false) | ||
} | ||
if value { | ||
try await extensionProfile.start() | ||
return .result(value: true) | ||
} else { | ||
try await extensionProfile.stop() | ||
return .result(value: false) | ||
} | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.