aboutsummaryrefslogtreecommitdiffstats
path: root/main.c
diff options
context:
space:
mode:
authorNRK <nrk@disroot.org>2023-10-01 13:06:04 +0200
committerNRK <nrk@disroot.org>2023-10-01 13:23:29 +0200
commit1fc28278b55a5835bfd57821619141bd92eed91d (patch)
tree1d7e9776b6cc542bd9acfe6460c5aa5efd372af4 /main.c
parent2093f36661194f6f820c1233ff8857656a4d1dfe (diff)
downloadnsxiv-1fc28278b55a5835bfd57821619141bd92eed91d.tar.zst
add option to update cache in a background process
the cli flag is undocumented for now, since it's experimental. Closes: https://codeberg.org/nsxiv/nsxiv/issues/416 Closes: https://codeberg.org/nsxiv/nsxiv/pulls/425 Co-authored-by: explosion-mental <explosion0mental@gmail.com>
Diffstat (limited to 'main.c')
-rw-r--r--main.c17
1 files changed, 17 insertions, 0 deletions
diff --git a/main.c b/main.c
index a050aa8..e0ff5b3 100644
--- a/main.c
+++ b/main.c
@@ -936,6 +936,23 @@ int main(int argc, char *argv[])
filecnt = fileidx;
fileidx = options->startnum < filecnt ? options->startnum : 0;
+ if (options->background_cache && !options->private_mode) {
+ pid_t ppid = getpid(); /* to check if parent is still alive or not */
+ switch (fork()) {
+ case 0:
+ tns_init(&tns, files, &filecnt, &fileidx, NULL);
+ while (filecnt > 0 && getppid() == ppid) {
+ tns_load(&tns, filecnt - 1, false, true);
+ remove_file(filecnt - 1, true);
+ }
+ exit(0);
+ break;
+ case -1:
+ error(0, errno, "fork failed");
+ break;
+ }
+ }
+
win_init(&win);
img_init(&img, &win);
arl_init(&arl);