forked from UnchartedBull/OctoDash
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Reduce input during on-boarding (UnchartedBull#954)
* - Add mdns and ngx-electron plugin - Add electron-rebuild to dev depends so that electron can be rebuilt with the installed node - Fix setTimeout and setInstance to with with Node modules (required for mdns) - Reduce the version on node as electron needs to be on the same version for this to work - Change order in on boarding wizard to select API first - Use mdns to detect and list octoprint instances (WIP need to figure out min version required) - Auto set Printer name if a detected install if found. I'm trying to reduce input and the need for a keyboard during onboarding. Obviously this is just the first step as the API key still needs to be inputed. But it's still a start. Follow Issue UnchartedBull#921 for more info on the changes. * Add postinstall so it auto rebuilds electron against node * Update src/app/config/no-config/no-config.component.ts Returns void Co-authored-by: Timon G. <timon.gaebelein@icloud.com> * Update src/app/config/no-config/no-config.component.ts Return Boolean Co-authored-by: Timon G. <timon.gaebelein@icloud.com> * Update src/app/config/no-config/no-config.component.ts Returns void Co-authored-by: Timon G. <timon.gaebelein@icloud.com> * Resolve a few issues with VSCode and more consistent var naming * Add version compare to disable older Nodes * Switch back to 5000 as the default and add a note about port 80 * test * Revert "test" This reverts commit 8564d39. * Attempt to fix CI * restructure main.js * With the new changes newer node is working again * Use proper indentation * Forgot to update package-lock with node update * electron stuff finished * Fix lint errors and warnings * finalise workflow * small bugfix * prevent the same instance showing multiple times * remove node from angular app * Manually trigger change detection * Also trigger change detection for Page changes to fix bug * intial setup to load op script * Fix ngZone issue * Remove ngx-electron from package-lock * Remove electron-rebuild, postinstall script and test if the travis changes are still needed since we are no longer rebuilding * Tested and no longer required, was a rebuild only issue * fix OctoPrint var * finally get that freakin jQuery working not pretty, but it works * cleanup + reset URL if manual input is opened. * Check OctoPrint connection and load client library * Update package-lock, fix a few navigation bugs * Make sure pages can't go below 0 or above totalPages * refactor navigation controller + show next button after page 1 again * login with request working * use printer name from printerprofile * fix setup (all working) * Convert to range slider to numeric input is not required * I think 150 would be fast enough to load * value selector for numbers * fix layout issue * Fix alignemnt on large and small views Co-authored-by: Timon G. <timon.gaebelein@icloud.com>
- Loading branch information
1 parent
e0a891e
commit 58ff9d0
Showing
25 changed files
with
1,047 additions
and
494 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
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
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,41 @@ | ||
/* eslint-disable @typescript-eslint/no-var-requires */ | ||
/* eslint-disable import/no-commonjs */ | ||
|
||
const mdns = require('mdns'); | ||
const compareVersions = require('compare-versions'); | ||
|
||
const minimumVersion = '1.3.5'; | ||
let mdnsBrowser; | ||
let nodes = []; | ||
|
||
function discoverNodes(window) { | ||
nodes = []; | ||
mdnsBrowser = mdns.createBrowser(mdns.tcp('octoprint')); | ||
mdnsBrowser.on('serviceUp', service => { | ||
nodes.push({ | ||
id: service.interfaceIndex, | ||
name: service.name, | ||
version: service.txtRecord.version, | ||
url: `http://${service.host.replace(/\.$/, '')}:${service.port}${service.txtRecord.path}api/`, | ||
disable: compareVersions(minimumVersion, service.txtRecord.version) === -1, | ||
}); | ||
sendNodes(window); | ||
}); | ||
|
||
mdnsBrowser.on('serviceDown', service => { | ||
nodes = nodes.filter(node => node.id !== service.interfaceIndex); | ||
sendNodes(window); | ||
}); | ||
|
||
mdnsBrowser.start(); | ||
} | ||
|
||
function stopDiscovery() { | ||
mdnsBrowser.stop(); | ||
} | ||
|
||
function sendNodes(window) { | ||
window.webContents.send('discoveredNodes', nodes); | ||
} | ||
|
||
module.exports = { discoverNodes, stopDiscovery }; |
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,68 @@ | ||
/* eslint-disable @typescript-eslint/no-var-requires */ | ||
/* eslint-disable import/no-commonjs */ | ||
|
||
const path = require('path'); | ||
const url = require('url'); | ||
|
||
const exec = require('child_process').exec; | ||
|
||
const sendCustomStyles = require('./styles'); | ||
const { downloadUpdate, sendVersionInfo } = require('./update'); | ||
const { discoverNodes, stopDiscovery } = require('./discover'); | ||
|
||
function activateScreenSleepListener(ipcMain) { | ||
ipcMain.on('screenSleep', () => { | ||
exec('xset dpms force standby'); | ||
}); | ||
|
||
ipcMain.on('screenWakeup', () => { | ||
exec('xset s off'); | ||
exec('xset -dpms'); | ||
exec('xset s noblank'); | ||
}); | ||
} | ||
|
||
function activateReloadListener(ipcMain, window) { | ||
ipcMain.on('reload', () => { | ||
window.loadURL( | ||
url.format({ | ||
pathname: path.join(__dirname, 'dist/index.html'), | ||
protocol: 'file:', | ||
slashes: true, | ||
}), | ||
); | ||
}); | ||
} | ||
|
||
function activateAppInfoListener(ipcMain, window, app) { | ||
ipcMain.on('appInfo', () => { | ||
sendCustomStyles(window); | ||
sendVersionInfo(window, app); | ||
}); | ||
} | ||
|
||
function activateUpdateListener(ipcMain, window) { | ||
ipcMain.on('update', (_, updateInfo) => { | ||
downloadUpdate(updateInfo, window); | ||
}); | ||
} | ||
|
||
function activateDiscoverListener(ipcMain, window) { | ||
ipcMain.on('discover', () => { | ||
discoverNodes(window); | ||
}); | ||
|
||
ipcMain.on('stopDiscover', () => { | ||
stopDiscovery(); | ||
}); | ||
} | ||
|
||
function activateListeners(ipcMain, window, app) { | ||
activateAppInfoListener(ipcMain, window, app); | ||
activateScreenSleepListener(ipcMain); | ||
activateReloadListener(ipcMain, window); | ||
activateUpdateListener(ipcMain, window); | ||
activateDiscoverListener(ipcMain, window); | ||
} | ||
|
||
module.exports = activateListeners; |
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,28 @@ | ||
/* eslint-disable @typescript-eslint/no-var-requires */ | ||
/* eslint-disable import/no-commonjs */ | ||
|
||
const fs = require('fs'); | ||
const path = require('path'); | ||
const { app } = require('electron'); | ||
|
||
function sendCustomStyles(window) { | ||
fs.readFile(path.join(app.getPath('userData'), 'custom-styles.css'), 'utf-8', (err, data) => { | ||
if (err) { | ||
if (err.code === 'ENOENT') { | ||
fs.writeFile(path.join(app.getPath('userData'), 'custom-styles.css'), '', err => { | ||
if (err) { | ||
window.webContents.send('customStylesError', err); | ||
} else { | ||
window.webContents.send('customStyles', ''); | ||
} | ||
}); | ||
} else { | ||
window.webContents.send('customStylesError', err); | ||
} | ||
} else { | ||
window.webContents.send('customStyles', data); | ||
} | ||
}); | ||
} | ||
|
||
module.exports = sendCustomStyles; |
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,103 @@ | ||
/* eslint-disable no-sync */ | ||
/* eslint-disable @typescript-eslint/no-var-requires */ | ||
/* eslint-disable import/no-commonjs */ | ||
|
||
const fs = require('fs'); | ||
const got = require('got'); | ||
const stream = require('stream'); | ||
const { promisify } = require('util'); | ||
const progress = require('progress-stream'); | ||
|
||
const exec = require('child_process').exec; | ||
|
||
function downloadUpdate(updateInfo, window) { | ||
const downloadPath = '/tmp/octodash.deb'; | ||
|
||
exec('arch', (err, stdout, stderr) => { | ||
if (err || stderr) { | ||
window.webContents.send('updateError', { | ||
error: err || { message: stderr }, | ||
}); | ||
} | ||
got(updateInfo.assetsURL) | ||
.then(releaseFiles => { | ||
const reducer = (accumulator, currentValue) => accumulator + currentValue; | ||
const averageETA = []; | ||
let downloadURL; | ||
let packageSize; | ||
for (const package of JSON.parse(releaseFiles.body)) { | ||
if (package.name.includes(stdout.trim())) { | ||
downloadURL = package.browser_download_url; | ||
packageSize = package.size; | ||
} | ||
} | ||
if (downloadURL) { | ||
const downloadPipeline = promisify(stream.pipeline); | ||
const downloadProgress = progress({ | ||
length: packageSize, | ||
time: 300, | ||
}); | ||
|
||
downloadProgress.on('progress', progress => { | ||
averageETA.push(progress.eta); | ||
if (averageETA.length > 4) averageETA.shift(); | ||
window.webContents.send('updateDownloadProgress', { | ||
percentage: progress.percentage, | ||
transferred: (progress.transferred / 100000).toFixed(1), | ||
total: (progress.length / 1000000).toFixed(1), | ||
remaining: (progress.remaining / 100000).toFixed(1), | ||
eta: new Date(averageETA.reduce(reducer) * 1000).toISOString().substr(14, 5), | ||
runtime: new Date(progress.runtime * 1000).toISOString().substr(14, 5), | ||
delta: (progress.delta / 100000).toFixed(1), | ||
speed: (progress.speed / 1000000).toFixed(2), | ||
}); | ||
}); | ||
|
||
try { | ||
if (fs.existsSync(downloadPath)) fs.unlinkSync(downloadPath); | ||
} catch { | ||
// no need to handle this properly | ||
} | ||
|
||
downloadPipeline(got.stream(downloadURL), downloadProgress, fs.createWriteStream(downloadPath)) | ||
.catch(error => { | ||
window.webContents.send('updateError', { | ||
error: { | ||
message: `Can't download package! ${error.message}.`, | ||
}, | ||
}); | ||
}) | ||
.then(() => { | ||
window.webContents.send('updateDownloadFinished'); | ||
exec('sudo ~/scripts/update-octodash', (err, _, stderr) => { | ||
if (err || stderr) { | ||
window.webContents.send('updateError', { | ||
error: err || { message: stderr }, | ||
}); | ||
} else { | ||
window.webContents.send('updateInstalled'); | ||
} | ||
}); | ||
}); | ||
} else { | ||
window.webContents.send('updateError', { | ||
error: { | ||
message: `Can't find matching package for architecture ${stdout}.`, | ||
}, | ||
}); | ||
} | ||
}) | ||
.catch(error => { | ||
error.message = `Can't load releases. ${error.message}`; | ||
window.webContents.send('updateError', { error }); | ||
}); | ||
}); | ||
} | ||
|
||
function sendVersionInfo(window, app) { | ||
window.webContents.send('versionInformation', { | ||
version: app.getVersion(), | ||
}); | ||
} | ||
|
||
module.exports = { downloadUpdate, sendVersionInfo }; |
Oops, something went wrong.