Fix wrong session index + save file corruption

Signed-off-by: AnErrupTion <anerruption@disroot.org>
This commit is contained in:
AnErrupTion
2025-12-06 14:25:01 +01:00
parent a9ff0a6d07
commit e6966a628c
5 changed files with 26 additions and 3 deletions

View File

@@ -46,7 +46,10 @@ pub fn addEnvironment(self: *Session, environment: Environment) !void {
fn sessionChanged(env: Env, maybe_user_list: ?*UserList) void {
if (maybe_user_list) |user_list| {
user_list.label.list.items[user_list.label.current].session_index.* = env.index;
const user = user_list.label.list.items[user_list.label.current];
if (!user.first_run) return;
user.session_index.* = env.index;
}
}

View File

@@ -11,6 +11,7 @@ pub const User = struct {
name: []const u8,
session_index: *usize,
allocated_index: bool,
first_run: bool,
};
const UserLabel = generic.CyclableLabel(User, *Session);
@@ -27,9 +28,11 @@ pub fn init(allocator: Allocator, buffer: *TerminalBuffer, usernames: StringList
if (username.len == 0) continue;
var maybe_session_index: ?*usize = null;
var first_run = true;
for (saved_users.user_list.items) |*saved_user| {
if (std.mem.eql(u8, username, saved_user.username)) {
maybe_session_index = &saved_user.session_index;
first_run = saved_user.first_run;
break;
}
}
@@ -45,6 +48,7 @@ pub fn init(allocator: Allocator, buffer: *TerminalBuffer, usernames: StringList
.name = username,
.session_index = maybe_session_index.?,
.allocated_index = allocated_index,
.first_run = first_run,
});
}