-
Notifications
You must be signed in to change notification settings - Fork 242
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
493a0f4
commit a0282e8
Showing
12 changed files
with
307 additions
and
150 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,62 @@ | ||
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") | ||
|
||
@Parameter(title: "Running") | ||
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 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.
Oops, something went wrong.