Skip to content

Commit 88027cc

Browse files
committed
feat: control center icon and control
1 parent 2aa9314 commit 88027cc

13 files changed

Lines changed: 392 additions & 3 deletions

File tree

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
EasyTier.xcodeproj/project.xcworkspace/xcuserdata/
1+
xcuserdata
2+
build.log
23
compile_commands.json
34

45
CLAUDE.md

ControlWidgets/AppIntent.swift

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
//
2+
// AppIntent.swift
3+
// ControlWidgets
4+
//
5+
// Created by YinMo19 on 2026/1/13.
6+
//
7+
8+
import AppIntents
9+
10+
// Toggle VPN connection via App Group notification
11+
struct ToggleVPNIntent: SetValueIntent {
12+
static let title: LocalizedStringResource = "Toggle VPN"
13+
14+
@Parameter(title: "Connected")
15+
var value: Bool
16+
17+
func perform() async throws -> some IntentResult {
18+
let defaults = UserDefaults(suiteName: "group.site.yinmo.easytier")
19+
20+
// Set the desired state
21+
defaults?.set(value, forKey: "VPNDesiredState")
22+
defaults?.synchronize()
23+
24+
// Notify main app to perform the action
25+
CFNotificationCenterPostNotification(
26+
CFNotificationCenterGetDarwinNotifyCenter(),
27+
CFNotificationName("site.yinmo.easytier.toggleVPN" as CFString),
28+
nil,
29+
nil,
30+
true
31+
)
32+
33+
return .result()
34+
}
35+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"colors" : [
3+
{
4+
"idiom" : "universal"
5+
}
6+
],
7+
"info" : {
8+
"author" : "xcode",
9+
"version" : 1
10+
}
11+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
{
2+
"images" : [
3+
{
4+
"idiom" : "universal",
5+
"platform" : "ios",
6+
"size" : "1024x1024"
7+
},
8+
{
9+
"appearances" : [
10+
{
11+
"appearance" : "luminosity",
12+
"value" : "dark"
13+
}
14+
],
15+
"idiom" : "universal",
16+
"platform" : "ios",
17+
"size" : "1024x1024"
18+
},
19+
{
20+
"appearances" : [
21+
{
22+
"appearance" : "luminosity",
23+
"value" : "tinted"
24+
}
25+
],
26+
"idiom" : "universal",
27+
"platform" : "ios",
28+
"size" : "1024x1024"
29+
}
30+
],
31+
"info" : {
32+
"author" : "xcode",
33+
"version" : 1
34+
}
35+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"info" : {
3+
"author" : "xcode",
4+
"version" : 1
5+
}
6+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"colors" : [
3+
{
4+
"idiom" : "universal"
5+
}
6+
],
7+
"info" : {
8+
"author" : "xcode",
9+
"version" : 1
10+
}
11+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
//
2+
// ControlWidgetsBundle.swift
3+
// ControlWidgets
4+
//
5+
// Created by YinMo19 on 2026/1/13.
6+
//
7+
8+
import WidgetKit
9+
import SwiftUI
10+
11+
@main
12+
struct ControlWidgetsBundle: WidgetBundle {
13+
var body: some Widget {
14+
ControlWidgetsControl()
15+
}
16+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
//
2+
// ControlWidgetsControl.swift
3+
// ControlWidgets
4+
//
5+
// Created by YinMo19 on 2026/1/13.
6+
//
7+
8+
import AppIntents
9+
import SwiftUI
10+
import WidgetKit
11+
12+
struct ControlWidgetsControl: ControlWidget {
13+
static let kind: String = "site.yinmo.easytier.ControlWidgets"
14+
15+
var body: some ControlWidgetConfiguration {
16+
AppIntentControlConfiguration(
17+
kind: Self.kind,
18+
provider: VPNControlProvider()
19+
) { isConnected in
20+
ControlWidgetToggle(
21+
isOn: isConnected,
22+
action: ToggleVPNIntent()
23+
) {
24+
Label("EasyTier", systemImage: "network")
25+
}
26+
}
27+
.displayName("EasyTier")
28+
.description("Toggle VPN connection")
29+
}
30+
}
31+
32+
struct VPNControlProvider: AppIntentControlValueProvider {
33+
func previewValue(configuration: VPNControlConfiguration) -> Bool {
34+
false
35+
}
36+
37+
func currentValue(configuration: VPNControlConfiguration) async throws -> Bool {
38+
let defaults = UserDefaults(suiteName: "group.site.yinmo.easytier")
39+
return defaults?.bool(forKey: "VPNIsConnected") ?? false
40+
}
41+
}
42+
43+
struct VPNControlConfiguration: ControlConfigurationIntent {
44+
static let title: LocalizedStringResource = "VPN Control"
45+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>com.apple.security.application-groups</key>
6+
<array>
7+
<string>group.site.yinmo.easytier</string>
8+
</array>
9+
</dict>
10+
</plist>

ControlWidgets/Info.plist

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>NSExtension</key>
6+
<dict>
7+
<key>NSExtensionPointIdentifier</key>
8+
<string>com.apple.widgetkit-extension</string>
9+
</dict>
10+
</dict>
11+
</plist>

0 commit comments

Comments
 (0)