Skip to content

Commit

Permalink
Initial Commit
Browse files Browse the repository at this point in the history
  • Loading branch information
richrace committed Jan 8, 2021
0 parents commit 2df1f10
Show file tree
Hide file tree
Showing 19 changed files with 3,925 additions and 0 deletions.
16 changes: 16 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"env": {
"browser": true,
"commonjs": true,
"es2021": true,
"node": true
},
"extends": [
"airbnb-base"
],
"parserOptions": {
"ecmaVersion": 12
},
"rules": {
}
}
71 changes: 71 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
.DS_Store
.env
.gclient_done
**/.npmrc
.tags*
.vs/
.vscode/
*.log
*.pyc
*.sln
*.swp
*.VC.db
*.VC.VC.opendb
*.vcxproj
*.vcxproj.filters
*.vcxproj.user
*.xcodeproj
/.idea/
/dist/
/external_binaries/
/out/
/vendor/.gclient
/vendor/debian_jessie_mips64-sysroot/
/vendor/debian_stretch_amd64-sysroot/
/vendor/debian_stretch_arm-sysroot/
/vendor/debian_stretch_arm64-sysroot/
/vendor/debian_stretch_i386-sysroot/
/vendor/gcc-4.8.3-d197-n64-loongson/
/vendor/readme-gcc483-loongson.txt
/vendor/download/
/vendor/llvm-build/
/vendor/llvm/
/vendor/npm/
/vendor/python_26/
/vendor/native_mksnapshot
/vendor/LICENSES.chromium.html
/vendor/pyyaml
node_modules/
SHASUMS256.txt
**/package-lock.json
compile_commands.json
.envrc

# npm package
/npm/dist
/npm/path.txt

.npmrc

# Generated API definitions
electron-api.json
electron.d.ts

# Spec hash calculation
spec/.hash

# Eslint Cache
.eslintcache*

# Generated native addon files
/spec-main/fixtures/native-addon/echo/build/

# If someone runs tsc this is where stuff will end up
ts-gen

# Used to accelerate CI builds
.depshash
.depshash-target

# Used to accelerate builds after sync
patches/mtime-cache.json
8 changes: 8 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Copyright 2020 Richard Race

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

31 changes: 31 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Arctis Monitor

This Electron application will create a Tray application to show the current battery level and some other information about the headset.

## Development

Clone the repo

Run
```
npm install
```

and then
```
npm start
```

## Build application

You can run:
```
npm run package-mac
```
to build a Mac OS application. I have not yet tried to build a Windows or Linux version.

## Credtis

* Icons made by [Freepik](https://www.flaticon.com/authors/freepik "Freepik") from [www.flaticon.com](https://www.flaticon.com/ "Flaticon")
* Most of the Electron based work has been inspired by https://github.com/kevinsawicki/tray-example
* The handling of the Arctis Headsets has been taken from https://github.com/atagulalan/arctis-battery-percentage
Binary file added assets/headphones.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/icon.icns
Binary file not shown.
46 changes: 46 additions & 0 deletions assets/index.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
:root {
--background-color: #f5f5f4;
--text-color: #333;
--window-border-radius: 6px;
--font-size: 14px;
}

/* The arrow at the top of the window */
.header-arrow {
position: absolute;
top: 2px;
left: 50%;
margin-left: -5px;
height: 10px;
width: 10px;
transform: rotate(45deg);
background-color: #e8e6e8;
}

.window {
position: absolute;
top: 5px;
}

.window-content {
background-color: var(--background-color);
flex-direction: column;
padding: 10px;
}

.device {
border-bottom: 1px solid black;
margin-bottom: 20px;
}

.device .product,
.battery .percent,
.muted .bool {
font-weight: bold;
}

.device .details {
flex-direction: row;
display: flex;
justify-content: space-evenly;
}
31 changes: 31 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<link rel="stylesheet" href="./vendor/photon/css/photon.min.css">
<link rel="stylesheet" href="./assets/index.css" media="screen" charset="utf-8">
<script charset="utf-8">require('./index')</script>
<title>Arctis Monitor</title>
</head>
<body>
<div class="header-arrow"></div>
<div class="window">
<header class="toolbar toolbar-header">
<h1 class="title">Arctis Monitor</h1>
</header>

<div class="window-content">
<div class="devices">
</div>
</div>

<footer class="toolbar toolbar-footer">
<div class="toolbar-actions">
<button id="quit" class="btn btn-default pull-right">
Quit
</button>
</div>
</footer>
</div>
</body>
</html>
118 changes: 118 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
/* eslint-disable import/no-extraneous-dependencies */
/* eslint-disable no-multi-str */
/* eslint-disable no-console */
const { ipcRenderer } = require('electron');
const { remote } = require('electron');
const { findDevices, processDevices } = require('./lib/devices');

const deviceHTMLTemplate = " \
<div id='{{ deviceID }}' class='device'> \
<div class='product'>{{ product }}</div> \
<div class='details'> \
<div class='battery'> \
Battery %: <span class='percent'>{{ batPercent }}</span> {{ chargingStatus }} \
</div> \
<div class='muted'> \
Muted? <span class='bool'>{{ isMuted }}</span> \
</div> \
</div> \
</div> \
";

const deviceTurnedOffTemplate = " \
<div id='{{ deviceID }}' class='device'> \
<div class='product'>{{ product }}</div> \
<div>This device is not connected or the headset is not turned on.</div> \
<div> \
";

function checkWindowSize() {
const win = remote.getCurrentWindow();
const width = 300;
const animate = false;
const deviceRow = 62;
const otherPadding = 70;

let height = otherPadding;

height += deviceRow * document.querySelectorAll('.device').length;

height = Math.min(400, height);

win.setSize(width, height, animate);
}

function updateStatus() {
const devices = findDevices();

if (devices.length === 0) {
document.querySelector('.devices').innerHTML = '<div>Sorry no devices found!</div>';

return;
}

processDevices(devices, (device, status) => {
let percentage = status.batteryPercent > 100 ? 100 : status.batteryPercent;
percentage = percentage < 0 ? 0 : percentage;

const muted = status.micStatus === 1 ? 'Yes' : 'No';
const charging = status.chargingInfo === 1;
const discharging = status.chargingInfo === 3;
const notConnected = status.chargingInfo === 0;

const deviceID = `device-${device.productId}`;

console.log('Rendering device: ', device);
let html;

if (notConnected) {
console.log('Not connected');
html = `${deviceTurnedOffTemplate}`
.replace('{{ deviceID }}', deviceID)
.replace('{{ product }}', device.additional.name);
} else {
console.log('Connected');
const dischargingIcon = discharging ? 'down' : false;
const icon = charging ? 'up' : dischargingIcon;
let chargingIcon = '';

if (icon) {
chargingIcon = `<span class="icon icon-${icon}"></span>`;
}

html = `${deviceHTMLTemplate}`
.replace('{{ deviceID }}', deviceID)
.replace('{{ product }}', device.additional.name)
.replace('{{ batPercent }}', percentage)
.replace('{{ isMuted }}', muted)
.replace('{{ chargingStatus }}', chargingIcon);
}

console.log('Rendering:', html);
if (document.querySelector(`#${deviceID}`)) {
document.querySelector(`#${deviceID}`).outerHTML = html;
} else {
document.querySelector('.devices').insertAdjacentHTML('beforeend', html);
}

if (status.micStatus === undefined) {
document.querySelector(`#${deviceID}`).querySelector('.muted').remove();
}

checkWindowSize();
});
}

function init() {
document.querySelector('button#quit').addEventListener('click', () => {
ipcRenderer.send('quit-from-tray');
});

updateStatus();

// Refresh 5 minutes
const time = 5 * 60 * 1000;
setInterval(updateStatus, time);
}

document.addEventListener('DOMContentLoaded', init);
Loading

0 comments on commit 2df1f10

Please sign in to comment.