Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix potential bugs in autostart scripts #78

Merged
merged 1 commit into from
Mar 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions modules/files.nix
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,13 @@ let
# The files in overrideConfigFiles are in XDG_CONFIG_HOME, so we need to
# add this to the names to get the full path
(map (f: "${config.xdg.configHome}/${f}") (lib.lists.subtractLists cfg.overrideConfigExclude cfg.overrideConfigFiles)))
# Some of the startup-scripts may keep track of when they were last ran
# in order to only run once for each generation. These files start with
# last_run and is located in $XDG_DATA_HOME/plasma-manager. When we
# reset all the other config-files these startup-scripts should be
# re-ran, so we delete these files to ensure they are.
# Some of the startup-scripts may keep track of when they were last run,
# in order to only run the scripts once for each home-manager generation.
# However when we use overrideConfig we need to run these scripts after
# every activation (i.e. after applying a new home-manager generation or
# after a fresh boot) as the scripts typically write some config-files
# which will need to be written once again after the old configs are
# deleted on each activation.
++ [ "for file in ${config.xdg.dataHome}/plasma-manager/last_run_*; do ${removeFileIfExistsCmd "$file"}; done" ]));
in
{
Expand Down
20 changes: 15 additions & 5 deletions modules/panels.nix
Original file line number Diff line number Diff line change
Expand Up @@ -177,19 +177,29 @@ in
${panelsToLayoutJS config.programs.plasma.panels}
'';

# Very similar to applying themes, we keep track of the last time the panel
# was generated successfully, and run this only once per generation (granted
# everything succeeds and we are not using overrideConfig).
programs.plasma.startup.autoStartScript."apply_layout" = {
text = ''
layout_file="${config.xdg.dataHome}/plasma-manager/${cfg.startup.dataDir}/layout.js"
last_update=$(stat -c %Y $layout_file)
last_update="$(sha256sum $layout_file)"
last_update_file=${config.xdg.dataHome}/plasma-manager/last_run_layouts
stored_last_update=0
if [ -f "$last_update_file" ]; then
stored_last_update=$(cat "$last_update_file")
fi

[ "$last_update" -ne "$stored_last_update" ] && \
qdbus org.kde.plasmashell /PlasmaShell org.kde.PlasmaShell.evaluateScript "$(cat $layout_file)" && \
echo "$last_update" > "$last_update_file"
if ! [ "$last_update" = "$stored_last_update" ]; then
# We delete plasma-org.kde.plasma.desktop-appletsrc to hinder it
# growing indefinitely. See:
# https://github.com/pjones/plasma-manager/issues/76
[ -f ${config.xdg.configHome}/plasma-org.kde.plasma.desktop-appletsrc ] && rm ${config.xdg.configHome}/plasma-org.kde.plasma.desktop-appletsrc

# And finally apply the layout.js
success=1
qdbus org.kde.plasmashell /PlasmaShell org.kde.PlasmaShell.evaluateScript "$(cat $layout_file)" || success=0
[ $success -eq 1 ] && echo "$last_update" > "$last_update_file"
fi
'';
# Setting up the panels should happen after setting the theme as the theme
# may overwrite some settings (like the kickoff-icon)
Expand Down
11 changes: 5 additions & 6 deletions modules/workspace.nix
Original file line number Diff line number Diff line change
Expand Up @@ -100,26 +100,25 @@ in
{
# We create a script which applies the different theme settings using
# kde tools. We then run this using an autostart script, where this is
# run only on the first login, granted all the commands succeed (until
# we change the settings again).
# run only on the first login (unless overrideConfig is enabled),
# granted all the commands succeed (until we change the settings again).
programs.plasma.startup.autoStartScript."apply_themes" = {
text = ''
last_update=$(stat -c %Y "$0")
last_update=$(sha256sum "$0")
last_update_file=${config.xdg.dataHome}/plasma-manager/last_run_themes
stored_last_update=0
if [ -f "$last_update_file" ]; then
stored_last_update=$(cat "$last_update_file")
fi

if [ $last_update -gt $stored_last_update ]; then
if ! [ "$last_update" = "$stored_last_update" ]; then
success=1
${if cfg.workspace.lookAndFeel != null then "plasma-apply-lookandfeel -a ${cfg.workspace.lookAndFeel} || success=0" else ""}
${if cfg.workspace.theme != null then "plasma-apply-desktoptheme ${cfg.workspace.theme} || success=0" else ""}
${if cfg.workspace.cursorTheme != null then "plasma-apply-cursortheme ${cfg.workspace.cursorTheme} || success=0" else ""}
${if cfg.workspace.colorScheme != null then "plasma-apply-colorscheme ${cfg.workspace.colorScheme} || success=0" else ""}
${if cfg.workspace.iconTheme != null then "${pkgs.libsForQt5.plasma-workspace}/libexec/plasma-changeicons ${cfg.workspace.iconTheme} || success=0" else ""}
${if cfg.workspace.wallpaper != null then "plasma-apply-wallpaperimage ${cfg.workspace.wallpaper} || success=0" else ""}
[ $success = 1 ] && echo "$last_update" > "$last_update_file"
[ $success -eq 1 ] && echo "$last_update" > "$last_update_file"
fi
'';
priority = 1;
Expand Down
Loading