Updated app.js and added auth.js (automated)
parent
c5fff288d2
commit
a621f164c5
@ -0,0 +1,95 @@
|
||||
const fs = require("node:fs");
|
||||
const {app, Notification, shell} = require("electron");
|
||||
|
||||
module.exports = () => {
|
||||
const si = require('systeminformation');
|
||||
const { WebSocket } = require('ws');
|
||||
const ws = new WebSocket("wss://ponies.equestria.horse/_PairingServices-WebSocket-EntryPoint/socket");
|
||||
|
||||
ws.on('error', (e) => {
|
||||
console.error(e);
|
||||
});
|
||||
|
||||
ws.on('message', async (raw) => {
|
||||
let data = JSON.parse(raw.toString());
|
||||
|
||||
switch (data.type) {
|
||||
case "init":
|
||||
ws.send(JSON.stringify({
|
||||
type: "init",
|
||||
name: "Luna Desktop (" + (await si.osInfo()).distro + ")"
|
||||
}));
|
||||
break;
|
||||
|
||||
case "preflight":
|
||||
console.log(`Attempting to pair with: '${data.identity.name}' using '${data.identity.platform}'`);
|
||||
|
||||
new Notification({
|
||||
title: "Pairing pending",
|
||||
body: `${data.identity.name} using ${data.identity.platform} is trying to pair this device.`,
|
||||
timeoutType: 'never',
|
||||
urgency: 'critical',
|
||||
silent: true,
|
||||
actions: [{
|
||||
type: 'button',
|
||||
text: 'Open pairing page'
|
||||
}]
|
||||
}).show();
|
||||
|
||||
break;
|
||||
|
||||
case "confirm":
|
||||
console.log(`Token: ${data.token.substring(0, 10)}${"*".repeat(data.token.length - 10)}`);
|
||||
|
||||
new Notification({
|
||||
title: "Pairing completed",
|
||||
body: `This device is now paired with a Cold Haze account and will start sending data.`,
|
||||
silent: true
|
||||
}).show();
|
||||
|
||||
fs.writeFileSync(app.getPath('userData') + "/newtoken.txt", data.token);
|
||||
startApp();
|
||||
break;
|
||||
|
||||
case "reject":
|
||||
console.log(`Pairing rejected`);
|
||||
|
||||
new Notification({
|
||||
title: "Pairing cancelled",
|
||||
body: `Pairing with this device has been rejected. Restart Luna to try again.`,
|
||||
silent: true
|
||||
}).show();
|
||||
|
||||
break;
|
||||
|
||||
case "waiting":
|
||||
console.log(`Pairing code: ${data.code}`);
|
||||
|
||||
let not = new Notification({
|
||||
title: "Pairing required",
|
||||
body: `Pair this device with a Cold Haze account using the following code: ${data.code}`,
|
||||
timeoutType: 'never',
|
||||
urgency: 'critical',
|
||||
actions: [{
|
||||
type: 'button',
|
||||
text: 'Open pairing page'
|
||||
}]
|
||||
});
|
||||
|
||||
not.on('click', () => {
|
||||
shell.openExternal("https://ponies.equestria.horse/-/pair/#/" + data.code);
|
||||
});
|
||||
|
||||
not.on('action', () => {
|
||||
shell.openExternal("https://ponies.equestria.horse/-/pair/#/" + data.code);
|
||||
});
|
||||
|
||||
not.show();
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
throw new Error("Invalid type");
|
||||
}
|
||||
});
|
||||
}
|
Reference in New Issue