linux-window-session-manager
linux-window-session-manager copied to clipboard
Auto shutdown/startup script
Not really an issue with LWSM as I am able to run the commands fine. I'm having some trouble getting an auto shutdown/startup script going. Would appreciate it if anyone has any solutions, cheers!
Your Environment
- Version used: lwsm 4.0.5
- Operating System and version: Fedora 35
- Desktop Environment: Gnome
- Node version: v16.13.0
- List of Applications that are open (lwsm save) or should be opened (lwsm restore): Chrome, Files
Expected Behavior
No errors
Current Behavior
Dec 26 11:30:40 wuxhua systemd[1]: Starting Linux Window Session Manager Pre-Shutdown Processes...
░░ Subject: A start job for unit save_session.service has begun execution
░░ Defined-By: systemd
░░ Support: https://lists.freedesktop.org/mailman/listinfo/systemd-devel
░░
░░ A start job for unit save_session.service has begun execution.
░░
░░ The job identifier is 6022.
Dec 26 11:30:40 wuxhua bash[7100]: lwsm: no config file present or it contains invalid json. Creating new one...
Dec 26 11:30:40 wuxhua bash[7100]: /usr/local/lib/node_modules/linux-window-session-manager/dist/index.js:84
Dec 26 11:30:40 wuxhua bash[7100]: throw err;
Dec 26 11:30:40 wuxhua bash[7100]: ^
Dec 26 11:30:40 wuxhua bash[7100]: Error: ENOENT: no such file or directory, mkdir 'undefined/.config/lwsm'
Dec 26 11:30:40 wuxhua bash[7100]: at Object.mkdirSync (node:fs:1334:3)
Dec 26 11:30:40 wuxhua bash[7100]: at mkdirSync (/usr/local/lib/node_modules/linux-window-session-manager/dist/index.js:80:12)
Dec 26 11:30:40 wuxhua bash[7100]: at Object.
Steps to Reproduce (for bugs)
Script stored in home/wuxhua/Scripts/save_session.sh
/usr/local/bin/lwsm list
Servicemd Service
`[Unit] Description=Linux Window Session Manager Pre-Shutdown Processes DefaultDependencies=no After=final.target
[Service] Type=oneshot ExecStart=bash /home/wuxhua/Scripts/save_session.sh
[Install] WantedBy=final.target`
Im not very familiar with this application, but it seems that it is user based. If you are running this in a service, it is likely not running as the required user.
I think you would need a startup app (added to your session startup) and one for logout which I'm not sure how that would work. It would probably be easy enough to have a cron job running for the user to regularly save the session?
Im trying some of this out at the moment. Will let you know how I go.
[ Update ] I dont think this will work as I expect. The program doesnt restore apps to correct positions or sizes and virtual screens. Much easier to have a manual hibernate. Im kind of puzzled why linux doesnt have a "snapshot" mechanism built into the system - essentially restoring the current memory layout for a session. Maybe I'll write one :)
I am also having issues creating a systemd service that saves the layout when suspending and restores it when resuming.
I am getting errors. Presumably because systemd does not have the environment variables set that my user has.
If somebody can make this work I'd be so happy :)
The zsh scripts themselves work from cli.
/etc/systemd/system/save-layout.service
──────────────────────────────────────────────────────────────────────────────
[Unit]
Description=Save window layout to json
Before=sleep.target
[Service]
User=cocoonkid
Environment=DISPLAY=:0
ExecStart=bash /home/cocoonkid/save-lwsm.sh
ExecStartPost=bash /home/cocoonkid/restore-lwsm.sh
[Install]
WantedBy=sleep.target
save-lwsm.sh
──────────────────────────────────────────────────────────────────────────────
#! /usr/bin/zsh
zsh -i -c "lwsm save default"
restore-lwsm.sh
──────────────────────────────────────────────────────────────────────────────
#! /usr/bin/zsh
zsh -i -c "lwsm restore default"