core: nitpick some var names

This commit is contained in:
Mitchell Hashimoto
2024-05-26 20:49:00 -07:00
parent 7c893881c3
commit 98b05ffd09

View File

@ -3486,15 +3486,16 @@ fn completeClipboardReadOSC52(
self.io_thread.wakeup.notify() catch {}; self.io_thread.wakeup.notify() catch {};
} }
// Wyhash is used to hash the contents of the desktop notification to limit how
// fast identical notifications can be sent sequentially.
const hash_algorithm = std.hash.Wyhash;
// This seed for Wyhash was literally chosen at random. The actual seed (AFAIK)
// shouldn't matter as long as it stays constant.
const hash_seed = 0xb8179c65b93cc558;
fn showDesktopNotification(self: *Surface, title: [:0]const u8, body: [:0]const u8) !void { fn showDesktopNotification(self: *Surface, title: [:0]const u8, body: [:0]const u8) !void {
if (@hasDecl(apprt.Surface, "showDesktopNotification")) { if (comptime !@hasDecl(apprt.Surface, "showDesktopNotification")) {
log.warn("runtime doesn't support desktop notifications", .{});
return;
}
// Wyhash is used to hash the contents of the desktop notification to limit
// how fast identical notifications can be sent sequentially.
const hash_algorithm = std.hash.Wyhash;
const now = try std.time.Instant.now(); const now = try std.time.Instant.now();
// Set a limit of one desktop notification per second so that the OS // Set a limit of one desktop notification per second so that the OS
@ -3506,8 +3507,8 @@ fn showDesktopNotification(self: *Surface, title: [:0]const u8, body: [:0]const
} }
} }
const new_notification_digest = d: { const new_digest = d: {
var hash = hash_algorithm.init(hash_seed); var hash = hash_algorithm.init(0);
hash.update(title); hash.update(title);
hash.update(body); hash.update(body);
break :d hash.final(); break :d hash.final();
@ -3516,7 +3517,7 @@ fn showDesktopNotification(self: *Surface, title: [:0]const u8, body: [:0]const
// Set a limit of one notification per five seconds for desktop // Set a limit of one notification per five seconds for desktop
// notifications with identical content. // notifications with identical content.
if (self.app.last_notification_time) |last| { if (self.app.last_notification_time) |last| {
if (self.app.last_notification_digest == new_notification_digest) { if (self.app.last_notification_digest == new_digest) {
if (now.since(last) < 5 * std.time.ns_per_s) { if (now.since(last) < 5 * std.time.ns_per_s) {
log.warn("suppressing identical desktop notification", .{}); log.warn("suppressing identical desktop notification", .{});
return; return;
@ -3525,10 +3526,8 @@ fn showDesktopNotification(self: *Surface, title: [:0]const u8, body: [:0]const
} }
self.app.last_notification_time = now; self.app.last_notification_time = now;
self.app.last_notification_digest = new_notification_digest; self.app.last_notification_digest = new_digest;
try self.rt_surface.showDesktopNotification(title, body); try self.rt_surface.showDesktopNotification(title, body);
} else log.warn("runtime doesn't support desktop notifications", .{});
} }
pub const face_ttf = @embedFile("font/res/JetBrainsMono-Regular.ttf"); pub const face_ttf = @embedFile("font/res/JetBrainsMono-Regular.ttf");