Skip to content

Commit

Permalink
v1.8.0 - Update depencencies && Fixes && UI Changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Lukylix committed Jan 30, 2024
1 parent 3edaf7c commit 10f5031
Show file tree
Hide file tree
Showing 32 changed files with 1,350 additions and 1,157 deletions.
1 change: 0 additions & 1 deletion .yarnrc.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
yarnPath: .yarn/releases/yarn-4.0.1.cjs
nodeLinker: node-modules
Binary file modified Home.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2024, Lucas Garcia (lukylix)

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
Binary file modified ProjectDetails.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion electron-builder.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ files:
- '!{.env,.env.*,.npmrc,pnpm-lock.yaml}'
asarUnpack:
- resources/*
afterSign: build/notarize.js
afterSign: ./build/notarize.js
win:
executableName: chrolog
icon: ./build/icon256.ico
Expand Down
18 changes: 14 additions & 4 deletions electron.vite.config.js → electron.vite.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,17 @@ import { resolve } from 'path'
import { defineConfig, externalizeDepsPlugin } from 'electron-vite'
import react from '@vitejs/plugin-react'
import svgr from '@svgr/rollup'
import { URL, pathToFileURL } from 'url'

export default defineConfig({
main: {
plugins: [externalizeDepsPlugin()],
build: {
rollupOptions: {
external: ['sqlite3']
external: ['sqlite3'],
output: {
format: 'es'
}
},
asar: false
}
Expand All @@ -17,20 +21,26 @@ export default defineConfig({
plugins: [externalizeDepsPlugin()],
build: {
rollupOptions: {
external: ['sqlite3']
external: ['sqlite3'],
output: {
format: 'es'
}
},
asar: false
}
},
renderer: {
resolve: {
alias: {
'@renderer': resolve('src/renderer/src')
'@renderer': new URL('./src/renderer/src', import.meta.url)
}
},
build: {
rollupOptions: {
external: ['sqlite3']
external: ['sqlite3'],
output: {
format: 'es'
}
}
},
plugins: [react(), svgr()],
Expand Down
46 changes: 23 additions & 23 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
{
"name": "chrolog",
"version": "1.7.2",
"version": "1.8.0",
"description": "A automated time tracking tool",
"main": "./out/main/index.js",
"main": "./out/main/index.mjs",
"author": "lukylix",
"homepage": "https://github.com/Lukylix/Chrolog",
"license": "MIT",
"scripts": {
"format": "prettier --write .",
"lint": "eslint . --ext .js,.jsx,.cjs,.mjs,.ts,.tsx,.cts,.mts --fix",
"start": "electron-vite preview",
"dev": "cross-env NODE_ENV=development electron-vite dev",
"dev": "cross-env NODE_ENV=development electron-vite dev -- --trace-warnings",
"build": "electron-vite build",
"m-postinstall": "electron-builder install-app-deps",
"build:win": " npm run build && electron-builder --win --config",
"build:mac": " npm run build && electron-builder --mac --config",
"build:win": "npm run build && electron-builder --win --config",
"build:mac": "npm run build && electron-builder --mac --config",
"build:linux": " npm run build && electron-builder --linux --config",
"react-devtools": "react-devtools",
"test-lib": "cross-env NODE_PATH=./node_modules node ./src/lib/test.js",
Expand All @@ -24,39 +25,38 @@
"mainConfig": "./vite.config.js"
},
"dependencies": {
"@electron-toolkit/preload": "^2.0.0",
"@electron-toolkit/utils": "^2.0.1",
"@electron/notarize": "^2.1.0",
"@electron/remote": "^2.1.0",
"@preact/signals-react": "^1.3.6",
"core-js": "^3.33.2",
"@electron-toolkit/preload": "^3.0.0",
"@electron-toolkit/utils": "^3.0.0",
"@electron/notarize": "^2.2.1",
"@electron/remote": "^2.1.2",
"@preact/signals-react": "^1.3.8",
"core-js": "^3.35.1",
"cross-env": "^7.0.3",
"electron-store": "^8.1.0",
"events": "^3.3.0",
"ffi-rs": "^1.0.21",
"ffi-rs": "^1.0.48",
"os": "^0.1.2",
"path": "^0.12.7",
"react-router-dom": "^6.18.0",
"react-router-dom": "^6.21.3",
"react-select": "^5.8.0",
"recharts": "^2.9.3",
"socket.io": "^4.7.2",
"sqlite3": "^5.1.6",
"recharts": "^2.11.0",
"socket.io": "^4.7.4",
"sqlite3": "^5.1.7",
"url": "^0.11.3",
"util": "^0.12.5"
},
"devDependencies": {
"@electron/rebuild": "^3.3.0",
"@svgr/rollup": "^8.1.0",
"@vitejs/plugin-react": "^4.1.1",
"electron": "27.0.4",
"electron-builder": "24.6.4",
"electron-vite": "^1.0.28",
"@vitejs/plugin-react": "^4.2.1",
"electron": "28.2.0",
"electron-builder": "24.12.0",
"electron-vite": "^2.0.0",
"eslint-plugin-react": "^7.33.2",
"prettier": "^2.8.8",
"prettier": "^3.2.4",
"prop-types": "^15.8.1",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"vite": "^4.5.0"
"vite": "^5.0.12"
},
"packageManager": "yarn@4.0.1"
}
15 changes: 0 additions & 15 deletions resources/package.json

This file was deleted.

2 changes: 1 addition & 1 deletion src/lib/chrolog-server/test-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const { open, load, close, DataType } = require('ffi-rs')

open({
library: 'chrolog',
path: `${__dirname}/../../../resources/chrolog.so`
path: `${import.meta.url}/../../../resources/chrolog.so`
})

function getActiveApp() {
Expand Down
45 changes: 42 additions & 3 deletions src/lib/chrolog/chrolog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#include <unistd.h>
#include <fcntl.h>
#include <linux/input.h>
#include <mutex>

#include <dlfcn.h>
#include <filesystem>
#include <sys/wait.h>
Expand All @@ -24,6 +24,7 @@
#include <set>
#include <chrono>
#include <thread>
#include <mutex>

#ifdef _WIN32
const char *GetActiveApp()
Expand Down Expand Up @@ -124,14 +125,18 @@ int GetNextProcessId()
return processId ? processId : 0;
}

std::mutex lastInputTimeMutex;
static double lastInputTime = 0;

double GetLastInputTime()
{
return lastInputTime;
lastInputTimeMutex.lock();
double lastInputTimeCopy = lastInputTime;
lastInputTimeMutex.unlock();
return lastInputTimeCopy;
}

HHOOK eHook = NULL;
HHOOK kHook = NULL;
HHOOK mHook = NULL;
std::thread thread = std::thread();

Expand All @@ -143,10 +148,41 @@ LRESULT CALLBACK MouseHookProc(int nCode, WPARAM wparam, LPARAM lparam)
auto now = std::chrono::system_clock::now();
auto duration = now.time_since_epoch();
auto milliseconds = std::chrono::duration_cast<std::chrono::milliseconds>(duration).count();
lastInputTimeMutex.lock();
lastInputTime = static_cast<double>(milliseconds);
lastInputTimeMutex.unlock();
return result;
}

LRESULT CALLBACK KeyboardHookProc(int nCode, WPARAM wparam, LPARAM lparam)
{
LRESULT result = CallNextHookEx(NULL, nCode, wparam, lparam);
if (nCode < 0)
return result;
auto now = std::chrono::system_clock::now();
auto duration = now.time_since_epoch();
auto milliseconds = std::chrono::duration_cast<std::chrono::milliseconds>(duration).count();
lastInputTimeMutex.lock();
lastInputTime = static_cast<double>(milliseconds);
lastInputTimeMutex.unlock();
return result;
}

void SetKeyboardHook()
{
if (kHook != NULL)
return;
kHook = SetWindowsHookEx(WH_KEYBOARD_LL, KeyboardHookProc, GetModuleHandle(NULL), 0);
}

void UnsetKeyboardHook()
{
if (kHook == NULL)
return;
UnhookWindowsHookEx(kHook);
kHook = NULL;
}

void SetMouseHook()
{
if (mHook != NULL)
Expand All @@ -165,13 +201,15 @@ void UnsetMouseHook()
void HookThread()
{
SetMouseHook();
SetKeyboardHook();
MSG Msg;
while (GetMessage(&Msg, NULL, 0, 0))
{
TranslateMessage(&Msg);
DispatchMessage(&Msg);
}
UnsetMouseHook();
UnsetKeyboardHook();
}

void CreateHookThreads()
Expand Down Expand Up @@ -200,6 +238,7 @@ BOOL APIENTRY DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserv
break;
case DLL_PROCESS_DETACH:
UnsetMouseHook();
UnsetKeyboardHook();
KillThread();
break;
}
Expand Down
7 changes: 4 additions & 3 deletions src/lib/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,14 @@ const getProcessInfos = async (processId) => {
}

if (process.platform === 'win32') {
const chrologPath = new URL('../../resources/chrolog.dll', import.meta.url)
open({
library: 'chrolog',
path: `${__dirname}/../../resources/chrolog.dll`
path: chrologPath
})
} else if (process.platform === 'linux') {
const chrologPath = `${__dirname}/../../resources/chrolog.so`
console.log('chrologPath', chrologPath)
const chrologPath = new URL('../../resources/chrolog.so', import.meta.url)
console.log('chrologPath', chrologPath.href)
open({
library: 'chrolog',
path: chrologPath
Expand Down
18 changes: 10 additions & 8 deletions src/main/index.js → src/main/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import Store from 'electron-store'
import os from 'os'
import { existsSync } from 'fs'
import { createServer as createHttpServer } from 'http'
import { URL } from 'url'

let startMinimized = (process.argv || []).indexOf('--hidden') !== -1

Expand All @@ -31,18 +32,19 @@ let tray = null

function createWindow() {
let icon
if (os.platform() === 'win32') icon = join(__dirname, '../../build/icon256.ico')
else if (os.platform() === 'linux') icon = join(__dirname, '../../build/icon512.png')
if (os.platform() === 'win32') icon = new URL('../../build/icon256.ico', import.meta.url)
else if (os.platform() === 'linux') icon = new URL('../../build/icon512.png', import.meta.url)
console.log('icon', icon.href)
const mainWindow = new BrowserWindow({
width: 900,
height: 670,
show: false,
autoHideMenuBar: true,
frame: false,
titleBarStyle: 'hidden',
icon,
icon: icon.href,
webPreferences: {
preload: join(__dirname, '../preload/index.js'),
preload: new URL('../preload/index.mjs', import.meta.url),
sandbox: false,
nodeIntegration: true,
contextIsolation: false,
Expand All @@ -68,10 +70,9 @@ function createWindow() {
for (const path of paths) {
try {
if (existsSync(join(app.getAppPath(), path))) {
console.log(join(__dirname, path), ' icon found')
console.log(new URL(path, import.meta.url).href, ' icon found.')
const nativeImageIcon = nativeImage.createFromPath(join(app.getAppPath(), path))
let appIcon = new Tray(nativeImageIcon)

const contextMenu = Menu.buildFromTemplate([
{
label: 'Show',
Expand Down Expand Up @@ -119,8 +120,9 @@ function createWindow() {
if (is.dev && process.env['ELECTRON_RENDERER_URL']) {
mainWindow.loadURL(process.env['ELECTRON_RENDERER_URL'])
} else {
if (process.env.NODE_ENV === 'development') join(__dirname, '../rendered/dev.html')
else mainWindow.loadFile(join(__dirname, '../renderer/index.html'))
const fileToLoad = process.env.NODE_ENV != 'development' ? 'index.html' : 'dev.html'
const realtivePathToload = `out/renderer/${fileToLoad}`
mainWindow.loadFile(realtivePathToload)
}

ipcMain.on('save-data', saveDataListener)
Expand Down
3 changes: 2 additions & 1 deletion src/main/utilis/database.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { Database } from 'sqlite3'
import sqlite3 from 'sqlite3'
import { app } from 'electron'
import { join } from 'path'
import fs from 'fs'

const { Database } = sqlite3
const appDataPath = app.getPath('appData')
const dirPath = join(appDataPath, 'Chrolog/storage')

Expand Down
2 changes: 1 addition & 1 deletion src/main/utilis/system.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ if (process.platform === 'win32') {
let processPath = app
.getPath('exe')
.replace(/(?!\\).[^\\]+\.exe$/gm, '')
.replace(/\/$/, '')
.replace(/\/+$/, '')
if (processPath.includes('node_modules'))
processPath = processPath.replace(/node_modules.*/gm, '').replace(/\/$/, '')
const chrologPaths = [
Expand Down
File renamed without changes.
4 changes: 1 addition & 3 deletions src/renderer/src/components/Header/header.css
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@
.dragable {
-webkit-app-region: drag;
-webkit-user-select: none;
user-select: none;

height: 30px;
}
.main > .container {
margin-top: 30px;
}
Loading

0 comments on commit 10f5031

Please sign in to comment.