From 053a8bf11c39e78dad15a809468cec7f0fca6e44 Mon Sep 17 00:00:00 2001 From: uonai Date: Sat, 1 Aug 2020 13:25:24 -0500 Subject: [PATCH 1/5] Electron env updates --- electron/main.js | 9 +++++++-- index.js | 32 ++++++++++++++++++++++---------- package.json | 6 +++--- 3 files changed, 32 insertions(+), 15 deletions(-) diff --git a/electron/main.js b/electron/main.js index f2f10b34..13fa46b1 100644 --- a/electron/main.js +++ b/electron/main.js @@ -3,6 +3,11 @@ const { app, BrowserWindow } = require("electron"); const path = require("path"); const fs = require("fs-extra"); +// NOTE(colin): use NEXTJS Production build +process.env.NODE_ENV = "production"; +// NOTE(colin): allow API connection +process.env.NODE_TLS_REJECT_UNAUTHORIZED = 0; + function bootServer() { // TODO(colin): Spin up server on a child process // const { fork } = require('child_process'); @@ -51,7 +56,7 @@ app.whenReady().then(() => { bootServer(); createWindow(); - app.on("activate", function() { + app.on("activate", function () { // On macOS it's common to re-create a window in the app when the // dock icon is clicked and there are no other windows open. if (BrowserWindow.getAllWindows().length === 0) createWindow(); @@ -61,7 +66,7 @@ app.whenReady().then(() => { // Quit when all windows are closed, except on macOS. There, it's common // for applications and their menu bar to stay active until the user quits // explicitly with Cmd + Q. -app.on("window-all-closed", function() { +app.on("window-all-closed", function () { if (process.platform !== "darwin") app.quit(); }); diff --git a/index.js b/index.js index b679cc82..0ab079fc 100644 --- a/index.js +++ b/index.js @@ -1,18 +1,30 @@ -require('@babel/register')({ +const path = require("path"); +const dirPath = path.join(__dirname); +require("@babel/register")({ presets: [ - [require.resolve('@babel/preset-env')], + [require.resolve("@babel/preset-env")], [ - require.resolve('next/babel'), + require.resolve("next/babel"), { - 'preset-env': {}, - 'transform-runtime': {}, - 'styled-jsx': {}, - 'class-properties': {}, + "preset-env": {}, + "transform-runtime": {}, + "styled-jsx": {}, + "class-properties": {}, }, ], ], - plugins: [[require.resolve('@babel/plugin-transform-runtime')]], - ignore: ['node_modules', '.next'], + plugins: [ + [require.resolve("@babel/plugin-transform-runtime")], + [ + require.resolve("babel-plugin-module-resolver"), + { + alias: { + "~": dirPath, + }, + }, + ], + ], + ignore: ["node_modules", ".next"], }); -module.exports = require('./server.js'); +module.exports = require("./server.js"); diff --git a/package.json b/package.json index 077ad340..91a78526 100644 --- a/package.json +++ b/package.json @@ -10,9 +10,9 @@ "build": "NODE_ENV=production next build", "build-electron": "NODE_ENV=production next build", "build-system": "rollup -c", - "electron": "electron ./electron/main.js ", - "electron-pack": "electron-builder --dir", - "electron-dist": "electron-builder", + "electron": "NODE_TLS_REJECT_UNAUTHORIZED=0 NODE_ENV=production electron ./electron/main.js ", + "electron-pack": "NODE_TLS_REJECT_UNAUTHORIZED=0 NODE_ENV=production electron-builder --dir", + "electron-dist": "NODE_TLS_REJECT_UNAUTHORIZED=0 NODE_ENV=production electron-builder", "scripts": "NODE_TLS_REJECT_UNAUTHORIZED=0 node ./scripts", "www-setup-database": "NODE_TLS_REJECT_UNAUTHORIZED=0 node ./scripts setup-database", "www-seed-database": "NODE_TLS_REJECT_UNAUTHORIZED=0 node ./scripts seed-database", From 05ed70d586f7399ee08d9cbe3c627cd624e42f32 Mon Sep 17 00:00:00 2001 From: uonai Date: Sun, 2 Aug 2020 16:09:55 -0500 Subject: [PATCH 2/5] Online / offline state update --- components/core/Application.js | 34 ++++++++++++++++++++++++++++------ electron/main.js | 5 +++-- package.json | 6 ++---- 3 files changed, 33 insertions(+), 12 deletions(-) diff --git a/components/core/Application.js b/components/core/Application.js index 301ac160..ea000ed8 100644 --- a/components/core/Application.js +++ b/components/core/Application.js @@ -48,6 +48,7 @@ export default class ApplicationPage extends React.Component { data: null, sidebar: null, sidebarLoading: false, + online: null, }; async componentDidMount() { @@ -55,6 +56,9 @@ export default class ApplicationPage extends React.Component { window.addEventListener("dragleave", this._handleDragLeave); window.addEventListener("dragover", this._handleDragOver); window.addEventListener("drop", this._handleDrop); + + window.addEventListener("online", this._handleOnlineStatus); + window.addEventListener("offline", this._handleOnlineStatus); } componentWillUnmount() { @@ -64,11 +68,19 @@ export default class ApplicationPage extends React.Component { window.removeEventListener("drop", this._handleDrop); } + _handleOnlineStatus = async () => { + window.alert(navigator.onLine ? "online" : "offline"); + this.setState({ online: navigator.onLine }); + }; + _handleSetFile = async ({ file, slate }) => { + // + console.log(file); this.setState({ fileLoading: true }); let data = new FormData(); - data.append("data", file); + data.append("image", file); + console.log(data); const options = { method: "POST", @@ -241,7 +253,8 @@ export default class ApplicationPage extends React.Component { _handleDeleteYourself = async () => { // TODO(jim): // Put this somewhere better for messages. - const message = "Do you really want to delete your account? It will be permanently removed"; + const message = + "Do you really want to delete your account? It will be permanently removed"; if (!window.confirm(message)) { return false; } @@ -441,8 +454,12 @@ export default class ApplicationPage extends React.Component { - + url="https://slate.host/application" + > + ); } @@ -515,12 +532,17 @@ export default class ApplicationPage extends React.Component { return ( - + + onDismissSidebar={this._handleDismissSidebar} + > {scene} diff --git a/electron/main.js b/electron/main.js index 13fa46b1..4e72b30c 100644 --- a/electron/main.js +++ b/electron/main.js @@ -4,9 +4,10 @@ const path = require("path"); const fs = require("fs-extra"); // NOTE(colin): use NEXTJS Production build -process.env.NODE_ENV = "production"; +if (process.env.NODE_ENV == undefined) process.env.NODE_ENV = "production"; // NOTE(colin): allow API connection -process.env.NODE_TLS_REJECT_UNAUTHORIZED = 0; +if (process.env.NODE_TLS_REJECT_UNAUTHORIZED == undefined) + process.env.NODE_TLS_REJECT_UNAUTHORIZED = 0; function bootServer() { // TODO(colin): Spin up server on a child process diff --git a/package.json b/package.json index 91a78526..b60029a4 100644 --- a/package.json +++ b/package.json @@ -8,11 +8,9 @@ "start": "NODE_ENV=production node . --unhandled-rejections=strict", "build-delete": "rm -rf .next && rm -rf dist/mac", "build": "NODE_ENV=production next build", - "build-electron": "NODE_ENV=production next build", "build-system": "rollup -c", - "electron": "NODE_TLS_REJECT_UNAUTHORIZED=0 NODE_ENV=production electron ./electron/main.js ", - "electron-pack": "NODE_TLS_REJECT_UNAUTHORIZED=0 NODE_ENV=production electron-builder --dir", - "electron-dist": "NODE_TLS_REJECT_UNAUTHORIZED=0 NODE_ENV=production electron-builder", + "electron-dev": "NODE_ENV=development electron ./electron/main.js ", + "electron-prod": "NODE_ENV=production next build && electron-builder --dir", "scripts": "NODE_TLS_REJECT_UNAUTHORIZED=0 node ./scripts", "www-setup-database": "NODE_TLS_REJECT_UNAUTHORIZED=0 node ./scripts setup-database", "www-seed-database": "NODE_TLS_REJECT_UNAUTHORIZED=0 node ./scripts seed-database", From 4beb1759b0803077c28ccd7f42806fd6c9f649a9 Mon Sep 17 00:00:00 2001 From: uonai Date: Sun, 2 Aug 2020 22:46:22 -0500 Subject: [PATCH 3/5] Redirect to /application route in electron --- electron/main.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/electron/main.js b/electron/main.js index 4e72b30c..a6578440 100644 --- a/electron/main.js +++ b/electron/main.js @@ -14,7 +14,7 @@ function bootServer() { // const { fork } = require('child_process'); // const ps = fork(path.join(__dirname, '../', 'index.js')); require(path.join(__dirname, "../", "index.js")); - console.log("server running"); + // console.log("server running"); } function fileOverrides() { @@ -45,7 +45,7 @@ function createWindow() { // and load the index.html of the app. // TODO(jim): // We shouldn't hardcode this port. - mainWindow.loadURL("http://localhost:1337"); + mainWindow.loadURL("http://localhost:1337/application"); console.log("window created"); } From b8b5996536eb4972fb6607d45098122df1faed4f Mon Sep 17 00:00:00 2001 From: uonai Date: Sun, 2 Aug 2020 23:03:10 -0500 Subject: [PATCH 4/5] Code cleanup --- components/core/Application.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/components/core/Application.js b/components/core/Application.js index ea000ed8..35958119 100644 --- a/components/core/Application.js +++ b/components/core/Application.js @@ -74,12 +74,10 @@ export default class ApplicationPage extends React.Component { }; _handleSetFile = async ({ file, slate }) => { - // - console.log(file); this.setState({ fileLoading: true }); let data = new FormData(); - data.append("image", file); + data.append("data", file); console.log(data); const options = { From bdbe8e3b9979f049968ac1f3756f83b2564e0a5f Mon Sep 17 00:00:00 2001 From: uonai Date: Sun, 2 Aug 2020 23:04:39 -0500 Subject: [PATCH 5/5] Code cleanup --- components/core/Application.js | 1 - 1 file changed, 1 deletion(-) diff --git a/components/core/Application.js b/components/core/Application.js index 35958119..91dac596 100644 --- a/components/core/Application.js +++ b/components/core/Application.js @@ -78,7 +78,6 @@ export default class ApplicationPage extends React.Component { let data = new FormData(); data.append("data", file); - console.log(data); const options = { method: "POST",