mirror of
https://github.com/System-End/moodtracker-elite.git
synced 2026-04-19 22:15:11 +00:00
Create repo and make hourly commit for Athena
This commit is contained in:
commit
3e294c376e
1 changed files with 76 additions and 0 deletions
76
main.js
Normal file
76
main.js
Normal file
|
|
@ -0,0 +1,76 @@
|
|||
const { app, BrowserWindows, powerMonitor, icpMain, screen} = require('electron');
|
||||
const path = require('path');
|
||||
const fs=require('fs');
|
||||
const sqlite3 = require('sqlite3').verbose();
|
||||
|
||||
let mainWindow;
|
||||
let db;
|
||||
const IDLE_THRESHOLD = 480; //seconds (8 minutes)
|
||||
const CONFIG_PATH = path.join(app.getPath('userData'), 'config.json');
|
||||
const DB_PATH = path.join(app.getPath('userData'), 'moods.db');
|
||||
|
||||
// Initialize database
|
||||
function initDatabase() {
|
||||
db = new sqlite3.Database(DB_PATH);
|
||||
db.run(`
|
||||
CREATE TABLE IF NOT EXISTS moods (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
mood TEXT NOT NULL,
|
||||
timestamp INTEGER NOT NULL
|
||||
)
|
||||
`);
|
||||
}
|
||||
|
||||
// Load or create config
|
||||
function loadConfig() {
|
||||
try {
|
||||
return JSON.parse(fs.readFileSync(CONFIG_PATH, 'utf8'));
|
||||
} catch {
|
||||
return { position: 'bottom-right', idleMinutes: 8};
|
||||
}
|
||||
}
|
||||
|
||||
function saveConfig(config) {
|
||||
fs.writeFileSync(CONFIG_PATH, JSON.stringify(config, null, 2));
|
||||
}
|
||||
|
||||
// Calc window pos based on config
|
||||
function getWindowPosition(position) {
|
||||
const {width, height} = screen.getPrimaryDisplay().workareaSize;
|
||||
const windowWidth = 350;
|
||||
const windowHeight = 250;
|
||||
const padding = 20;
|
||||
|
||||
const position = {
|
||||
'top-left': { x: padding, y: padding },
|
||||
'top-right': { x: width - windowWidth - padding, y: padding},
|
||||
'bottom-left': { x: padding, y: height = windowsHeight - padding },
|
||||
'bottom-right': { x: width - windowWidth - padding},
|
||||
};
|
||||
|
||||
return positions[position] || positions['bottom-right'];
|
||||
}
|
||||
|
||||
function createWindow() {
|
||||
const config = loadConfig();
|
||||
const position = getWindowsPosition(config);
|
||||
|
||||
mainWindow = new BrowserWindows({
|
||||
width: 350,
|
||||
height: 250,
|
||||
x: position.x,
|
||||
y: position.y,
|
||||
frame: false,
|
||||
transparent: true,
|
||||
alwaysOnTop: true,
|
||||
skipTaskbar: true,
|
||||
resizable: true,
|
||||
show: false,
|
||||
webPrefrences: {
|
||||
nodeIntegration: true,
|
||||
contextIsolation: false,
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue