Skip to content

Commit 6723fe2

Browse files
committed
Replace WebView-based container app with SwiftUI
The container app previously used a WKWebView to display HTML/CSS/JS for the "enable extension" screen. This was overly complex for what is essentially a simple informational view. Replaced with a pure SwiftUI implementation: - CacheStatusApp.swift: SwiftUI App entry point - ContentView.swift: Native UI with extension state checking Benefits: - Reduced from ~170 lines + storyboard to ~80 lines total - Native macOS styling with automatic dark mode support - No WebKit dependency - Simpler, more maintainable codebase Removed: - AppDelegate.swift, ViewController.swift - Main.storyboard - Resources/ folder (Main.html, Style.css, Script.js, Icon.png)
1 parent 76668fa commit 6723fe2

10 files changed

Lines changed: 91 additions & 290 deletions

File tree

CF Cache Status/CF Cache Status.xcodeproj/project.pbxproj

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -103,12 +103,10 @@
103103
5B8F9F0B2F07E4C50092E4D0 /* CF Cache Status */ = {
104104
isa = PBXGroup;
105105
children = (
106-
5B8F9F0C2F07E4C50092E4D0 /* AppDelegate.swift */,
107-
5B8F9F182F07E4C50092E4D0 /* ViewController.swift */,
108-
5B8F9F1A2F07E4C50092E4D0 /* Main.storyboard */,
106+
5BSWIFTUI002F09A0000000001 /* CacheStatusApp.swift */,
107+
5BSWIFTUI022F09A0000000001 /* ContentView.swift */,
109108
5B8F9F1D2F07E4C60092E4D0 /* Assets.xcassets */,
110109
5B8F9F1F2F07E4C60092E4D0 /* Info.plist */,
111-
5B8F9F0E2F07E4C50092E4D0 /* Resources */,
112110
);
113111
path = "CF Cache Status";
114112
sourceTree = "<group>";
@@ -235,12 +233,7 @@
235233
isa = PBXResourcesBuildPhase;
236234
buildActionMask = 2147483647;
237235
files = (
238-
5B8F9F132F07E4C50092E4D0 /* Icon.png in Resources */,
239-
5B8F9F1C2F07E4C50092E4D0 /* Main.storyboard in Resources */,
240-
5B8F9F172F07E4C50092E4D0 /* Script.js in Resources */,
241-
5B8F9F112F07E4C50092E4D0 /* Main.html in Resources */,
242236
5B8F9F1E2F07E4C60092E4D0 /* Assets.xcassets in Resources */,
243-
5B8F9F152F07E4C50092E4D0 /* Style.css in Resources */,
244237
);
245238
runOnlyForDeploymentPostprocessing = 0;
246239
};
@@ -265,8 +258,8 @@
265258
isa = PBXSourcesBuildPhase;
266259
buildActionMask = 2147483647;
267260
files = (
268-
5B8F9F192F07E4C50092E4D0 /* ViewController.swift in Sources */,
269-
5B8F9F0D2F07E4C50092E4D0 /* AppDelegate.swift in Sources */,
261+
5BSWIFTUI012F09A0000000001 /* CacheStatusApp.swift in Sources */,
262+
5BSWIFTUI032F09A0000000001 /* ContentView.swift in Sources */,
270263
);
271264
runOnlyForDeploymentPostprocessing = 0;
272265
};
@@ -431,6 +424,7 @@
431424
buildSettings = {
432425
CODE_SIGN_STYLE = Automatic;
433426
CURRENT_PROJECT_VERSION = 1;
427+
DEVELOPMENT_TEAM = H95JUDBHF7;
434428
ENABLE_APP_SANDBOX = YES;
435429
ENABLE_HARDENED_RUNTIME = YES;
436430
ENABLE_USER_SELECTED_FILES = readonly;
@@ -465,6 +459,7 @@
465459
buildSettings = {
466460
CODE_SIGN_STYLE = Automatic;
467461
CURRENT_PROJECT_VERSION = 1;
462+
DEVELOPMENT_TEAM = H95JUDBHF7;
468463
ENABLE_APP_SANDBOX = YES;
469464
ENABLE_HARDENED_RUNTIME = YES;
470465
ENABLE_USER_SELECTED_FILES = readonly;

CF Cache Status/CF Cache Status/AppDelegate.swift

Lines changed: 0 additions & 9 deletions
This file was deleted.

CF Cache Status/CF Cache Status/Base.lproj/Main.storyboard

Lines changed: 0 additions & 125 deletions
This file was deleted.
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
//
2+
// CacheStatusApp.swift
3+
// CF Cache Status
4+
//
5+
6+
import SwiftUI
7+
8+
@main
9+
struct CacheStatusApp: App {
10+
var body: some Scene {
11+
Window("Cache Status", id: "main") {
12+
ContentView()
13+
}
14+
.windowResizability(.contentSize)
15+
.defaultPosition(.center)
16+
}
17+
}
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
//
2+
// ContentView.swift
3+
// CF Cache Status
4+
//
5+
6+
import SwiftUI
7+
import SafariServices
8+
9+
let extensionBundleIdentifier = "com.cfcachestatus.CF-Cache-Status.Extension"
10+
11+
struct ContentView: View {
12+
@State private var extensionEnabled: Bool?
13+
14+
private var statusText: String {
15+
guard let enabled = extensionEnabled else {
16+
return "You can turn on Cache Status's extension in the Extensions section of Safari Settings."
17+
}
18+
if enabled {
19+
return "Cache Status's extension is currently on. You can turn it off in the Extensions section of Safari Settings."
20+
} else {
21+
return "Cache Status's extension is currently off. You can turn it on in the Extensions section of Safari Settings."
22+
}
23+
}
24+
25+
var body: some View {
26+
VStack(spacing: 20) {
27+
Image(systemName: "cloud")
28+
.font(.system(size: 72, weight: .thin))
29+
.foregroundStyle(.secondary)
30+
31+
Text(statusText)
32+
.multilineTextAlignment(.center)
33+
.foregroundStyle(.secondary)
34+
35+
Button("Quit and Open Safari Settings…") {
36+
openSafariPreferences()
37+
}
38+
.buttonStyle(.borderedProminent)
39+
}
40+
.padding(40)
41+
.frame(width: 400, height: 300)
42+
.onAppear {
43+
checkExtensionState()
44+
}
45+
}
46+
47+
private func checkExtensionState() {
48+
SFSafariExtensionManager.getStateOfSafariExtension(withIdentifier: extensionBundleIdentifier) { state, error in
49+
DispatchQueue.main.async {
50+
if let state = state, error == nil {
51+
extensionEnabled = state.isEnabled
52+
}
53+
}
54+
}
55+
}
56+
57+
private func openSafariPreferences() {
58+
SFSafariApplication.showPreferencesForExtension(withIdentifier: extensionBundleIdentifier) { _ in
59+
DispatchQueue.main.async {
60+
NSApplication.shared.terminate(nil)
61+
}
62+
}
63+
}
64+
}
65+
66+
#Preview {
67+
ContentView()
68+
}

CF Cache Status/CF Cache Status/Resources/Base.lproj/Main.html

Lines changed: 0 additions & 21 deletions
This file was deleted.
-8.8 KB
Binary file not shown.

CF Cache Status/CF Cache Status/Resources/Script.js

Lines changed: 0 additions & 22 deletions
This file was deleted.

CF Cache Status/CF Cache Status/Resources/Style.css

Lines changed: 0 additions & 45 deletions
This file was deleted.

0 commit comments

Comments
 (0)