Skip to content

Commit eae998c

Browse files
committed
add support for URLs
1 parent 97eadaf commit eae998c

5 files changed

Lines changed: 76 additions & 11 deletions

File tree

SerialPlotter.xcodeproj/project.pbxproj

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,22 @@
1414
5E39F6C62E51D9D000571E8F /* SerialPlotter.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = SerialPlotter.app; sourceTree = BUILT_PRODUCTS_DIR; };
1515
/* End PBXFileReference section */
1616

17+
/* Begin PBXFileSystemSynchronizedBuildFileExceptionSet section */
18+
5E80C8692E798E20003EAC95 /* Exceptions for "SerialPlotter" folder in "SerialPlotter" target */ = {
19+
isa = PBXFileSystemSynchronizedBuildFileExceptionSet;
20+
membershipExceptions = (
21+
Info.plist,
22+
);
23+
target = 5E39F6C52E51D9D000571E8F /* SerialPlotter */;
24+
};
25+
/* End PBXFileSystemSynchronizedBuildFileExceptionSet section */
26+
1727
/* Begin PBXFileSystemSynchronizedRootGroup section */
1828
5E39F6C82E51D9D000571E8F /* SerialPlotter */ = {
1929
isa = PBXFileSystemSynchronizedRootGroup;
30+
exceptions = (
31+
5E80C8692E798E20003EAC95 /* Exceptions for "SerialPlotter" folder in "SerialPlotter" target */,
32+
);
2033
path = SerialPlotter;
2134
sourceTree = "<group>";
2235
};
@@ -262,7 +275,7 @@
262275
CODE_SIGN_ENTITLEMENTS = SerialPlotter/SerialPlotter.entitlements;
263276
CODE_SIGN_STYLE = Automatic;
264277
COMBINE_HIDPI_IMAGES = YES;
265-
CURRENT_PROJECT_VERSION = 4;
278+
CURRENT_PROJECT_VERSION = 5;
266279
DEVELOPMENT_TEAM = 9XCKWAKCP6;
267280
ENABLE_APP_SANDBOX = YES;
268281
ENABLE_HARDENED_RUNTIME = YES;
@@ -278,7 +291,9 @@
278291
ENABLE_RESOURCE_ACCESS_PRINTING = NO;
279292
ENABLE_RESOURCE_ACCESS_USB = NO;
280293
GENERATE_INFOPLIST_FILE = YES;
294+
INFOPLIST_FILE = SerialPlotter/Info.plist;
281295
INFOPLIST_KEY_CFBundleDisplayName = "Serial Plotter";
296+
INFOPLIST_KEY_LSApplicationCategoryType = "public.app-category.developer-tools";
282297
INFOPLIST_KEY_NSHumanReadableCopyright = "";
283298
LD_RUNPATH_SEARCH_PATHS = (
284299
"$(inherited)",
@@ -289,7 +304,7 @@
289304
"$(PROJECT_DIR)/SerialPlotter/Python",
290305
);
291306
MACOSX_DEPLOYMENT_TARGET = 14.6;
292-
MARKETING_VERSION = 1.3;
307+
MARKETING_VERSION = 1.4;
293308
PRODUCT_BUNDLE_IDENTIFIER = com.asboy2035.SerialPlotter;
294309
PRODUCT_NAME = "$(TARGET_NAME)";
295310
REGISTER_APP_GROUPS = YES;
@@ -309,7 +324,7 @@
309324
CODE_SIGN_ENTITLEMENTS = SerialPlotter/SerialPlotter.entitlements;
310325
CODE_SIGN_STYLE = Automatic;
311326
COMBINE_HIDPI_IMAGES = YES;
312-
CURRENT_PROJECT_VERSION = 4;
327+
CURRENT_PROJECT_VERSION = 5;
313328
DEVELOPMENT_TEAM = 9XCKWAKCP6;
314329
ENABLE_APP_SANDBOX = YES;
315330
ENABLE_HARDENED_RUNTIME = YES;
@@ -325,7 +340,9 @@
325340
ENABLE_RESOURCE_ACCESS_PRINTING = NO;
326341
ENABLE_RESOURCE_ACCESS_USB = NO;
327342
GENERATE_INFOPLIST_FILE = YES;
343+
INFOPLIST_FILE = SerialPlotter/Info.plist;
328344
INFOPLIST_KEY_CFBundleDisplayName = "Serial Plotter";
345+
INFOPLIST_KEY_LSApplicationCategoryType = "public.app-category.developer-tools";
329346
INFOPLIST_KEY_NSHumanReadableCopyright = "";
330347
LD_RUNPATH_SEARCH_PATHS = (
331348
"$(inherited)",
@@ -336,7 +353,7 @@
336353
"$(PROJECT_DIR)/SerialPlotter/Python",
337354
);
338355
MACOSX_DEPLOYMENT_TARGET = 14.6;
339-
MARKETING_VERSION = 1.3;
356+
MARKETING_VERSION = 1.4;
340357
PRODUCT_BUNDLE_IDENTIFIER = com.asboy2035.SerialPlotter;
341358
PRODUCT_NAME = "$(TARGET_NAME)";
342359
REGISTER_APP_GROUPS = YES;

SerialPlotter/ContentView.swift

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ struct ContentView: View {
2020
@State private var selectedKey: String? = nil
2121
@State private var showingConnectionSheet = false
2222
@State private var showingQRCode = false
23+
@State private var showingUrlError: Bool = false
2324

2425
private let rainbowColors: [Color] = [.red, .orange, .yellow, .green, .blue, .purple]
2526
private let devicePresets = ["megaatmega2560", "uno", "nano", "esp32"]
@@ -63,11 +64,7 @@ struct ContentView: View {
6364

6465
ToolbarItem {
6566
Button(action: {
66-
if monitorManager.isRunning {
67-
monitorManager.stopMonitoring()
68-
} else {
69-
monitorManager.startMonitoring()
70-
}
67+
toggleMonitoring()
7168
}) {
7269
Label(
7370
monitorManager.isRunning ? "Stop" : "Start",
@@ -102,6 +99,34 @@ struct ContentView: View {
10299
showingQRCode: $showingQRCode
103100
)
104101
}
102+
.onOpenURL { url in
103+
print("Opened from URL: \(url)")
104+
105+
switch url.host {
106+
case "start": monitorManager.startMonitoring()
107+
case "stop": monitorManager.stopMonitoring()
108+
case "toggle": toggleMonitoring()
109+
default: showUrlError()
110+
}
111+
}
112+
.alert("Invalid URL",
113+
isPresented: $showingUrlError) {
114+
Button("OK", role: .cancel) { }
115+
} message: {
116+
Text("No action is linked to the body of the URL that was used.")
117+
}
118+
}
119+
120+
private func showUrlError() {
121+
showingUrlError = true
122+
}
123+
124+
private func toggleMonitoring() {
125+
if monitorManager.isRunning {
126+
monitorManager.stopMonitoring()
127+
} else {
128+
monitorManager.startMonitoring()
129+
}
105130
}
106131

107132
private var currentValuesSection: some View {

SerialPlotter/Info.plist

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
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>CFBundleURLTypes</key>
6+
<array>
7+
<dict>
8+
<key>CFBundleTypeRole</key>
9+
<string>Editor</string>
10+
<key>CFBundleURLName</key>
11+
<string>SerialPlotter</string>
12+
<key>CFBundleURLSchemes</key>
13+
<array>
14+
<string>serialplotter</string>
15+
</array>
16+
</dict>
17+
</array>
18+
</dict>
19+
</plist>

SerialPlotter/Modifiers/NavigationSubtitleIfAvailable.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,4 @@ struct NavigationSubtitleIfAvailable: ViewModifier {
2222
content // fallback for older OSes
2323
}
2424
}
25-
}
25+
}

SerialPlotter/SerialPlotterApp.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,12 @@ import SwiftUI
1010
@main
1111
struct SerialPlotterApp: App {
1212
var body: some Scene {
13-
WindowGroup {
13+
Window("Main", id: "serialMain") {
1414
ContentView()
15+
.onDisappear() {
16+
NSApplication.shared.terminate(nil)
17+
}
1518
}
19+
.handlesExternalEvents(matching: Set(["start", "stop", "toggle"]))
1620
}
1721
}

0 commit comments

Comments
 (0)