Skip to content

Commit

Permalink
moar struct init
Browse files Browse the repository at this point in the history
  • Loading branch information
donpdonp committed Jan 8, 2025
1 parent 2ab07d6 commit d0c76fd
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
9 changes: 8 additions & 1 deletion src/config.zig
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,13 @@ pub const ColumnConfig = struct {
img_only: bool,

const Self = @This();

pub fn reset(self: *Self) *Self {
self.title = "";
self.filter = "mastodon.example.com";
self.token = null;
return self;
}
};

pub const LoginInfo = struct {
Expand Down Expand Up @@ -189,7 +196,7 @@ pub fn writefile(settings: Settings, filename: []const u8) void {
configFile.columns = column_infos.items;
if (std.fs.cwd().createFile(filename, .{ .truncate = true })) |*file| {
warn("config.write toJson\n", .{});
//std.json.stringify(configFile, std.json.StringifyOptions{}, file.writer()) catch unreachable;
std.json.stringify(configFile, std.json.StringifyOptions{}, file.writer()) catch unreachable;
warn("config saved. {s} {} bytes\n", .{ filename, file.getPos() catch unreachable });
file.close();
} else |err| {
Expand Down
6 changes: 2 additions & 4 deletions src/main.zig
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ pub fn main() !void {

if (config.readfile(config.config_file_path())) |config_data| {
settings = config_data;
try gui.init(alloc, &settings);
const dummy_payload = alloc.create(thread.CommandVerb) catch unreachable;
_ = thread.create("gui", gui.go, dummy_payload, guiback) catch unreachable;
_ = thread.create("heartbeat", heartbeat.go, dummy_payload, heartback) catch unreachable;
Expand All @@ -55,7 +56,6 @@ fn initialize(allocator: std.mem.Allocator) !void {
try db.init(allocator);
try dbfile.init();
try thread.init(allocator);
try gui.init(allocator, &settings);
}

fn statewalk(allocator: std.mem.Allocator) void {
Expand Down Expand Up @@ -341,9 +341,7 @@ fn guiback(command: *thread.Command) void {
colInfo.last_check = 0;
settings.columns.append(colInfo) catch unreachable;
const colConfig = alloc.create(config.ColumnConfig) catch unreachable;
colInfo.config = colConfig;
colInfo.config.title = ""[0..];
colInfo.config.filter = "mastodon.example.com"[0..];
colInfo.config = colConfig.reset();
colInfo.filter = filter_lib.parse(alloc, colInfo.config.filter);
gui.schedule(gui.add_column_schedule, @as(*anyopaque, @ptrCast(colInfo)));
config.writefile(settings, "config.json");
Expand Down

0 comments on commit d0c76fd

Please sign in to comment.