mirror of
https://github.com/fairyglade/ly.git
synced 2025-12-21 03:34:54 +00:00
Fix wrong session index + save file corruption
Signed-off-by: AnErrupTion <anerruption@disroot.org>
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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,
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user