diff options
author | RaindropsSys <contact@minteck.org> | 2023-04-10 13:18:12 +0200 |
---|---|---|
committer | RaindropsSys <contact@minteck.org> | 2023-04-10 13:18:12 +0200 |
commit | b923af24291bac3c6fb41cf1f0b057b691c653bb (patch) | |
tree | a67b32c23a2ad06b8abca1d880d2836e0a418503 /luna | |
parent | d1fae42963bc184d5ff12a9b1771a68ac9699c55 (diff) | |
download | cold-haze-desktop-b923af24291bac3c6fb41cf1f0b057b691c653bb.tar.gz cold-haze-desktop-b923af24291bac3c6fb41cf1f0b057b691c653bb.tar.bz2 cold-haze-desktop-b923af24291bac3c6fb41cf1f0b057b691c653bb.zip |
Diffstat (limited to 'luna')
-rw-r--r-- | luna/icons/logo-macos.icns | bin | 0 -> 575974 bytes | |||
-rw-r--r-- | luna/icons/logo-macos.png | bin | 0 -> 173240 bytes | |||
-rw-r--r-- | luna/icons/logo.png | bin | 0 -> 92283 bytes | |||
-rw-r--r-- | luna/icons/menu-coldhaze/16x16@2x.png | bin | 0 -> 3680 bytes | |||
-rw-r--r-- | luna/icons/menu/16x16@2x.png | bin | 0 -> 4686 bytes | |||
-rw-r--r-- | luna/icons/tray-full.png | bin | 0 -> 86112 bytes | |||
-rw-r--r-- | luna/icons/tray/16x16Template@2x.png | bin | 0 -> 1896 bytes | |||
-rw-r--r-- | luna/index.js | 230 |
8 files changed, 230 insertions, 0 deletions
diff --git a/luna/icons/logo-macos.icns b/luna/icons/logo-macos.icns Binary files differnew file mode 100644 index 0000000..7beb7d9 --- /dev/null +++ b/luna/icons/logo-macos.icns diff --git a/luna/icons/logo-macos.png b/luna/icons/logo-macos.png Binary files differnew file mode 100644 index 0000000..09227ce --- /dev/null +++ b/luna/icons/logo-macos.png diff --git a/luna/icons/logo.png b/luna/icons/logo.png Binary files differnew file mode 100644 index 0000000..69a67ac --- /dev/null +++ b/luna/icons/logo.png diff --git a/luna/icons/menu-coldhaze/16x16@2x.png b/luna/icons/menu-coldhaze/16x16@2x.png Binary files differnew file mode 100644 index 0000000..b38d6b2 --- /dev/null +++ b/luna/icons/menu-coldhaze/16x16@2x.png diff --git a/luna/icons/menu/16x16@2x.png b/luna/icons/menu/16x16@2x.png Binary files differnew file mode 100644 index 0000000..07fba85 --- /dev/null +++ b/luna/icons/menu/16x16@2x.png diff --git a/luna/icons/tray-full.png b/luna/icons/tray-full.png Binary files differnew file mode 100644 index 0000000..7e2ee53 --- /dev/null +++ b/luna/icons/tray-full.png diff --git a/luna/icons/tray/16x16Template@2x.png b/luna/icons/tray/16x16Template@2x.png Binary files differnew file mode 100644 index 0000000..9ac8eec --- /dev/null +++ b/luna/icons/tray/16x16Template@2x.png diff --git a/luna/index.js b/luna/index.js new file mode 100644 index 0000000..b13082e --- /dev/null +++ b/luna/index.js @@ -0,0 +1,230 @@ +const { app, desktopCapturer, dialog, Tray, Menu, shell, session } = require('electron'); +const { platform, hostname } = require('node:os'); +const { writeFileSync, existsSync, readFileSync } = require('node:fs'); +const axios = require('axios'); +const si = require('systeminformation'); + +global.luna_version = "1.3.0"; +global.lastSentData = {}; +global.clientsList = {}; +global.lastDataUpdate = 0; +global.proxyStatus = 0; +global.computerId = ""; + +function timeAgo(time) { + if (!isNaN(parseInt(time))) { + time = new Date(time).getTime(); + } + + if (time === 0) return "never"; + + let periods = ["sec", "min", "hr", "d", "wk", "mo", "y", "ages"]; + + let lengths = ["60", "60", "24", "7", "4.35", "12", "100"]; + + let now = new Date().getTime(); + + let difference = Math.round((now - time) / 1000); + let tense; + let period; + + if (difference <= 10 && difference >= 0) { + return "now"; + } else if (difference > 0) { + tense = "ago"; + } else { + tense = "later"; + } + + let j; + + for (j = 0; difference >= lengths[j] && j < lengths.length - 1; j++) { + difference /= lengths[j]; + } + + difference = Math.round(difference); + + period = periods[j]; + + return `${difference} ${period} ${tense}`; +} + +function updateTray() { + let template = [ + { label: 'Cold Haze Desktop ', type: 'normal', enabled: false, icon: __dirname + "/icons/menu-coldhaze/16x16@2x.png" }, + { type: 'separator' }, + { label: 'Luna ' + luna_version, type: 'normal', enabled: false, icon: __dirname + "/icons/menu/16x16@2x.png" }, + { label: 'Last updated ' + timeAgo(global.lastDataUpdate), type: 'normal', enabled: false }, + ]; + + template.push(...[ + { type: 'separator' }, + { label: global['hasWindow'] ? "Hide application" : "Show application", accelerator: "CmdOrCtrl+N", click: () => { + if (global['hasWindow']) { + hideWindow() + } else { + showWindow() + } + } }, + { label: "View on Cold Haze", accelerator: "CmdOrCtrl+O", click: () => { + showWindow() + navigateTo("coldhaze://-/computers/" + global.computerId); + } }, + { label: 'Quit', type: 'normal', role: 'quit', accelerator: "CmdOrCtrl+Q" } + ]); + + const contextMenu = Menu.buildFromTemplate(template); + + tray.setToolTip('Cold Haze Desktop'); + tray.setContextMenu(contextMenu); +} + +global.token = ""; + +async function systemProfile() { + let osInfo = await si.osInfo(); + let baseboard = await si.baseboard(); + let processes = (await si.processes()).list; + + let data = { + luna_version, + dsb: { + platform: "desktop", + version: 4 + }, + top_sites: null, + remote_control: false, + host: hostname(), + os: osInfo.distro + " " + osInfo.release, + kernel: osInfo.platform.substring(0, 1).toUpperCase() + osInfo.platform.substring(1) + " " + osInfo.kernel + " (" + osInfo.arch + ")", + serial: baseboard.serial ?? osInfo.serial, + serial_source: baseboard.serial ? "hardware" : "software", + date: new Date().toISOString(), + screens: [], + windows: [], + cpu: (await si.cpu()), + temperature: (await si.cpuTemperature()), + ram: (await si.mem()), + ram_chips: (await si.memLayout()), + battery: (await si.battery()), + os_info: (await si.osInfo()), + gpu: (await si.graphics()), + uuid: (await si.uuid()), + versions: (await si.versions()), + users: (await si.users()), + filesystems: (await si.fsSize()), + fs_stats: (await si.fsStats()), + usb: (await si.usb()), + audio: (await si.audio()), + network: (await si.networkInterfaces()), + connections: (await si.networkConnections()), + processes: processes.map((i) => { + return { + pid: i.pid, + name: i.name, + cpu: i.cpu, + ram: i.mem, + date: new Date(i.started).toISOString(), + user: i.user, + path: i.path + } + }).sort((a, b) => { + return b.cpu - a.cpu; + }) + } + + global.lastSentData = data; + + let sources = await desktopCapturer.getSources({ types: ['screen'], thumbnailSize: { width: 445, height: 256 } }); + + for (let source of sources) { + console.log(`Screen ${source.id} (${source.name})`); + + data.screens.push({ + id: source.display_id, + gid: source.id, + name: source.name, + }); + } + + try { + global.computerId = (await axios("https://ponies.equestria.horse/api/computer?type=data", { + method: "post", + data, + headers: {'Cookie': 'PEH2_SESSION_TOKEN=' + token} + })).data; + + global.lastDataUpdate = new Date().getTime(); + } catch (e) { + console.error(e); + } + + writeFileSync("./data.json", JSON.stringify(data)); +} + +async function refresh() { + let sources = await desktopCapturer.getSources({ types: ['screen'], thumbnailSize: { width: 445, height: 256 } }); + + for (let source of sources) { + console.log(`Screen ${source.id} (${source.name})`); + + try { + console.log((await axios("https://ponies.equestria.horse/api/computer?type=screenshot", { + method: "post", + data: { + host: hostname(), + id: source.display_id, + data: source.thumbnail.toJPEG(80).toString("base64") + }, + headers: {'Cookie': 'PEH2_SESSION_TOKEN=' + token} + })).data); + } catch (e) { + console.error(e); + } + } +} + +let lunaStartUp = setInterval(() => { + session.fromPartition("persist:default").cookies.get({url: 'https://ponies.equestria.horse'}).then((cookies) => { + let cookie = cookies.filter(i => i.name === "PEH2_SESSION_TOKEN")[0]; + + if (cookie && cookie.value && cookie.value.trim() !== "") { + global['token'] = cookie.value; + } + }) + + if (global['token'].trim() === "") return; + + global.tray = new Tray(__dirname + '/icons/tray/16x16Template@2x.png'); + updateTray(); + + clearInterval(lunaStartUp); + refresh(); + systemProfile(); + + setInterval(() => { + updateTray(); + }, 1000); + + setInterval(async () => { + try { + await axios("https://ponies.equestria.horse/api/computer?type=heartbeat", { + method: "POST", + data: { + host: hostname() + }, + headers: {'Cookie': 'PEH2_SESSION_TOKEN=' + token} + }); + } catch (e) { + console.error(e); + } + }, 5000); + + setInterval(() => { + refresh(); + }, 60000); + + setInterval(() => { + systemProfile(); + }, 600000); +}, 1000);
\ No newline at end of file |