mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-07-16 08:46:08 +03:00
core: nitpick some var names
This commit is contained in:
@ -3486,49 +3486,48 @@ 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")) {
|
||||||
const now = try std.time.Instant.now();
|
log.warn("runtime doesn't support desktop notifications", .{});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Set a limit of one desktop notification per second so that the OS
|
// Wyhash is used to hash the contents of the desktop notification to limit
|
||||||
// doesn't kill us when we run out of resources.
|
// how fast identical notifications can be sent sequentially.
|
||||||
if (self.app.last_notification_time) |last| {
|
const hash_algorithm = std.hash.Wyhash;
|
||||||
if (now.since(last) < 1 * std.time.ns_per_s) {
|
|
||||||
log.warn("rate limiting desktop notifications", .{});
|
const now = try std.time.Instant.now();
|
||||||
|
|
||||||
|
// Set a limit of one desktop notification per second so that the OS
|
||||||
|
// doesn't kill us when we run out of resources.
|
||||||
|
if (self.app.last_notification_time) |last| {
|
||||||
|
if (now.since(last) < 1 * std.time.ns_per_s) {
|
||||||
|
log.warn("rate limiting desktop notifications", .{});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const new_digest = d: {
|
||||||
|
var hash = hash_algorithm.init(0);
|
||||||
|
hash.update(title);
|
||||||
|
hash.update(body);
|
||||||
|
break :d hash.final();
|
||||||
|
};
|
||||||
|
|
||||||
|
// Set a limit of one notification per five seconds for desktop
|
||||||
|
// notifications with identical content.
|
||||||
|
if (self.app.last_notification_time) |last| {
|
||||||
|
if (self.app.last_notification_digest == new_digest) {
|
||||||
|
if (now.since(last) < 5 * std.time.ns_per_s) {
|
||||||
|
log.warn("suppressing identical desktop notification", .{});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const new_notification_digest = d: {
|
self.app.last_notification_time = now;
|
||||||
var hash = hash_algorithm.init(hash_seed);
|
self.app.last_notification_digest = new_digest;
|
||||||
hash.update(title);
|
try self.rt_surface.showDesktopNotification(title, body);
|
||||||
hash.update(body);
|
|
||||||
break :d hash.final();
|
|
||||||
};
|
|
||||||
|
|
||||||
// Set a limit of one notification per five seconds for desktop
|
|
||||||
// notifications with identical content.
|
|
||||||
if (self.app.last_notification_time) |last| {
|
|
||||||
if (self.app.last_notification_digest == new_notification_digest) {
|
|
||||||
if (now.since(last) < 5 * std.time.ns_per_s) {
|
|
||||||
log.warn("suppressing identical desktop notification", .{});
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
self.app.last_notification_time = now;
|
|
||||||
self.app.last_notification_digest = new_notification_digest;
|
|
||||||
|
|
||||||
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");
|
||||||
|
Reference in New Issue
Block a user