Skip to content

Commit

Permalink
New: Sleep after pressing the Fade button
Browse files Browse the repository at this point in the history
  • Loading branch information
Adam777Z committed Nov 14, 2021
1 parent 74cff2c commit c4d41ea
Show file tree
Hide file tree
Showing 10 changed files with 57 additions and 10 deletions.
12 changes: 8 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ The stored token and all settings can be deleted in the app Settings.
- Select light(s) to control: All, Location, Group, Light
- Turn on/off
- Fade on/off (can set the duration)
- Only available in the desktop app: Quit and Lock (Windows only) after pressing the Fade button
- Only available in the desktop app: Quit, Lock (Windows only), Sleep (Windows only) after pressing the Fade button
- Set brightness

## Progressive Web App (PWA)
Expand Down Expand Up @@ -44,8 +44,11 @@ To enable, create the `data` folder where the executable file is located.\
The `data` folder already exists in the Portable version ZIP file.

### How to build
1. npm install
2. npm run dist
1. Have [NirCmd](https://www.nirsoft.net/utils/nircmd.html) in the resources folder:\
resources\nircmdc.exe\
(Windows only)
2. npm install
3. npm run dist

## Support and Feedback
Available under [Discussions](https://github.com/Adam777Z/lifx/discussions).
Expand All @@ -54,4 +57,5 @@ Available under [Discussions](https://github.com/Adam777Z/lifx/discussions).
- Thanks to [LIFX](https://www.lifx.com/) for the lights and the [LIFX HTTP API](https://api.developer.lifx.com/)
- [Electron](https://www.electronjs.org/) (desktop app)
- [Bootstrap](https://getbootstrap.com/)
- [Bootstrap Icons](https://icons.getbootstrap.com/)
- [Bootstrap Icons](https://icons.getbootstrap.com/)
- [NirCmd](https://www.nirsoft.net/utils/nircmd.html) (used for Sleep, Windows only)
23 changes: 23 additions & 0 deletions assets/js/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ document.addEventListener('DOMContentLoaded', (event) => {
! localStorage.getItem('lifx_app_quit')
&&
! localStorage.getItem('lifx_app_lock')
&&
! localStorage.getItem('lifx_app_sleep')
) {
delete_all_settings_btn.style.display = 'none';
}
Expand Down Expand Up @@ -83,6 +85,10 @@ document.addEventListener('DOMContentLoaded', (event) => {
document.querySelector('#lock').checked = localStorage.getItem('lifx_app_lock') == 'true';
}

if (localStorage.getItem('lifx_app_sleep')) {
document.querySelector('#sleep').checked = localStorage.getItem('lifx_app_sleep') == 'true';
}

if (window.electron) {
document.querySelectorAll('.electron-only').forEach(e => e.style.display = null);

Expand Down Expand Up @@ -139,6 +145,8 @@ document.addEventListener('DOMContentLoaded', (event) => {
localStorage.getItem('lifx_app_quit')
||
localStorage.getItem('lifx_app_lock')
||
localStorage.getItem('lifx_app_sleep')
) {
delete_all_settings_btn.style.display = 'block';
}
Expand Down Expand Up @@ -193,6 +201,9 @@ document.addEventListener('DOMContentLoaded', (event) => {
localStorage.removeItem('lifx_app_lock');
document.querySelector('#lock').checked = false;

localStorage.removeItem('lifx_app_sleep');
document.querySelector('#sleep').checked = false;

delete_all_settings_btn.style.display = 'none';
});

Expand Down Expand Up @@ -283,6 +294,10 @@ document.addEventListener('DOMContentLoaded', (event) => {
window.electron.lock();
}

if (window.electron && document.querySelector('#sleep').checked) {
window.electron.sleep();
}

if (window.electron && document.querySelector('#quit').checked) {
window.electron.quitApp();
} else {
Expand Down Expand Up @@ -330,6 +345,14 @@ document.addEventListener('DOMContentLoaded', (event) => {
}
});

document.querySelector('#sleep').addEventListener('change', (event) => {
if (event.target.checked) {
localStorage.setItem('lifx_app_sleep', event.target.checked);
} else {
localStorage.removeItem('lifx_app_sleep');
}
});

function update_state() {
document.querySelector('#power-switch').checked = state == 'on';
document.querySelector('#fade-btn').textContent = 'Fade ' + ( state == 'off' ? 'on' : 'off' );
Expand Down
2 changes: 1 addition & 1 deletion assets/js/script.min.js

Large diffs are not rendered by default.

6 changes: 5 additions & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ <h1>LIFX</h1>
<div id="top-container" class="col" style="display: none;">
<div class="d-flex justify-content-end align-items-center">
<div id="settings-only" style="display: none;">
<span id="app-version" class="me-3 align-middle">v1.0.1</span>
<span id="app-version" class="me-3 align-middle">v1.1.0</span>
<a class="me-3" href="https://github.com/Adam777Z/lifx" target="_blank" rel="noopener noreferrer" title="View on GitHub"><i class="bi bi-github fs-2"></i></a>
</div>

Expand Down Expand Up @@ -130,6 +130,10 @@ <h1>LIFX</h1>
<input class="form-check-input" type="checkbox" id="lock">
<label class="form-check-label" for="lock">Lock</label>
</div>
<div class="form-check form-check-inline ms-2 me-0 electron-windows-only" style="display: none;">
<input class="form-check-input" type="checkbox" id="sleep">
<label class="form-check-label" for="sleep">Sleep</label>
</div>
</div>
</div>
</div>
Expand Down
6 changes: 6 additions & 0 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,4 +95,10 @@ ipcMain.on('lock', () => {
if (process.platform === 'win32') {
require('child_process').exec('rundll32.exe user32.dll, LockWorkStation');
}
});

ipcMain.on('sleep', () => {
if (process.platform === 'win32') {
require('child_process').execFile('resources/nircmdc.exe', ['standby']);
}
});
13 changes: 11 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "lifx",
"productName": "LIFX",
"version": "1.0.1",
"version": "1.1.0",
"description": "LIFX App (unofficial)",
"author": "Adam777",
"homepage": "https://github.com/Adam777Z/lifx#readme",
Expand All @@ -21,7 +21,7 @@
"license": "MIT-0",
"main": "main.js",
"devDependencies": {
"electron": "^15.1.2",
"electron": "^15.3.1",
"electron-builder": "^22.13.1"
},
"scripts": {
Expand All @@ -35,12 +35,21 @@
"buildResources": "assets/images"
},
"artifactName": "${productName}-${version}-${arch}-${os}.${ext}",
"win": {
"extraFiles": {
"from": "resources/nircmdc.exe",
"to": "resources/nircmdc.exe"
}
},
"nsis": {
"oneClick": false,
"perMachine": false,
"allowElevation": true,
"allowToChangeInstallationDirectory": true,
"artifactName": "${productName} Setup ${version} ${arch}.${ext}"
},
"linux": {
"category": "Utility"
}
},
"postinstall": "electron-builder install-app-deps"
Expand Down
3 changes: 2 additions & 1 deletion preload.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ contextBridge.exposeInMainWorld(
{
'platform': process.platform,
'quitApp': () => ipcRenderer.send('quitApp'),
'lock': () => ipcRenderer.send('lock')
'lock': () => ipcRenderer.send('lock'),
'sleep': () => ipcRenderer.send('sleep')
}
);
Binary file modified screenshots/desktop-app-main-windows-10.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 modified screenshots/desktop-app-settings-windows-10.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion sw.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const cacheName = 'lifx-cache';
const cacheVersion = '1.0.1'; // Needed for service worker auto update
const cacheVersion = '1.1.0'; // Needed for service worker auto update

self.addEventListener('install', (event) => {
event.waitUntil(
Expand Down

0 comments on commit c4d41ea

Please sign in to comment.