Decouple save file path from config directory (closes #1025)

Signed-off-by: AnErrupTion <anerruption@disroot.org>
This commit is contained in:
AnErrupTion 2026-07-06 22:11:52 +02:00
parent a41ebe8f6f
commit 78c7c2e2e8
No known key found for this signature in database
4 changed files with 25 additions and 10 deletions

View File

@ -348,8 +348,9 @@ path = /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
# If null, the keybind is disabled and isn't shown
restart_key = F2
# Save the current desktop and login as defaults, and load them on startup
save = true
# Absolute directory for the save file
# If null, current desktop & login won't be saved nor loaded
save_file_dir = $CONFIG_DIRECTORY/ly
# Service name (set to ly to use the provided pam config file)
service_name = ly

View File

@ -80,7 +80,7 @@ margin_box_v: u8 = 1,
numlock: bool = false,
path: ?[]const u8 = "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
restart_key: ?[]const u8 = "F2",
save: bool = true,
save_file_dir: ?[]const u8 = build_options.config_directory ++ "/ly",
service_name: [:0]const u8 = "ly",
session_log: ?[]const u8 = "ly-session.log",
setup_cmd: []const u8 = build_options.config_directory ++ "/ly/setup.sh",

View File

@ -2,6 +2,7 @@
// Properties removed or changed since 0.6.0
// Color codes interpreted differently since 1.1.0
const build_options = @import("build_options");
const std = @import("std");
var temporary_allocator = std.heap.page_allocator;
@ -194,6 +195,19 @@ pub fn configFieldHandler(_: std.mem.Allocator, field: ini.IniField) ?ini.IniFie
return null;
}
if (std.mem.eql(u8, field.key, "save")) {
// The option now uses a string for the file's parent directory
var mapped_field = field;
if (std.mem.eql(u8, field.value, "true")) {
mapped_field.value = build_options.config_directory ++ "/ly";
} else if (std.mem.eql(u8, field.value, "false")) {
mapped_field.value = "null";
}
return mapped_field;
}
// TODO: Dearest Melpert,
// I pray this message finds you well, as daylight dwindles and the witching hour
// approaches, I find it more and more imperative as time continues that I place

View File

@ -224,7 +224,7 @@ pub fn main(init: std.process.Init) !void {
}
// Load configuration file
defer if (state.config.save) {
defer if (state.config.save_file_dir != null) {
state.allocator.free(state.save_path);
state.allocator.free(state.old_save_path);
};
@ -266,8 +266,8 @@ pub fn main(init: std.process.Init) !void {
state.lang = lang_parser.structure;
if (state.config.save) {
state.save_path = try std.Io.Dir.path.join(state.allocator, &[_][]const u8{ config_parent_path, "save.txt" });
if (state.config.save_file_dir) |dir| {
state.save_path = try std.Io.Dir.path.join(state.allocator, &[_][]const u8{ dir, "save.txt" });
state.old_save_path = try std.Io.Dir.path.join(state.allocator, &[_][]const u8{ config_parent_path, "save.ini" });
}
@ -285,7 +285,7 @@ pub fn main(init: std.process.Init) !void {
state.has_old_save = false;
state.saved_username = null;
if (state.config.save) read_save_file: {
if (state.config.save_file_dir != null) read_save_file: {
old_save_parser = migrator.tryMigrateIniSaveFile(state.allocator, state.io, state.old_save_path, &state.saved_users, usernames.items) catch break :read_save_file;
// Don't read the new save file if the old one still exists
@ -335,7 +335,7 @@ pub fn main(init: std.process.Init) !void {
// If no save file previously existed, fill it up with all usernames
// TODO: Add new username with existing save file
if (state.config.save and state.saved_users.user_list.items.len == 0) {
if (state.config.save_file_dir != null and state.saved_users.user_list.items.len == 0) {
for (usernames.items) |user| {
try state.saved_users.user_list.append(state.allocator, .{
.username = user,
@ -1118,7 +1118,7 @@ pub fn main(init: std.process.Init) !void {
// Skip if autologin is active to prevent overriding autologin session
var default_input = state.config.default_input;
if (state.config.save and !state.is_autologin) {
if (state.config.save_file_dir != null and !state.is_autologin) {
if (state.login_text) |box| {
if (state.saved_username) |username| {
defer state.allocator.free(username);
@ -1502,7 +1502,7 @@ fn authenticate(ptr: *anyopaque) !bool {
try TerminalBuffer.presentBuffer();
}
if (state.config.save) save_last_settings: {
if (state.config.save_file_dir != null) save_last_settings: {
// It isn't worth cluttering the code with precise error
// handling, so let's just report a generic error message,
// that should be good enough for debugging anyway.