feat(tabs): don't write tab styles config if it doesn't already exist
This commit is contained in:
parent
8eb536b5b9
commit
2371140b3f
2 changed files with 15 additions and 2 deletions
10
src/main.zig
10
src/main.zig
|
@ -406,6 +406,16 @@ pub fn free_config(allocator: std.mem.Allocator, bufs: [][]const u8) void {
|
|||
|
||||
var config_mutex: std.Thread.Mutex = .{};
|
||||
|
||||
pub fn exists_config(T: type) bool {
|
||||
config_mutex.lock();
|
||||
defer config_mutex.unlock();
|
||||
const json_file_name = get_app_config_file_name(application_name, @typeName(T)) catch return false;
|
||||
const text_file_name = json_file_name[0 .. json_file_name.len - ".json".len];
|
||||
var file = std.fs.openFileAbsolute(text_file_name, .{ .mode = .read_only }) catch return false;
|
||||
defer file.close();
|
||||
return true;
|
||||
}
|
||||
|
||||
pub fn read_config(T: type, allocator: std.mem.Allocator) struct { T, [][]const u8 } {
|
||||
config_mutex.lock();
|
||||
defer config_mutex.unlock();
|
||||
|
|
|
@ -80,8 +80,11 @@ const TabBar = struct {
|
|||
fn init(allocator: std.mem.Allocator, parent: Plane, event_handler: ?EventHandler) !Self {
|
||||
var w = try WidgetList.createH(allocator, parent, "tabs", .dynamic);
|
||||
w.ctx = w;
|
||||
const tab_style, const tab_style_bufs = root.read_config(Style, allocator);
|
||||
root.write_config(tab_style, allocator) catch {};
|
||||
const tab_style, const tab_style_bufs: [][]const u8 = if (root.exists_config(Style)) blk: {
|
||||
const tab_style, const tab_style_bufs = root.read_config(Style, allocator);
|
||||
root.write_config(tab_style, allocator) catch {};
|
||||
break :blk .{ tab_style, tab_style_bufs };
|
||||
} else .{ Style{}, &.{} };
|
||||
return .{
|
||||
.allocator = allocator,
|
||||
.plane = w.plane,
|
||||
|
|
Loading…
Add table
Reference in a new issue