chore: add more logging

This commit is contained in:
LordMZTE 2022-07-18 18:43:56 +02:00
parent 7647f569e4
commit f0f50adfef
Signed by: LordMZTE
GPG Key ID: B64802DC33A64FF6
2 changed files with 13 additions and 2 deletions

View File

@ -16,6 +16,8 @@ pub fn build(b: *std.build.Builder) !void {
lib.linkSystemLibrary("cairo");
pkgs.addAllTo(lib);
lib.strip = mode != .Debug;
lib.install();
lib.step.dependOn(&(try NhdbusGen.init(lib)).step);

View File

@ -4,6 +4,8 @@ const c = ffi.c;
const Mode = c.Mode;
pub const log = @import("glib-log").log(c, "rofi-nheko", 512);
// log levels are handled by glib, so zig shouldn't filter
pub const log_level = .debug;
export var mode: Mode = .{
.abi_version = c.ABI_VERSION,
@ -102,6 +104,7 @@ fn init(m: [*c]Mode) callconv(.C) c_int {
@ptrCast(c.GAsyncReadyCallback, onRoomsReceived),
state(m),
);
std.log.info("Requested rooms", .{});
return 1;
}
@ -111,6 +114,7 @@ fn onRoomsReceived(proxy: *c.nhdbus, res: *c.GAsyncResult, s: *State) void {
var err: ?*c.GError = null;
_ = c.nhdbus__call_rooms_finish(proxy, &rooms, res, &err);
ffi.checkGError(err) catch return;
std.log.info("Received rooms", .{});
(std.Thread.spawn(.{}, readRooms, .{ rooms.?, s }) catch
@panic("Failed to spawn room reader thread")).detach();
@ -175,6 +179,7 @@ fn readRooms(rooms: *c.GVariant, s: *State) void {
std.sort.sort(Room, s.rooms.items, {}, compareRoom);
ffi.rofi_view_reload();
std.log.info("Read {} rooms", .{s.rooms.items.len});
}
fn compareRoom(_: void, lhs: Room, rhs: Room) bool {
@ -222,17 +227,21 @@ fn result(
defer state(m).rooms_lock.unlock();
// no line selected
if (selected_line == std.math.maxInt(c_uint) or (mretv & c.MENU_OK) == 0)
if (selected_line == std.math.maxInt(c_uint) or (mretv & c.MENU_OK) == 0) {
std.log.warn("Exiting without changing room", .{});
return c.MODE_EXIT;
}
const room = state(m).rooms.items[selected_line];
var err: ?*c.GError = null;
_ = c.nhdbus__call_activate_room_sync(
state(m).dbus,
state(m).rooms.items[selected_line].id,
room.id,
null,
&err,
);
ffi.checkGError(err) catch {};
std.log.info("Changed room to {s} ({s})", .{ room.id, room.name });
return c.MODE_EXIT;
}