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.
Switch to websockets (UnchartedBull#1438)
* remove api from host * websocket connected * wip * move config to electron * finish moving config part to electron * temperatures on main screen using socket * defer filament manager from abstract class * replaced printer temperature + status observable * PrinterService behind abstract service * Create system service * merge profile & printer service * add lottie loading animation for files * enclosure service created * starting to refactor files service * adjust sorting * fix M600 not being sent * Fix long-pressing directive * replace subject with replaySubject * Move PSUControl + TPLinkSmartPlug * get fanspeed from websocket * rework OctoDash model * remove DLP service and replace with socket * wip * event socket done * update standby screen * fix state issue * socket reauth * Finish job service transition * squish the bugs * replace checkmark animation * start transitioning file service * transition files service * cleanup
- Loading branch information
1 parent
c6d8fb8
commit f946abc
Showing
117 changed files
with
3,654 additions
and
3,519 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
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 }; |
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
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
Oops, something went wrong.