aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authoraxtlos <axtlos@getcryst.al>2024-05-28 22:32:33 +0200
committeraxtlos <axtlos@getcryst.al>2024-05-28 22:32:33 +0200
commitaa800ed218603f04dd30596be18fb59c2f8e1205 (patch)
tree80d9d56b3998857d6c6d35fc4e3801b4f21596ae /src
parent97ad7eece798776d2b38e29ce0b0b216309e3ef1 (diff)
downloadautodarkmode-aa800ed218603f04dd30596be18fb59c2f8e1205.tar.gz
autodarkmode-aa800ed218603f04dd30596be18fb59c2f8e1205.tar.bz2
Dont use lock file every time to check if theme needs to be changed
Diffstat (limited to '')
-rw-r--r--src/main.c49
1 files changed, 31 insertions, 18 deletions
diff --git a/src/main.c b/src/main.c
index 6302e51..4265d3f 100644
--- a/src/main.c
+++ b/src/main.c
@@ -37,6 +37,8 @@ GMainLoop *main_loop;
enum LocationType loctype = 0;
dictionary *dict = NULL;
bool quit = false;
+bool firstrun = true;
+bool isdark = false;
float lat = 0;
float lng = 0;
@@ -55,14 +57,18 @@ void
on_dark (void)
{
char *home = getenv ("HOME");
- char *darklock;
- if (home != NULL) {
- darklock = malloc(strlen(home)*sizeof(char)+strlen("/.cache/darkmode")*sizeof(char)+1);
- sprintf (darklock, "%s/.cache/darkmode", home);
- if (access(darklock, F_OK) == 0) {
- free (darklock);
- return;
- }
+ char *darklock = malloc(strlen(home)*sizeof(char)+strlen("/.cache/darkmode")*sizeof(char)+1);
+ sprintf (darklock, "%s/.cache/darkmode", home);
+ if (firstrun) {
+ if (home != NULL) {
+ if (access(darklock, F_OK) == 0) {
+ free (darklock);
+ isdark = true;
+ return;
+ }
+ }
+ } else if (isdark) {
+ return;
}
const char *dark_command = iniparser_getstring (dict, "dark:cmd", "");
@@ -78,21 +84,26 @@ on_dark (void)
}
FILE *dark = fopen (darklock, "w");
fclose (dark);
+ free (darklock);
+ isdark = true;
}
void
on_light (void)
{
- char *home = getenv ("HOME");
- char *darklock;
- if (home != NULL) {
- darklock = malloc(strlen(home)*sizeof(char)+strlen("/.cache/darkmode")*sizeof(char)+1);
- sprintf (darklock, "%s/.cache/darkmode", home);
- if (access(darklock, F_OK) != 0) {
- free (darklock);
- return;
- }
-
+ char *home = getenv("HOME");
+ char *darklock = malloc(strlen(home)*sizeof(char)+strlen("/.cache/darkmode")*sizeof(char)+1);
+ sprintf (darklock, "%s/.cache/darkmode", home);
+ if (firstrun) {
+ if (home != NULL) {
+ if (access(darklock, F_OK) != 0) {
+ free (darklock);
+ isdark = true;
+ return;
+ }
+ }
+ } else if (!isdark) {
+ return;
}
const char *light_command = iniparser_getstring (dict, "light:cmd", "");
@@ -109,6 +120,7 @@ on_light (void)
remove (darklock);
free (darklock);
+ isdark = false;
}
void
@@ -127,6 +139,7 @@ loop (void)
on_dark ();
else
on_light ();
+ firstrun = false;
}
void