51 lines
1.6 KiB
Zig
51 lines
1.6 KiB
Zig
running: bool = true,
|
|
usage_number: locked(u16) = .{ .data = 0 },
|
|
current_items: locked(?[]*models.Item) = .{ .data = null },
|
|
current_items_allocator: std.heap.ArenaAllocator,
|
|
appState: AppState,
|
|
_private: Private,
|
|
|
|
const Private = struct {
|
|
preCurrentItemsUnload: Observer(*Tab),
|
|
};
|
|
|
|
pub fn init(model: *Self, currentItemsAllocator: std.heap.ArenaAllocator, appState: AppState) !void {
|
|
model.* = Self{
|
|
.current_items_allocator = currentItemsAllocator,
|
|
.appState = appState,
|
|
._private = .{
|
|
.preCurrentItemsUnload = Observer(*Tab){
|
|
.ctx = @ptrCast(@alignCast(model)),
|
|
.update = preCurrentItemsUnload,
|
|
},
|
|
},
|
|
};
|
|
|
|
try model.appState.tabPreCurrentItemsUnload.attach(&model._private.preCurrentItemsUnload);
|
|
}
|
|
|
|
pub fn preCurrentItemsUnload(ctx: *anyopaque, tab: *Tab) void {
|
|
const self: *Self = @ptrCast(@alignCast(ctx));
|
|
if (tab == self.appState.currentTab) {
|
|
// @panic("asdasdasd");
|
|
self.current_items.mutex.lock();
|
|
defer self.current_items.mutex.unlock();
|
|
|
|
self.current_items.data = null;
|
|
}
|
|
}
|
|
|
|
pub fn deinit(self: *@This()) void {
|
|
self.appState.tabPreCurrentItemsUnload.detach(&self._private.preCurrentItemsUnload);
|
|
self.appState.deinit();
|
|
self.current_items_allocator.deinit();
|
|
}
|
|
|
|
const std = @import("std");
|
|
const models = @import("../core/models.zig");
|
|
const Tab = @import("../core/tab/tab.zig").Tab;
|
|
const locked = @import("../core/sync.zig").locked;
|
|
const AppState = @import("../core/app_state.zig").AppState;
|
|
const Observer = @import("../core/observable.zig").Observer;
|
|
const Self = @This();
|