this repo has no description
13
fork

Configure Feed

Select the types of activity you want to include in your feed.

vxfw(Command): add notifications

+36
+10
src/vxfw/App.zig
··· 257 257 }; 258 258 }, 259 259 .queue_refresh => self.vx.queueRefresh(), 260 + .notify => |notification| { 261 + self.vx.notify(self.tty.anyWriter(), notification.title, notification.body) catch |err| { 262 + std.log.err("notify error: {}", .{err}); 263 + }; 264 + const alloc = cmds.allocator; 265 + if (notification.title) |title| { 266 + alloc.free(title); 267 + } 268 + alloc.free(notification.body); 269 + }, 260 270 } 261 271 } 262 272 }
+26
src/vxfw/vxfw.zig
··· 87 87 88 88 /// Queue a refresh of the entire screen. Implicitly sets redraw 89 89 queue_refresh, 90 + 91 + /// Send a system notification 92 + notify: struct { 93 + title: ?[]const u8, 94 + body: []const u8, 95 + }, 90 96 }; 91 97 92 98 pub const EventContext = struct { ··· 143 149 pub fn queueRefresh(self: *EventContext) Allocator.Error!void { 144 150 try self.addCmd(.queue_refresh); 145 151 self.redraw = true; 152 + } 153 + 154 + /// Send a system notification. This function dupes title and body using it's own allocator. 155 + /// They will be freed once the notification has been sent 156 + pub fn sendNotification( 157 + self: *EventContext, 158 + maybe_title: ?[]const u8, 159 + body: []const u8, 160 + ) Allocator.Error!void { 161 + const alloc = self.cmds.allocator; 162 + if (maybe_title) |title| { 163 + return self.addCmd(.{ .notify = .{ 164 + .title = try alloc.dupe(u8, title), 165 + .body = try alloc.dupe(u8, body), 166 + } }); 167 + } 168 + return self.addCmd(.{ .notify = .{ 169 + .title = null, 170 + .body = try alloc.dupe(u8, body), 171 + } }); 146 172 } 147 173 }; 148 174