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

Switch to websockets #1438

Merged
merged 36 commits into from
Mar 18, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
859f239
remove api from host
UnchartedBull Jan 31, 2021
cb85e48
websocket connected
UnchartedBull Jan 31, 2021
2239828
wip
UnchartedBull Feb 9, 2021
50d6d03
Merge branch 'main' into feature/websocket
UnchartedBull Feb 9, 2021
b4df95b
move config to electron
UnchartedBull Feb 9, 2021
e1bf720
finish moving config part to electron
UnchartedBull Feb 9, 2021
83c4631
temperatures on main screen using socket
UnchartedBull Feb 10, 2021
620882d
defer filament manager from abstract class
UnchartedBull Feb 10, 2021
d2559f6
replaced printer temperature + status observable
UnchartedBull Feb 10, 2021
e081043
PrinterService behind abstract service
UnchartedBull Feb 15, 2021
703633d
Create system service
UnchartedBull Feb 15, 2021
fa191d0
merge profile & printer service
UnchartedBull Feb 16, 2021
30fb11e
add lottie loading animation for files
UnchartedBull Feb 16, 2021
75c32ac
enclosure service created
UnchartedBull Feb 17, 2021
7c701b0
starting to refactor files service
UnchartedBull Feb 17, 2021
1895c5c
adjust sorting
UnchartedBull Feb 18, 2021
4605fe6
fix M600 not being sent
UnchartedBull Mar 5, 2021
b750914
Fix long-pressing directive
UnchartedBull Mar 5, 2021
c6a118d
replace subject with replaySubject
UnchartedBull Mar 11, 2021
e15af7b
Move PSUControl + TPLinkSmartPlug
UnchartedBull Mar 11, 2021
d328e2c
get fanspeed from websocket
UnchartedBull Mar 11, 2021
be4998e
rework OctoDash model
UnchartedBull Mar 13, 2021
138e2ed
remove DLP service and replace with socket
UnchartedBull Mar 15, 2021
3d0b0b8
wip
UnchartedBull Mar 15, 2021
56276a8
event socket done
UnchartedBull Mar 17, 2021
fdf7258
update standby screen
UnchartedBull Mar 17, 2021
fda82de
fix state issue
UnchartedBull Mar 17, 2021
b5f1a76
socket reauth
UnchartedBull Mar 17, 2021
550f2b1
Finish job service transition
UnchartedBull Mar 17, 2021
73f8a7b
squish the bugs
UnchartedBull Mar 17, 2021
eb8e540
replace checkmark animation
UnchartedBull Mar 18, 2021
59436b9
start transitioning file service
UnchartedBull Mar 18, 2021
0759ccc
transition files service
UnchartedBull Mar 18, 2021
27193d1
cleanup
UnchartedBull Mar 18, 2021
99ba705
Merge branch 'main' into feature/websocket
UnchartedBull Mar 18, 2021
6326daa
Merge branch 'main' into feature/websocket
UnchartedBull Mar 18, 2021
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
1 change: 0 additions & 1 deletion angular.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
"builder": "@angular-devkit/build-angular:browser",
"options": {
"aot": true,
"allowedCommonJsDependencies": ["angular-svg-round-progressbar", "lodash", "ajv"],
"outputPath": "dist",
"index": "src/index.html",
"main": "src/main.ts",
Expand Down
56 changes: 56 additions & 0 deletions helper/config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/* eslint-disable @typescript-eslint/no-var-requires */

const Store = require('electron-store');
const Ajv = require('ajv');
const configSchema = require('./config.schema');

let store;
const ajv = new Ajv({ allErrors: true });
const validate = ajv.compile(configSchema);

function readConfig(window) {
try {
if (!store) {
store = new Store();
}
const config = store.get('config');
window.webContents.send('configRead', config);
} catch {
window.webContents.send('configError', "Can't read config file.");
}
}

function saveConfig(window, config) {
if (validate(config)) {
try {
store.set('config', config);
window.webContents.send('configSaved', config);
} catch {
window.webContents.send('configError', "Can't save config file.");
}
} else {
window.webContents.send('configSaveFail', getConfigErrors());
}
}

function checkConfig(window, config) {
if (!validate(config)) {
window.webContents.send('configFail', getConfigErrors());
} else {
window.webContents.send('configPass');
}
}

function getConfigErrors() {
const errors = [];
validate.errors?.forEach(error => {
if (error.keyword === 'type') {
errors.push(`${error.dataPath} ${error.message}`);
} else {
errors.push(`${error.dataPath === '' ? '.' : error.dataPath} ${error.message}`);
}
});
return errors;
}

module.exports = { readConfig, saveConfig, checkConfig };
4 changes: 3 additions & 1 deletion src/app/config/config.schema.ts → helper/config.schema.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export const configSchema = {
const configSchema = {
definitions: {},
$schema: 'http://json-schema.org/draft-07/schema#',
$id: 'http://example.com/root.json',
Expand Down Expand Up @@ -322,3 +322,5 @@ export const configSchema = {
},
},
};

module.exports = configSchema;
2 changes: 1 addition & 1 deletion helper/discover.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ function discoverNodes(window) {
id: service.addresses[0] + service.port,
name: service.name,
version: service.txt.version,
url: `http://${service.host.replace(/\.$/, '')}:${service.port}${service.txt.path}api/`,
url: `http://${service.host.replace(/\.$/, '')}:${service.port}${service.txt.path}`,
disable: compareVersions(minimumVersion, service.txt.version) === -1,
});
sendNodes(window);
Expand Down
43 changes: 11 additions & 32 deletions helper/listener.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,20 @@
/* eslint-disable @typescript-eslint/no-var-requires */
/* eslint-disable import/no-commonjs */
const exec = require('child_process').exec;
const waitPort = require('wait-port');

const sendCustomStyles = require('./styles');
const { downloadUpdate, sendVersionInfo } = require('./update');
const { discoverNodes, stopDiscovery } = require('./discover');
const { readConfig, saveConfig, checkConfig } = require('./config');

function activateScreenSleepListener(ipcMain) {
ipcMain.on('screenControl', (_, screenCommand) => {
exec(screenCommand.command);
});
ipcMain.on('screenControl', (_, screenCommand) => exec(screenCommand.command));
}

function activateReloadListener(ipcMain, window, dev) {
ipcMain.on('reload', () => {
if (dev) {
window.reload();
window.loadURL('http://localhost:4200');
} else {
window.loadURL('app://.');
}
Expand All @@ -31,42 +29,23 @@ function activateAppInfoListener(ipcMain, window, app) {
}

function activateUpdateListener(ipcMain, window) {
ipcMain.on('update', (_, updateInfo) => {
downloadUpdate(updateInfo, window);
});
ipcMain.on('update', (_, updateInfo) => downloadUpdate(updateInfo, window));
}

function activateDiscoverListener(ipcMain, window) {
ipcMain.on('discover', () => {
discoverNodes(window);
});
ipcMain.on('discover', () => discoverNodes(window));

ipcMain.on('stopDiscover', () => {
stopDiscovery();
});
ipcMain.on('stopDiscover', () => stopDiscovery());
}

function activatePortListener(ipcMain, window) {
ipcMain.on('checkOctoPrintPort', (_, hostInfo) => {
const waitPortParams = {
host: hostInfo.host,
port: hostInfo.port,
output: 'silent',
timeout: 60000,
};

waitPort(waitPortParams)
.then(open => {
window.webContents.send('octoprintReady', open);
})
.catch(error => {
window.webContents.send('waitPortError', error);
});
});
function activateConfigListener(ipcMain, window) {
ipcMain.on('readConfig', () => readConfig(window));
ipcMain.on('saveConfig', (_, config) => saveConfig(window, config));
ipcMain.on('checkConfig', (_, config) => checkConfig(window, config));
}

function activateListeners(ipcMain, window, app, dev) {
activatePortListener(ipcMain, window);
activateConfigListener(ipcMain, window);
activateAppInfoListener(ipcMain, window, app);
activateScreenSleepListener(ipcMain);
activateReloadListener(ipcMain, window, dev);
Expand Down
15 changes: 9 additions & 6 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,24 @@ const Store = require('electron-store');
const args = process.argv.slice(1);
const big = args.some(val => val === '--big');
const dev = args.some(val => val === '--serve');
const scheme = 'app';

const activateListeners = require('./helper/listener');
const createProtocol = require('./helper/protocol');

protocol.registerSchemesAsPrivileged([{ scheme: scheme, privileges: { standard: true } }]);
createProtocol(scheme, path.join(__dirname, 'dist'));
if (!dev) {
const createProtocol = require('./helper/protocol');
const scheme = 'app';

app.commandLine.appendSwitch('touch-events', 'enabled');
protocol.registerSchemesAsPrivileged([{ scheme: scheme, privileges: { standard: true } }]);
createProtocol(scheme, path.join(__dirname, 'dist'));
}

const store = new Store();
app.commandLine.appendSwitch('touch-events', 'enabled');

let window;

function createWindow() {
const _store = new Store();

if (!dev) {
session.defaultSession.webRequest.onHeadersReceived((details, callback) => {
callback({
Expand Down
Loading