Skip to content

Commit 22031ac

Browse files
committed
10102218
1 parent 89c058f commit 22031ac

19 files changed

+284
-150
lines changed

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@ it simply tracks your mouse and keyboard usage on your system by reading `/dev/i
3737
when they become idle for 2 min, the app considers your time as "waste time" and as you come back it will continue normally.
3838

3939
#### How to use it?
40-
You can directly use the `/build/clocker` binary file by copying it to the `/bin` system directory.
40+
You can directly use the `/build/clocker` binary file by copying it to the `/usr/bin` system directory.
4141
or make source easily by running `make && make install` in the root directory of the project (recommended).
42-
it will copy `clocker` to `/bin` and clocker updater to `/root/.clocker`.
42+
it will copy `clocker` and `clocker updater` to `/usr/bin`.
4343
for run clocker run:
4444
```
4545
$ sudo clocker

common/info.h common/defs.h

+20-5
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,34 @@
1515
// You should have received a copy of the GNU General Public License
1616
// along with Clocker. If not, see <http://www.gnu.org/licenses/>.
1717

18-
#ifndef COMMON_INFO_H
19-
#define COMMON_INFO_H
18+
#ifndef COMMON_DEFS_H
19+
#define COMMON_DEFS_H
2020

2121
#include "../includes/common/inc.h"
2222

23-
Str clocker_banner = COLOR_TRANSPARENT"\n"\
23+
#define INIT_VERSION "0.2-beta.0"
24+
25+
#define CLOCKER_BANNER COLOR_TRANSPARENT"\n"\
2426
" █████████ ████ █████\n" \
2527
" ███░░░░░███░░███ ░░███\n" \
2628
" ███ ░░░ ░███ ██████ ██████ ░███ █████ ██████ ████████\n" \
2729
"░███ ░███ ███░░███ ███░░███ ░███░░███ ███░░███░░███░░███\n" \
2830
"░███ ░███ ░███ ░███░███ ░░░ ░██████░ ░███████ ░███ ░░░\n" \
2931
"░░███ ███ ░███ ░███ ░███░███ ███ ░███░░███ ░███░░░ ░███\n" \
3032
" ░░█████████ █████░░██████ ░░██████ ████ █████░░██████ █████\n" \
31-
" ░░░░░░░░░ ░░░░░ ░░░░░░ ░░░░░░ ░░░░ ░░░░░ ░░░░░░ ░░░░░\n"COLOR_RESET;
33+
" ░░░░░░░░░ ░░░░░ ░░░░░░ ░░░░░░ ░░░░ ░░░░░ ░░░░░░ ░░░░░\n"COLOR_RESET
34+
35+
36+
#define ERR_TXT(txt_) COLOR_RED txt_ COLOR_RESET
37+
#define WRN_TXT(txt_) COLOR_YELLOW txt_ COLOR_RESET
38+
#define OK_TXT(txt_) COLOR_GREEN txt_ COLOR_RESET
39+
#define INF_TXT(txt_) COLOR_B_CYAN txt_ COLOR_RESET
40+
41+
#define DNG_TXT(txt_) COLOR_B_RED txt_ COLOR_RESET
42+
#define ATT_TXT(txt_) COLOR_B_YELLOW txt_ COLOR_RESET
43+
44+
#define TRANSPARENT_TXT(txt_) COLOR_TRANSPARENT txt_ COLOR_RESET
45+
#define BOLD_TXT(txt_) COLOR_BOLD txt_ COLOR_RESET
46+
#define ITALIC_TXT(txt_) COLOR_ITALIC txt_ COLOR_RESET
3247

33-
#endif // COMMON_INFO_H
48+
#endif // COMMON_DEFS_H

headers/cmd.h

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#define HEADERS_CMD_H
2020

2121
#include "../includes/common/inc.h"
22+
#include "../headers/mutexed.h"
2223

2324
Hndl cmd_run(Hndl state);
2425

headers/listener.h

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#define HEADERS_LISTENER_H
2020

2121
#include "../includes/common/inc.h"
22+
#include "../common/defs.h"
2223

2324
typedef UInt64 Listener;
2425

headers/sig_handler.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,10 @@
2020

2121
#include <signal.h>
2222
#include "../includes/common/inc.h"
23+
#include "../common/defs.h"
2324

2425
typedef sig_t Sig;
2526

26-
Sig sig_handler(Int32 signal);
27+
Void signal_handler(Int32 signal);
2728

2829
#endif // HEADERS_SIG_HANDLER_H

headers/env.h headers/thread_arg.h

+39
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,46 @@
1919
#define HEADERS_ENV_H
2020

2121
#include "../includes/common/inc.h"
22+
#include "../headers/mutexed.h"
2223

24+
typedef enum {
25+
TM_Default,
26+
TM_Busy,
27+
TM_Paused
28+
}
29+
TimeMode;
2330

31+
typedef enum {
32+
TC_None,
33+
TC_End,
34+
TC_Report,
35+
TC_Pause,
36+
TC_Resume
37+
}
38+
TimeCommand;
39+
40+
typedef struct {
41+
Str version;
42+
Mutexed* mode;
43+
Mutexed* command;
44+
}
45+
TreadArg;
46+
47+
48+
INLINE Str time_mode_from(TimeMode mode) {
49+
switch (mode) {
50+
case TM_Default:
51+
return "default";
52+
53+
case TM_Busy:
54+
return "busy";
55+
56+
case TM_Paused:
57+
return WRN_TXT("paused");
58+
59+
default:
60+
return "";
61+
}
62+
}
2463

2564
#endif // HEADERS_ENV_H

headers/time_handler.h

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#define HEADERS_TIME_HANDLE_H
2020

2121
#include "../includes/common/inc.h"
22+
#include "../headers/thread_arg.h"
2223

2324
Hndl time_handle(Void* arg);
2425

headers/updater_checker.h

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#define HEADERS_UPDATECHRCKER_H
2222

2323
#include "../includes/common/inc.h"
24+
#include "../common/defs.h"
2425

2526
typedef enum {
2627
US_Error,

includes/prims/inc/debug.h

+6
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,12 @@
3939
#define COLOR_CYAN "\x1b[36m"
4040
#define COLOR_RESET "\x1b[0m"
4141

42+
#define COLOR_B_RED "\x1b[91m"
43+
#define COLOR_B_GREEN "\x1b[92m"
44+
#define COLOR_B_YELLOW "\x1b[93m"
45+
#define COLOR_B_BLUE "\x1b[94m"
46+
#define COLOR_B_CYAN "\x1b[96m"
47+
4248
#define __FILENAME__ (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILE__)
4349

4450
#define ERR_LBL "ERR"

makefile

+11-8
Original file line numberDiff line numberDiff line change
@@ -29,22 +29,25 @@ clocker := ${current}/src/clocker.c
2929
updater := ${current}/src/updater.c
3030

3131
buildClocker := ${current}/build/clocker
32-
buildUpdater := ${current}/build/updater
32+
buildUpdater := ${current}/build/clocker-updater
3333

3434
all:
3535
@mkdir -p ${current}/build
36-
@gcc -w -g ${component} ${clocker} -o ${buildClocker} -lpthread
37-
@gcc -w -g ${updater} ${current}/src/components/update_checker.c -o ${buildUpdater} -lpthread
36+
@gcc -fcompare-debug-second -w -g ${component} ${clocker} -o ${buildClocker} -lpthread
37+
@gcc -fcompare-debug-second -w -g ${updater} ${current}/src/components/update_checker.c -o ${buildUpdater} -lpthread
3838

3939
install:
40-
@mkdir -p /root/.clocker
41-
@gcc -w -g ${component} ${clocker} -o /bin/clocker -lpthread
42-
@gcc -w -g ${updater} ${current}/src/components/update_checker.c -o /root/.clocker/clocker-updater -lpthread
40+
@mkdir -p /root/.config/clocker
41+
@cp ${buildClocker} /usr/bin
42+
@cp ${buildUpdater} /usr/bin
4343

4444
run:
4545
@sudo ${buildClocker}
4646

47+
clean:
48+
@rm -rf ${current}/build/
4749

4850
uninstall:
49-
@rm -rf /root/.clocker
50-
@rm /bin/clocker
51+
@rm -rf /root/.config/clocker
52+
@rm /usr/bin/clocker
53+
@rm /usr/bin/clocker-updater

src/clocker.c

+27-18
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
#include <string.h>
2323
#include <signal.h>
2424

25-
#include "../common/info.h"
25+
#include "../common/defs.h"
2626
#include "../includes/common/inc.h"
2727
#include "../headers/time_handler.h"
2828
#include "../headers/mutexed.h"
@@ -33,12 +33,7 @@
3333
typedef pthread_t Thread;
3434

3535

36-
Void clocker_update_checking() {
37-
Updater checker = update_checker_new();
38-
soft_assert_wrn(
39-
checker != 0,
40-
"Creating new update object failed!"
41-
);
36+
Void clocker_update_checking(Updater checker) {
4237

4338
UpdateStatus update_check_res = update_checker_check(checker);
4439
soft_assert_wrn(
@@ -54,8 +49,8 @@ Void clocker_update_checking() {
5449

5550
Char result = fgetc(stdin);
5651
if (result == '\n' || result == 'Y' || result == 'y') {
57-
Str arg[2] = {"/root/.clocker/clocker-updater", INVALID_HNDL};
58-
execvp("/root/.clocker/clocker-updater", arg);
52+
Str arg[3] = {"/usr/bin/clocker-updater", "--from-clocker", INVALID_HNDL};
53+
execvp("/usr/bin/clocker-updater", arg);
5954
perror("");
6055
}
6156
else {
@@ -74,26 +69,40 @@ Int32 main(
7469
) {
7570

7671
// signal handling
77-
signal(SIGINT, sig_handler);
78-
signal(SIGSEGV, sig_handler);
72+
signal(SIGINT, signal_handler);
73+
signal(SIGSEGV, signal_handler);
74+
75+
76+
Updater checker = update_checker_new();
77+
soft_assert_wrn(
78+
checker != 0,
79+
"Creating new update object failed!"
80+
);
7981

8082
if (argv[1] && strcmp(argv[1], "--update") == 0) {
81-
clocker_update_checking();
83+
clocker_update_checking(checker);
8284
}
8385

84-
printf("%s\n\n", clocker_banner);
85-
printf("Type "COLOR_ITALIC"`help`"COLOR_RESET" to list supported commands\n");
8686

87-
Mutexed* state = mutexed_new(gen_type(0));
88-
soft_assert_ret_int(state != INVALID_HNDL, "Failed to create new mutexed!");
87+
printf("%s\n\n", CLOCKER_BANNER);
88+
printf("Type "ITALIC_TXT("`help`")" to list supported commands\n");
89+
90+
TreadArg thread_arg = (TreadArg) {
91+
.command = mutexed_new(gen_type(TC_None)),
92+
.mode = mutexed_new(gen_type(TM_Default)),
93+
.version = update_checker_get_version(checker)
94+
};
95+
soft_assert_ret_int(thread_arg.command != INVALID_HNDL, "Failed to create new mutexed!");
96+
soft_assert_ret_int(thread_arg.mode != INVALID_HNDL, "Failed to create new mutexed!");
97+
8998

9099
// creating time handling thread
91100
Thread timer_thread = 0;
92101
pthread_create(
93102
&timer_thread,
94103
INVALID_HNDL,
95104
time_handle,
96-
(Hndl) state
105+
(Hndl) &thread_arg
97106
);
98107

99108
// creating cmd handling thread
@@ -102,7 +111,7 @@ Int32 main(
102111
&cmd_thread,
103112
INVALID_HNDL,
104113
cmd_run,
105-
(Hndl) state
114+
(Hndl) &thread_arg
106115
);
107116

108117
// waiting for time thread

0 commit comments

Comments
 (0)