also looking at this
fix(bridge): stop discarding the fields the page actually sends
#82
7 files
+375
-34
| @@ -64,7 +64,7 @@ pub const AppBridge = struct { | ||
| 64 | 64 | } else if (std.mem.eql(u8, action, A.set_badge)) { |
| 65 | 65 | try self.setBadge(data); |
| 66 | 66 | } else if (std.mem.eql(u8, action, A.bounce)) { |
| 67 | try self.bounce(); | |
| 67 | try self.bounce(data); | |
| 68 | 68 | } else { |
| 69 | 69 | if (comptime builtin.mode == .debug) |
| 70 | 70 | std.debug.print("[AppBridge] Unknown action: {s}\n", .{action}); |
| @@ -244,17 +244,32 @@ pub const AppBridge = struct { | ||
| 244 | 244 | } |
| 245 | 245 | } |
| 246 | 246 | |
| 247 | fn bounce(self: *Self) !void { | |
| 247 | /// `craft.app.bounce(type)` — 'critical' or 'informational'. | |
| 248 | /// | |
| 249 | /// This took no payload at all and always requested an informational | |
| 250 | /// bounce, so `bounce('critical')` hopped the Dock icon once instead of | |
| 251 | /// bouncing until the user activates the app — which is the entire | |
| 252 | /// difference between the two, and the only reason to pass an argument. | |
| 253 | fn bounce(self: *Self, data: ?[]const u8) !void { | |
| 248 | 254 | _ = self; |
| 249 | 255 | if (builtin.os.tag == .macos) { |
| 250 | 256 | const macos = ; |
| 251 | 257 | const NSApplication = macos.getClass("NSApplication"); |
| 252 | 258 | const app = macos.msgSend0(NSApplication, "sharedApplication"); |
| 253 | 259 | |
| 254 | // NSApplicationActivateIgnoringOtherApps + request user attention | |
| 255 | // NSInformationalRequest = 10 | |
| 260 | // `NSRequestUserAttentionType`: critical bounces until the app is | |
| 261 | // activated, informational bounces once. | |
| 262 | const NSCriticalRequest: c_long = 0; | |
| 256 | 263 | const NSInformationalRequest: c_long = 10; |
| 257 | _ = macos.msgSend1(app, "requestUserAttention:", NSInformationalRequest); | |
| 264 | ||
| 265 | const request = if (data) |json_data| blk: { | |
| 266 | break :blk if (std.mem.indexOf(u8, json_data, "critical") != null) | |
| 267 | NSCriticalRequest | |
| 268 | else | |
| 269 | NSInformationalRequest; | |
| 270 | } else NSInformationalRequest; | |
| 271 | ||
| 272 | _ = macos.msgSend1(app, "requestUserAttention:", request); | |
| 258 | 273 | } |
| 259 | 274 | } |
| 260 | 275 | |