Skip to content

Commit

Permalink
feat: better detection of valid config
Browse files Browse the repository at this point in the history
  • Loading branch information
timotheeg committed Oct 14, 2024
1 parent 7a01194 commit 62da69f
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion public/ocr/ocr_main.js
Original file line number Diff line number Diff line change
Expand Up @@ -1706,7 +1706,24 @@ function saveConfig(config) {
}

function hasConfig() {
return !!localStorage.getItem('config');
const maybeConfig = localStorage.getItem('config');
if (!config) return false;

// minimal checks for validitu of the config object
// could add coimprehensive verification later
// for now guard against initial calibration not completed
try {
const parsed = JSON.parse(maybeConfig);
if (!parsed || !parsed.tasks) return false;

const tasks = Object.values(parsed.tasks);
if (tasks.length <= 0) return false;
if (!tasks.every(task => !!task.crop)) return false;
} catch (err) {
return false;
}

return true;
}

function getGameTypeFromTasks(tasks) {
Expand Down

0 comments on commit 62da69f

Please sign in to comment.