From f192d5234591306d515908eb78a8c32f7faf99d4 Mon Sep 17 00:00:00 2001 From: cha0s Date: Mon, 4 Apr 2022 07:16:46 -0500 Subject: [PATCH] feat: electron goodies --- .neutrinorc.js | 8 -------- build/flecks.yml | 6 ++++++ packages/core/package.json | 5 ++++- packages/core/src/electron/server.js | 29 ++++++++++++++++++++++++++++ packages/core/src/server.js | 14 -------------- 5 files changed, 39 insertions(+), 23 deletions(-) delete mode 100644 .neutrinorc.js create mode 100644 packages/core/src/electron/server.js diff --git a/.neutrinorc.js b/.neutrinorc.js deleted file mode 100644 index 326b528..0000000 --- a/.neutrinorc.js +++ /dev/null @@ -1,8 +0,0 @@ -require('dotenv/config'); - -module.exports = { - options: { - root: __dirname, - }, - use: [], -}; diff --git a/build/flecks.yml b/build/flecks.yml index 79252e3..1cab6a5 100644 --- a/build/flecks.yml +++ b/build/flecks.yml @@ -109,6 +109,11 @@ '@flecks/redux': {} '@flecks/repl': {} '@flecks/server': + nodeArgs: + - '--inspect' + # - '--log-deopt' + # - '--log-ic' + # - '--logfile=/home/cha0s/yuge/tmp/v8.log' up: - '@flecks/docker' - '@flecks/db' @@ -136,6 +141,7 @@ resolution: [1600, 900] '@humus/combat': {} '@humus/core': {} +'@humus/core/electron': {} '@humus/farm': {} '@humus/inventory': {} '@humus/universe': diff --git a/packages/core/package.json b/packages/core/package.json index bfe044e..9a7d964 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -18,6 +18,8 @@ }, "files": [ "build", + "electron/server.js", + "electron/server.js.map", "index.js", "index.js.map", "server.js", @@ -44,7 +46,8 @@ "@flecks/redux": "^1.4.1", "@flecks/socket": "^1.4.1", "@flecks/user": "^1.4.1", - "debug": "4.3.1" + "debug": "4.3.1", + "is-electron": "^2.2.1" }, "devDependencies": { "@flecks/fleck": "^1.4.1" diff --git a/packages/core/src/electron/server.js b/packages/core/src/electron/server.js new file mode 100644 index 0000000..6a575ca --- /dev/null +++ b/packages/core/src/electron/server.js @@ -0,0 +1,29 @@ +import {Hooks} from '@flecks/core'; +import isElectron from 'is-electron'; + +const { + NODE_ENV, +} = process.env; + +export default { + [Hooks]: { + '@flecks/electron/server.window': async (win) => { + win.removeMenu(); + if ('production' !== NODE_ENV) { + win.openDevTools(); + } + win.maximize(); + win.once('ready-to-show', () => { + win.show(); + }); + }, + '@flecks/web/server.request.route': (flecks) => async (req, res, next) => { + if (isElectron() && 0 === req.user.id) { + const {User} = flecks.get('$flecks/db.models'); + req.logIn(await User.findByPk(1), next); + return; + } + next(); + }, + }, +}; diff --git a/packages/core/src/server.js b/packages/core/src/server.js index d7304cf..e69de29 100644 --- a/packages/core/src/server.js +++ b/packages/core/src/server.js @@ -1,14 +0,0 @@ -import {Hooks} from '@flecks/core'; - -export default { - [Hooks]: { - '@flecks/electron/server.window': async (win) => { - win.removeMenu(); - win.openDevTools(); - win.maximize(); - win.once('ready-to-show', () => { - win.show(); - }); - }, - }, -};