This repository has been archived by the owner on Feb 13, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add electron header app * Add automatic releases * General cleanup
- Loading branch information
Showing
12 changed files
with
4,099 additions
and
46 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,33 @@ | ||
name: Build/release | ||
|
||
on: | ||
push: | ||
workflow_dispatch: | ||
|
||
jobs: | ||
release: | ||
runs-on: ${{ matrix.os }} | ||
|
||
strategy: | ||
matrix: | ||
os: [macos-latest, ubuntu-latest, windows-latest] | ||
|
||
steps: | ||
- name: Check out Git repository | ||
uses: actions/checkout@v1 | ||
|
||
- name: Install Node.js, NPM and Yarn | ||
uses: actions/setup-node@v1 | ||
with: | ||
node-version: 10 | ||
|
||
- name: Build/release Electron app | ||
uses: samuelmeuli/action-electron-builder@v1 | ||
with: | ||
# GitHub token, automatically provided to the action | ||
# (No need to define this secret in the repo settings) | ||
github_token: ${{ secrets.github_token }} | ||
|
||
# If the commit is tagged with a version (e.g. "v1.0.0"), | ||
# release the app after building | ||
release: ${{ startsWith(github.ref, 'refs/tags/v') }} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,24 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<link rel=stylesheet href=style.css /> | ||
<title>Perseverance Rich Presence</title> | ||
</head> | ||
<body> | ||
<h2>Connection Status</h2> | ||
<img id="connectImg" src=""> | ||
<p id="connectText"></p> | ||
<br> | ||
<br> | ||
<label for="location">Location: </label> | ||
<input id="location" type="text"> | ||
<button onclick="updateLocation()" style="display: inline;">Change Location</button> | ||
<img id="success" src=""> | ||
<div id="version"> | ||
<p>Version: </p> | ||
<p id="versionId"></p> | ||
</div> | ||
<script src=renderer.js></script> | ||
</body> | ||
</html> |
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 |
---|---|---|
@@ -1,73 +1,204 @@ | ||
'use strict' | ||
|
||
// Global | ||
const { app, BrowserWindow, ipcMain, Menu, Tray } = require('electron'); | ||
const { Client } = require('discord-rpc'); | ||
const julian = require('julian'); | ||
const { autoUpdater } = require('electron-updater'); | ||
|
||
let connected = false; | ||
let minimized = false; | ||
let electronWindow; | ||
let location = 'Jezero Crater'; | ||
|
||
// App | ||
function createWindow() { | ||
electronWindow = new BrowserWindow({ | ||
backgroundColor: '#36393f', | ||
closable: false, | ||
fullscreenable: false, | ||
icon: 'percy.png', | ||
width: 340, | ||
height: 380, | ||
resizable: false, | ||
titleBarStyle: 'hidden', | ||
webPreferences: { | ||
nodeIntegration: true, | ||
contextIsolation: false, | ||
zoomFactor: 1.0, | ||
}, | ||
}); | ||
electronWindow.loadFile('index.html'); | ||
|
||
electronWindow.on('minimize', event => { | ||
event.preventDefault(); | ||
electronWindow.hide(); | ||
minimized = true; | ||
}); | ||
|
||
electronWindow.on('restore', () => { | ||
electronWindow.show(); | ||
minimized = false; | ||
if (connected) { | ||
electronWindow.webContents.executeJavaScript('setConnected();'); | ||
} else { | ||
electronWindow.webContents.executeJavaScript('setDisconnected();'); | ||
} | ||
}); | ||
|
||
electronWindow.webContents.executeJavaScript(`startup('${app.getVersion()}', '${location}');`); | ||
} | ||
|
||
function createTray() { | ||
const appIcon = new Tray('percy.png'); | ||
const contextMenu = Menu.buildFromTemplate([ | ||
{ | ||
label: 'Show', | ||
click: () => { | ||
electronWindow.show(); | ||
minimized = false; | ||
if (connected) { | ||
electronWindow.webContents.executeJavaScript('setConnected();'); | ||
} else { | ||
setDisconnected(); | ||
} | ||
} | ||
}, | ||
{ | ||
label: 'Quit', | ||
click: () => { | ||
electronWindow.destroy(); | ||
} | ||
}, | ||
]); | ||
|
||
appIcon.on('double-click', () => { | ||
electronWindow.show(); | ||
}); | ||
appIcon.setToolTip('Perseverance RPC'); | ||
appIcon.setContextMenu(contextMenu); | ||
} | ||
|
||
Menu.setApplicationMenu(Menu.buildFromTemplate([ | ||
{ | ||
label: 'Options', | ||
submenu: [ | ||
{ | ||
role: 'toggleDevTools', | ||
}, | ||
{ | ||
label: 'Quit', | ||
click: () => { | ||
electronWindow.destroy(); | ||
} | ||
}, | ||
] | ||
}, | ||
])); | ||
|
||
ipcMain.on('updateLocation', (event, arg) => { | ||
location = arg; | ||
update(); | ||
event.returnValue = true; | ||
}); | ||
|
||
app.on('ready', () => { | ||
createWindow(); | ||
createTray(); | ||
autoUpdater.checkForUpdatesAndNotify(); | ||
}); | ||
|
||
app.on('window-all-closed', () => { | ||
app.quit(); | ||
}) | ||
|
||
app.on('activate', () => { | ||
if (electronWindow === null) { | ||
createWindow(); | ||
} | ||
}); | ||
|
||
app.on('quit', () => console.log("Quitting")); | ||
|
||
// RPC | ||
const clientId = '811145575134658561'; | ||
const day = 24 * 60 * 60; | ||
let marsSol = 88775244; | ||
const landingTimestamp = 1613681692; | ||
const landingTimestamp = 1613681692000; | ||
|
||
function getMSD(earthTimestamp) { | ||
return (julian(earthTimestamp) - 2405522.0028779) / 1.0274912517; | ||
return (julian(earthTimestamp) - 2451549.5) / 1.0274912517 + 44796; | ||
} | ||
|
||
function getMission() { | ||
const date = Date.now(); | ||
let sol = Math.floor(getMSD(date) - getMSD(new Date(landingTimestamp * 1000).getTime())); | ||
let percentage = ((getMSD(date) - getMSD(new Date(landingTimestamp * 1000).getTime())) * 100 - sol * 100).toFixed(2); | ||
let _day = new Date(landingTimestamp * 1000); | ||
_day.setDate(_day.getDate() + sol); | ||
_day = new Date(_day.getTime() + new Date(day * percentage).getTime()); | ||
|
||
return { | ||
sol, | ||
percentage, | ||
offset: _day.getTime() | ||
} | ||
const date = Date.now(); | ||
const diff = getMSD(date) - getMSD(landingTimestamp); | ||
const sol = Math.floor(diff); | ||
const percentage = (diff * 100 - sol * 100).toFixed(2); | ||
let _day = landingTimestamp; | ||
_day += sol; | ||
_day += day * percentage; | ||
|
||
return { | ||
sol, | ||
percentage, | ||
offset: _day, | ||
} | ||
} | ||
|
||
const rpcClient = new Client({ transport: 'ipc' }); | ||
let updateInterval; | ||
|
||
rpcClient.on('ready', () => { | ||
update(); | ||
setInterval(update, 10 * 1000); | ||
update(); | ||
updateInterval = setInterval(update, 10 * 1000); | ||
connected = true; | ||
if (!minimized && electronWindow) { | ||
electronWindow.webContents.executeJavaScript('setConnected();'); | ||
} | ||
}); | ||
|
||
rpcClient.on('disconnected', () => { | ||
console.log('Disconnected, attempting reconnect every 10 seconds'); | ||
setTimeout(connect, 10000); | ||
connected = false; | ||
if (!minimized && electronWindow) { | ||
electronWindow.webContents.executeJavaScript('setDisconnected();'); | ||
} | ||
clearInterval(updateInterval); | ||
updateInterval = null; | ||
console.log('Disconnected, attempting reconnect every 10 seconds'); | ||
setTimeout(connect, 10000); | ||
|
||
}) | ||
|
||
function update() { | ||
const missionInfo = getMission(); | ||
const state = `Perseverance - Sol ${missionInfo.sol} (${missionInfo.percentage}%)`; | ||
const details = `Location: Jezero Crater`; | ||
const buttons = [ | ||
{ | ||
label: 'Where is Perseverance!', | ||
url: 'https://mars.nasa.gov/mars2020/mission/where-is-the-rover/', | ||
}, | ||
{ | ||
label: 'Read about Sol (Mars day)!', | ||
url: 'https://en.wikipedia.org/wiki/Sol_(day_on_Mars)', | ||
} | ||
]; | ||
|
||
rpcClient.setActivity({ | ||
state, | ||
details, | ||
startTimestamp: missionInfo.offset, | ||
largeImageKey: 'ps', | ||
largeImageText: 'Nasa is running this mission!', | ||
buttons, | ||
}).catch(console.error); | ||
const missionInfo = getMission(); | ||
const state = `Perseverance - Sol ${missionInfo.sol} (${missionInfo.percentage}%)`; | ||
const details = `Location: ${location}`; | ||
const buttons = [ | ||
{ | ||
label: 'Where is Perseverance!', | ||
url: 'https://mars.nasa.gov/mars2020/mission/where-is-the-rover/', | ||
}, | ||
{ | ||
label: 'Read about Sol (Mars day)!', | ||
url: 'https://en.wikipedia.org/wiki/Sol_(day_on_Mars)', | ||
} | ||
]; | ||
|
||
rpcClient.setActivity({ | ||
state, | ||
details, | ||
startTimestamp: missionInfo.offset, | ||
largeImageKey: 'ps', | ||
largeImageText: 'Nasa is running this mission!', | ||
buttons, | ||
}).catch(console.error); | ||
} | ||
|
||
function connect() { | ||
rpcClient._connectPromise = undefined; | ||
rpcClient.login({ clientId }) | ||
.then(() => console.log('RPC Connected.')) | ||
.catch(console.error); | ||
rpcClient._connectPromise = undefined; | ||
rpcClient.login({ clientId }) | ||
.then(() => console.log('RPC Connected.')) | ||
.catch(console.error); | ||
} | ||
|
||
connect(); |
Oops, something went wrong.