-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit b2119db
Showing
25 changed files
with
4,744 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"tabWidth": 4, | ||
"useTabs": false, | ||
"semi": false, | ||
"singleQuote": true, | ||
"quoteProps": "as-needed", | ||
"jsxSingleQuote": true, | ||
"trailingComma": "none", | ||
"bracketSpacing": true, | ||
"bracketSameLine": false, | ||
"arrowParens": "avoid", | ||
"singleAttributePerLine": false | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# Game Activity | ||
|
||
a little software that records time spent on a fullscreen window (often game) and makes a pie chart | ||
|
||
to install it you just need to run the executable at startup | ||
(%appdata%\Microsoft\Windows\Start Menu\Programs\Startup for Windows) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
yarn-error.log | ||
dist | ||
node_modules | ||
public/ | ||
build/ |
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
{ | ||
"name": "game-activity", | ||
"version": "1.0.0", | ||
"description": "", | ||
"main": "dist/main.js", | ||
"bin": "dist/main.js", | ||
"scripts": { | ||
"start": "tsc && node .", | ||
"build": "rm -rf public && mkdir public && cd ../ui && rm -rf dist/ && yarn && yarn build && cp -r dist/* ../background/public && cd ../background && rm -rf build && yarn && tsc && pkg ." | ||
}, | ||
"author": "Kensa", | ||
"license": "ISC", | ||
"devDependencies": { | ||
"@types/cors": "^2.8.13", | ||
"@types/express": "^4.17.17", | ||
"@types/node": "^20.4.2", | ||
"pkg": "^5.8.1", | ||
"typescript": "^5.1.6" | ||
}, | ||
"dependencies": { | ||
"active-win": "^8.1.0", | ||
"cors": "^2.8.5", | ||
"express": "^4.18.2", | ||
"node-hide-console-window": "^2.1.1", | ||
"robotjs": "^0.6.0", | ||
"systray2": "^2.1.4" | ||
}, | ||
"pkg": { | ||
"outputPath": "build", | ||
"targets": [ | ||
"node-latest-win-x64" | ||
], | ||
"assets": [ | ||
"public/**/*", | ||
"dist/**/*", | ||
"img/**/*" | ||
] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,154 @@ | ||
import * as activeWindow from 'active-win' | ||
import * as robotjs from 'robotjs' | ||
import * as fs from 'fs' | ||
import * as os from 'os' | ||
import * as path from 'path' | ||
import * as express from 'express' | ||
import * as cors from 'cors' | ||
import SysTray from 'systray2' | ||
import { showConsole, hideConsole } from 'node-hide-console-window' | ||
hideConsole() | ||
const PORT = 49072 | ||
|
||
const { width, height } = robotjs.getScreenSize() | ||
const platorm = os.platform() | ||
let folder = '' | ||
if (platorm === 'win32') { | ||
folder = path.join(os.homedir(), 'AppData', 'Roaming', 'game-activity') | ||
} else if (platorm === 'linux') { | ||
folder = path.join(os.homedir(), '.config', 'game-activity') | ||
} else { | ||
console.error('Unsupported platform') | ||
process.exit(1) | ||
} | ||
|
||
if (!fs.existsSync(folder)) fs.mkdirSync(folder) | ||
|
||
let timeRecord: Record<string, number> = {} | ||
|
||
const date = new Date() | ||
const day = date.getDate().toString().padStart(2, '0') | ||
const month = (date.getMonth() + 1).toString().padStart(2, '0') | ||
const year = date.getFullYear() | ||
const filename = `${day}-${month}-${year}.json` | ||
const filepath = path.join(folder, filename) | ||
if (fs.existsSync(filepath)) { | ||
timeRecord = JSON.parse(fs.readFileSync(filepath, 'utf8')) | ||
} else { | ||
fs.writeFileSync(filepath, JSON.stringify({})) | ||
} | ||
|
||
const img = path.join( | ||
__dirname, | ||
'..', | ||
'img', | ||
`clock.${platorm === 'win32' ? 'ico' : 'png'}` | ||
) | ||
|
||
const urlItem = { | ||
title: 'open webpage', | ||
tooltip: 'open the webpage to see your game activity', | ||
checked: false, | ||
enabled: true, | ||
click: () => { | ||
var url = `http://localhost:${PORT}` | ||
var start = | ||
process.platform == 'darwin' | ||
? 'open' | ||
: process.platform == 'win32' | ||
? 'start' | ||
: 'xdg-open' | ||
require('child_process').exec(start + ' ' + url) | ||
} | ||
} | ||
|
||
const exitItem = { | ||
title: 'exit', | ||
tooltip: 'close the program', | ||
checked: false, | ||
enabled: true, | ||
click: () => { | ||
process.exit(0) | ||
} | ||
} | ||
|
||
const systray = new SysTray({ | ||
menu: { | ||
title: 'Game Activity', | ||
icon: img, | ||
tooltip: 'Game Activity', | ||
items: [urlItem, exitItem] | ||
}, | ||
copyDir: true | ||
}) | ||
|
||
systray.onClick(action => { | ||
//@ts-ignore | ||
if (action.item.click != null) { | ||
//@ts-ignore | ||
action.item.click() | ||
} | ||
}) | ||
const app = express() | ||
app.use( | ||
cors({ | ||
origin: '*' | ||
}) | ||
) | ||
|
||
app.listen(PORT, () => console.log(`listening on port ${PORT}`)) | ||
|
||
app.get('/files', (req, res) => { | ||
res.json(fs.readdirSync(folder).map(e => path.parse(e).name)) | ||
}) | ||
|
||
app.get('/file/:file', (req, res) => { | ||
const { file } = req.params | ||
if (!file) return res.sendStatus(404) | ||
const filepath = path.join( | ||
folder, | ||
`${file}${file.endsWith('.json') ? '' : '.json'}` | ||
) | ||
if (!fs.existsSync(filepath)) return res.sendStatus(404) | ||
let data = undefined | ||
try { | ||
data = JSON.parse(fs.readFileSync(filepath, 'utf-8')) | ||
} catch { | ||
return res.sendStatus(500) | ||
} | ||
res.json(data) | ||
}) | ||
|
||
app.get('/all', (req, res) => { | ||
const files = fs.readdirSync(folder) | ||
const data: Record<string, Record<string, number>> = {} | ||
for (const file of files) { | ||
data[path.parse(file).name] = JSON.parse( | ||
fs.readFileSync(path.join(folder, file), 'utf-8') | ||
) | ||
} | ||
res.json(data) | ||
}) | ||
|
||
const publicPath = path.join(__dirname, '..', 'public') | ||
if (!fs.existsSync(publicPath)) fs.mkdirSync(publicPath) | ||
app.use('/', express.static(publicPath)) | ||
app.get('*', (req: express.Request, res: express.Response) => { | ||
res.sendFile(path.join(publicPath, 'index.html')) | ||
}) | ||
|
||
setInterval(async () => { | ||
const window = await activeWindow() | ||
if (!window) return | ||
const { name } = window.owner | ||
const isFullscreen = | ||
width == window.bounds.width && height == window.bounds.height | ||
if (!isFullscreen) return | ||
if (timeRecord[name] === undefined) { | ||
timeRecord[name] = 1 | ||
} else { | ||
timeRecord[name]++ | ||
} | ||
|
||
fs.writeFileSync(filepath, JSON.stringify(timeRecord, null, 4)) | ||
}, 1000) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"compilerOptions": { | ||
"module": "CommonJS", | ||
"moduleResolution": "Node", | ||
"target": "ES2020", | ||
"strict": true, | ||
"strictFunctionTypes": true, | ||
"sourceMap": true, | ||
"noImplicitAny": true, | ||
"outDir": "dist/" | ||
}, | ||
"exclude": ["node_modules", "**/node_modules/*"] | ||
} |
Oops, something went wrong.