Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reduce input during on-boarding #954

Merged
merged 51 commits into from
Sep 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
8554b88
- Add mdns and ngx-electron plugin
TheSin- Aug 29, 2020
8923014
Merge with upstream master
TheSin- Aug 29, 2020
7313d24
Add postinstall so it auto rebuilds electron against node
TheSin- Aug 31, 2020
b038c08
Update src/app/config/no-config/no-config.component.ts
TheSin- Aug 31, 2020
6c53aec
Update src/app/config/no-config/no-config.component.ts
TheSin- Aug 31, 2020
8716587
Update src/app/config/no-config/no-config.component.ts
TheSin- Aug 31, 2020
68887b1
Resolve a few issues with VSCode and more consistent var naming
TheSin- Aug 31, 2020
afb80d7
Add version compare to disable older Nodes
TheSin- Aug 31, 2020
57172e1
Switch back to 5000 as the default and add a note about port 80
TheSin- Aug 31, 2020
8564d39
test
UnchartedBull Aug 31, 2020
9caf235
Revert "test"
UnchartedBull Aug 31, 2020
73387d2
Attempt to fix CI
TheSin- Aug 31, 2020
36887ce
Merge branch 'master' of git://github.com/TheSin-/OctoDash
TheSin- Aug 31, 2020
a2dff3a
restructure main.js
UnchartedBull Aug 31, 2020
957cb03
With the new changes newer node is working again
TheSin- Aug 31, 2020
735f395
Use proper indentation
TheSin- Aug 31, 2020
0e3d9a6
Forgot to update package-lock with node update
TheSin- Aug 31, 2020
becd2c4
electron stuff finished
UnchartedBull Aug 31, 2020
540fc43
Fix lint errors and warnings
TheSin- Aug 31, 2020
2e2e675
Merge remote-tracking branch 'origin/master'
UnchartedBull Aug 31, 2020
ab726d4
finalise workflow
UnchartedBull Aug 31, 2020
8f91083
small bugfix
UnchartedBull Aug 31, 2020
e2f64d2
prevent the same instance showing multiple times
UnchartedBull Aug 31, 2020
6bafeb3
remove node from angular app
UnchartedBull Aug 31, 2020
d050ae0
Manually trigger change detection
UnchartedBull Aug 31, 2020
727ad51
Also trigger change detection for Page changes to fix bug
UnchartedBull Aug 31, 2020
ad0c41b
intial setup to load op script
UnchartedBull Sep 1, 2020
dd4816f
Fix ngZone issue
UnchartedBull Sep 1, 2020
6bc207d
Merge remote-tracking branch 'upstream/master'
TheSin- Sep 1, 2020
5824236
Remove ngx-electron from package-lock
TheSin- Sep 1, 2020
510bf8a
Remove electron-rebuild, postinstall script and test if the travis ch…
TheSin- Sep 1, 2020
11ff0b5
Tested and no longer required, was a rebuild only issue
TheSin- Sep 1, 2020
b174b30
Merge master
TheSin- Sep 2, 2020
beabf32
fix OctoPrint var
UnchartedBull Sep 2, 2020
ae5a087
finally get that freakin jQuery working
UnchartedBull Sep 2, 2020
5f7fe86
cleanup + reset URL if manual input is opened.
UnchartedBull Sep 2, 2020
2a62ccb
Check OctoPrint connection and load client library
UnchartedBull Sep 2, 2020
dbc7db9
Update package-lock, fix a few navigation bugs
TheSin- Sep 3, 2020
4df9b99
Make sure pages can't go below 0 or above totalPages
TheSin- Sep 3, 2020
a913bd3
refactor navigation controller + show next button after page 1 again
UnchartedBull Sep 4, 2020
77bafa9
login with request working
UnchartedBull Sep 4, 2020
4bc7f96
use printer name from printerprofile
UnchartedBull Sep 4, 2020
bf98a4a
fix setup (all working)
UnchartedBull Sep 4, 2020
5dac7f9
Merge with Master
TheSin- Sep 4, 2020
6083fca
Convert to range slider to numeric input is not required
TheSin- Sep 11, 2020
e63a183
Merge changes from master
TheSin- Sep 11, 2020
f6086df
I think 150 would be fast enough to load
TheSin- Sep 11, 2020
159e418
value selector for numbers
UnchartedBull Sep 15, 2020
dd861f0
Merge branch 'master' into master
UnchartedBull Sep 15, 2020
3f33af4
fix layout issue
UnchartedBull Sep 15, 2020
be231ef
Fix alignemnt on large and small views
TheSin- Sep 15, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ module.exports = {
'@typescript-eslint/no-parameter-properties': 'off',
'@typescript-eslint/no-use-before-define': 'off',
'import/no-unresolved': 'off',
camelcase: 'warn',
'camelcase': 'warn',
'simple-import-sort/sort': 'warn',
'sort-imports': 'off',
'import/first': 'warn',
Expand All @@ -42,5 +42,11 @@ module.exports = {
],
},
},
{
files: '**/*.js',
env: {
node: true,
},
},
],
};
41 changes: 14 additions & 27 deletions angular.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"version": 1,
"newProjectRoot": "projects",
"projects": {
"OctoPrintDash": {
"OctoDash": {
"projectType": "application",
"schematics": {
"@schematics/angular:component": {
Expand All @@ -18,6 +18,7 @@
"builder": "@angular-devkit/build-angular:browser",
"options": {
"aot": true,
"allowedCommonJsDependencies": ["angular-svg-round-progressbar"],
"outputPath": "dist",
"index": "src/index.html",
"main": "src/main.ts",
Expand All @@ -40,9 +41,7 @@
"output": "/"
}
],
"styles": [
"src/styles.scss"
],
"styles": ["src/styles.scss"],
"scripts": []
},
"configurations": {
Expand Down Expand Up @@ -79,18 +78,18 @@
"serve": {
"builder": "@angular-devkit/build-angular:dev-server",
"options": {
"browserTarget": "OctoPrintDash:build"
"browserTarget": "OctoDash:build"
},
"configurations": {
"production": {
"browserTarget": "OctoPrintDash:build:production"
"browserTarget": "OctoDash:build:production"
}
}
},
"extract-i18n": {
"builder": "@angular-devkit/build-angular:extract-i18n",
"options": {
"browserTarget": "OctoPrintDash:build"
"browserTarget": "OctoDash:build"
}
},
"test": {
Expand All @@ -100,47 +99,35 @@
"polyfills": "src/polyfills.ts",
"tsConfig": "tsconfig.spec.json",
"karmaConfig": "karma.conf.js",
"assets": [
"src/favicon.ico",
"src/assets",
"src/assets/icon/icon-main-title.svg"
],
"styles": [
"src/styles.scss"
],
"assets": ["src/favicon.ico", "src/assets", "src/assets/icon/icon-main-title.svg"],
"styles": ["src/styles.scss"],
"scripts": []
}
},
"lint": {
"builder": "@angular-devkit/build-angular:tslint",
"options": {
"tsConfig": [
"tsconfig.app.json",
"tsconfig.spec.json",
"tsconfig.json"
],
"exclude": [
"**/node_modules/**"
]
"tsConfig": ["tsconfig.app.json", "tsconfig.spec.json", "tsconfig.json"],
"exclude": ["**/node_modules/**"]
}
},
"e2e": {
"builder": "@angular-devkit/build-angular:protractor",
"options": {
"protractorConfig": "e2e/protractor.conf.js",
"devServerTarget": "OctoPrintDash:serve"
"devServerTarget": "OctoDash:serve"
},
"configurations": {
"production": {
"devServerTarget": "OctoPrintDash:serve:production"
"devServerTarget": "OctoDash:serve:production"
}
}
}
}
}
},
"defaultProject": "OctoPrintDash",
"defaultProject": "OctoDash",
"cli": {
"analytics": "e1569209-2b82-4195-9c15-0669a78feccb"
}
}
}
41 changes: 41 additions & 0 deletions helper/discover.js
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 };
68 changes: 68 additions & 0 deletions helper/listener.js
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;
28 changes: 28 additions & 0 deletions helper/styles.js
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;
103 changes: 103 additions & 0 deletions helper/update.js
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 };
Loading