From 6102f3d4f6266b17ce51350bd0e82ff0cf5c0bbd Mon Sep 17 00:00:00 2001 From: Daniel Stock Date: Tue, 28 May 2024 18:50:15 +0200 Subject: [PATCH] ignore config and include an example config instead --- .gitignore | 2 ++ config.example.json | 10 ++++++++++ config.json | 8 -------- main.js | 41 +++++++++++++++++++++++------------------ 4 files changed, 35 insertions(+), 26 deletions(-) create mode 100644 config.example.json delete mode 100644 config.json diff --git a/.gitignore b/.gitignore index ceaea36..77715bb 100644 --- a/.gitignore +++ b/.gitignore @@ -130,3 +130,5 @@ dist .yarn/install-state.gz .pnp.* +# Tooloop +config.json \ No newline at end of file diff --git a/config.example.json b/config.example.json new file mode 100644 index 0000000..4649d2e --- /dev/null +++ b/config.example.json @@ -0,0 +1,10 @@ +{ + "url": "file:///assets/data/index.html", + "allowedDomains": [ + "localhost", + "127.0.0.1", + "tooloop.de", + "www.tooloop.de" + ], + "logPath": "/assets/logs/Tooloop-Kiosk-Browser.log" +} \ No newline at end of file diff --git a/config.json b/config.json deleted file mode 100644 index 62dc20b..0000000 --- a/config.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "url": "https://www.tooloop.de", - "allowedDomains": [ - "tooloop.de", - "www.tooloop.de" - ], - "logPath": "/Users/vollstock/Arbeit/Playground/tooloop-kiosk-browser-logs/tooloop-kiosk-browser.log" -} \ No newline at end of file diff --git a/main.js b/main.js index 03a87bf..0577550 100644 --- a/main.js +++ b/main.js @@ -25,7 +25,11 @@ function loadConfig() { const data = fs.readFileSync(path.join(__dirname, "config.json"), { encoding: 'utf8' }); config = JSON.parse(data); } catch (err) { - console.error(err); + if (err.code == 'ENOENT') { + console.warn('No config file found.'); + } else { + console.error(err); + } } } @@ -59,24 +63,25 @@ async function createWindow() { win.loadFile('index.html'); - try { - let url = new URL(config.url); - // let options = { - // method: 'HEAD', - // host: url.hostname, - // port: url.port ? url.port : 80, - // path: '/' - // }; - // let req = http.request(options, function (r) { - // log.info(r.headers); - // }); - // req.end(); + if (config != undefined) { + try { + let url = new URL(config.url); + // let options = { + // method: 'HEAD', + // host: url.hostname, + // port: url.port ? url.port : 80, + // path: '/' + // }; + // let req = http.request(options, function (r) { + // log.info(r.headers); + // }); + // req.end(); - win.loadURL(config.url); + win.loadURL(config.url); - } catch (err) { - log.error(err); - } finally { + } catch (err) { + log.error(err); + } } } @@ -103,7 +108,7 @@ app.whenReady().then(() => { loadConfig(); log.initialize(); - if ('logPath' in config) { + if (config != undefined && 'logPath' in config) { log.transports.file.resolvePathFn = () => config.logPath; }