Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DRAFT] Homebrewery as an Electron App #3502

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion config/default.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
"web_port" : 8000,
"enable_v3" : true,
"enable_themes" : true,
"local_environments" : ["docker", "local"],
"local_environments" : ["docker", "local", "electron"],
"publicUrl" : "https://homebrewery.naturalcrit.com"
}
67 changes: 67 additions & 0 deletions electron-main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
// Modules to control application life and create native browser window
const { app, BrowserWindow } = require('electron');
const path = require('path');
// const express = require('express');
// const cors = require('cors');

process.env.NODE_ENV = 'electron';

const DB = require('./server/db.js');
const server = require('./server/app.js');
const config = require('./server/config.js');
let PORT;

const startLocalServer = (done)=>{
DB.connect(config).then(()=>{
// Ensure that we have successfully connected to the database
// before launching server
PORT = process.env.PORT || config.get('web_port') || 8000;
server.app.listen(PORT, ()=>{
console.log(`\n\tServer started at: ${new Date().toLocaleString()}`);
console.log(`\tENVIRONMENT: ${process.env.NODE_ENV}`);
console.log(`\tserver on port: http://localhost:${PORT}\n\n`);
done();
});
});
};

function createWindow() {
// Create the browser window.
const mainWindow = new BrowserWindow({
width : 800,
height : 600,
webPreferences : {
preload : path.join(__dirname, 'preload.js'),
},
});

// and load the index.html of the app.
// mainWindow.loadFile('index.html')
mainWindow.loadURL(`http://localhost:${PORT}`);

// Open the DevTools.
// mainWindow.webContents.openDevTools()
}

// This method will be called when Electron has finished
// initialization and is ready to create browser windows.
// Some APIs can only be used after this event occurs.
app.whenReady().then(()=>{
startLocalServer(createWindow);

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();
});
});

// 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 () {
if(process.platform !== 'darwin') app.quit();
});

// In this file you can include the rest of your app's specific main process
// code. You can also put them in separate files and require them here.
Loading