-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathServer.js
65 lines (55 loc) · 1.91 KB
/
Server.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
const express = require('express');
const { exec } = require('child_process');
const { Notion } = require('@neurosity/notion');
const app = express();
const PORT = 3001;
const FOCUS_THRESHOLD = 0.3;
const notion = new Notion();
let currentFocusScore = 0;
async function loginToNeurosity() {
try {
await notion.login({
email: "EMAIL",
password: "PASSWORD"
});
console.log("Logged in to Neurosity");
} catch (error) {
console.error("Error logging in:", error);
}
}
loginToNeurosity();
notion.focus().subscribe(focusData => {
console.log("Received focus data:", focusData);
if (focusData && focusData.probability) {
currentFocusScore = focusData.probability;
console.log("Updated Focus score:", currentFocusScore);
if (currentFocusScore > FOCUS_THRESHOLD) {
console.log("Focus threshold crossed. Executing Flipper command.");
const flipperCommands = [
'input send ok press',
'input send ok short',
'input send ok release'
];
flipperCommands.forEach(command => {
exec(`osascript -e 'tell application "Terminal" to do script "${command}" in front window'`, (error, stdout, stderr) => {
if (error) {
console.error(`Error executing Flipper command: ${error}`);
return;
}
console.log(`Flipper command output for ${command}: ${stdout}`);
});
});
}
} else {
console.log("Focus score data not received or undefined.");
}
});
app.get('/', (req, res) => {
res.send('Neurosity Middleware Running');
});
app.get('/focus', (req, res) => {
res.json({ focusScore: currentFocusScore });
});
app.listen(PORT, () => {
console.log(`Middleware listening at http://localhost:${PORT}`);
});