Skip to content

Commit

Permalink
feat: electron apps ipc communicaiton instead tcp/udp
Browse files Browse the repository at this point in the history
  • Loading branch information
darekf77 committed Apr 17, 2024
1 parent 59e86da commit 1b8454f
Show file tree
Hide file tree
Showing 17 changed files with 323 additions and 160 deletions.
12 changes: 6 additions & 6 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
{
"type": "node",
"request": "launch",
"name": "Launch Server standalone",
"name": "Debug/Start Server",
"program": "${workspaceFolder}/run.js",
"args": [
"port=4404",
"port=4504",
"--ENVoverride=%7B%0A%20%20%20%20%22clientProjectName%22%3A%20%22firedev%22%0A%7D "
],
"runtimeArgs": [
Expand All @@ -18,7 +18,7 @@
]
},
{
"name": "Start electron app debug",
"name": "Debug/Start Electron",
"type": "node",
"request": "launch",
"protocol": "inspector",
Expand Down Expand Up @@ -46,10 +46,10 @@
],
"compounds": [
{
"name": "Debug Server + Electron App",
"name": "Debug/Start (Server + Electron)",
"configurations": [
"Launch Server standalone",
"Start electron app debug"
"Debug/Start Server",
"Debug/Start Electron"
]
}
]
Expand Down
5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@
"background-worker-process": "~16.5.22",
"base32": "0.0.7",
"bcryptjs": "2.4.3",
"better-sqlite3": "7.6.2",
"better-sqlite3": "9.5.0",
"body-parser": "1.18.2",
"bootstrap": "4.6.2",
"buffer-shims": "1.0.0",
Expand Down Expand Up @@ -330,7 +330,6 @@
"ts-node": "10.9.1",
"tslint": "5.9.1",
"turndown": "7.1.2",
"typeorm": "~0.3.10",
"typescript": "~5.0.2",
"typescript-class-helpers": "~16.5.28",
"typescript-formatter": "~7.2.2",
Expand All @@ -352,4 +351,4 @@
"firedev-debug": "bin/firedev-debug",
"firedev-debug-brk": "bin/firedev-debug-brk"
}
}
}
2 changes: 2 additions & 0 deletions projects/container-v4/isomorphic-lib-v4/run-org.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
const process= require('process');
process.removeAllListeners('warning');
const util = require('util');
const vm = require('vm');
const path = require('path');
Expand Down
2 changes: 2 additions & 0 deletions projects/container-v4/isomorphic-lib-v4/run.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
const process= require('process');
process.removeAllListeners('warning');
const util = require('util');
const vm = require('vm');
const path = require('path');
Expand Down
10 changes: 4 additions & 6 deletions projects/container-v4/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,7 @@
"@types/q": "1.5.5",
"socket.io": "~2.4.1",
"axios": "~1.3.5",
"typeorm": "^0.3.10",
"better-sqlite3": "7.6.2",
"better-sqlite3": "9.5.0",
"sql.js": "^1.8.0",
"localforage": "~1.10.0",
"@ngrx/effects": "^16.0.1",
Expand Down Expand Up @@ -350,7 +349,7 @@
"background-worker-process": "16.5.22",
"base32": "0.0.7",
"bcryptjs": "2.4.3",
"better-sqlite3": "7.6.2",
"better-sqlite3": "9.5.0",
"body-parser": "1.18.2",
"bootstrap": "4.6.2",
"buffer-shims": "1.0.0",
Expand Down Expand Up @@ -394,6 +393,7 @@
"file-loader": "1.1.5",
"file-saver": "2.0.5",
"file-type": "18.5.0",
"firedev": "^16",
"firedev-crud": "16.5.66",
"firedev-crud-deamon": "16.5.20",
"firedev-ports": "16.5.22",
Expand Down Expand Up @@ -529,7 +529,6 @@
"tslib": "~2.3.0",
"tslint": "5.9.1",
"turndown": "7.1.2",
"typeorm": "0.3.10",
"typescript": "~5.0.2",
"typescript-class-helpers": "~16.5.28",
"typescript-formatter": "~7.2.2",
Expand All @@ -545,8 +544,7 @@
"webpack-dev-middleware": "~6.0.2",
"webpack-dev-server": "~4.13.2",
"yup": "1.1.1",
"zone.js": "~0.13.0",
"firedev": "^16"
"zone.js": "~0.13.0"
},
"devDependencies": {},
"license": "UNLICENSED",
Expand Down
4 changes: 2 additions & 2 deletions projects/container-v4/package.json_tnp.json5
Original file line number Diff line number Diff line change
Expand Up @@ -164,10 +164,10 @@

// ------- DATABASES ------------------------------------------
// outstanding crossplatform orm
typeorm: '^0.3.10',
// typeorm: '^0.3.10',

// amazing sqlite drive without node-gyp
'better-sqlite3': '7.6.2',
'better-sqlite3': '9.5.0',

// awesome sql in browser
// indexeddb just like localstorage
Expand Down
161 changes: 87 additions & 74 deletions src/app.electron.ts
Original file line number Diff line number Diff line change
@@ -1,97 +1,110 @@

import { CLIENT_DEV_NORMAL_APP_PORT, CLIENT_DEV_WEBSQL_APP_PORT } from './app.hosts';
import {
path,
//#region @backend
fse
//#endregion
} from 'tnp-core';
path,
//#region @backend
fse,
Helpers
//#endregion
} from 'tnp-core/src';
Helpers.hideNodeWarnings()
//#region @backend
import { app, BrowserWindow, screen } from 'electron';

import start from './app';
let win: BrowserWindow | null = null;
const args = process.argv.slice(1);
const serve = args.some(val => val === '--serve');
const websql = args.some(val => val === '--websql');

function createWindow(): BrowserWindow {

const size = screen.getPrimaryDisplay().workAreaSize;

// Create the browser window.
win = new BrowserWindow({
x: 0,
y: 0,
autoHideMenuBar: true,
width: size.width / 2,
height: size.height / 2,
webPreferences: {
nodeIntegration: true,
allowRunningInsecureContent: (serve),
contextIsolation: false,
},
});

if (serve) {
const debug = require('electron-debug');
debug();

require('electron-reloader')(module);
win.loadURL('http://localhost:' + (websql ? CLIENT_DEV_WEBSQL_APP_PORT : CLIENT_DEV_NORMAL_APP_PORT));
} else {
// Path when running electron executable
let pathIndex = './index.html';

if (fse.existsSync(path.join(__dirname, '../dist/index.html'))) {
// Path when running electron in local folder
pathIndex = '../dist/index.html';
}

const url = new URL(path.join('file:', __dirname, pathIndex));
win.loadURL(url.href);
}
const size = screen.getPrimaryDisplay().workAreaSize;

// Create the browser window.
win = new BrowserWindow({
x: 0,
y: 0,
autoHideMenuBar: true,
width: size.width,
height: size.height,
webPreferences: {
nodeIntegration: true,
allowRunningInsecureContent: (serve),
contextIsolation: false,
},
});

// Emitted when the window is closed.
win.on('closed', () => {
// Dereference the window object, usually you would store window
// in an array if your app supports multi windows, this is the time
// when you should delete the corresponding element.
win = null;
});
if (serve) {
const debug = require('electron-debug');
debug();

return win;
}
require('electron-reloader')(module);
win.webContents.openDevTools();
win.loadURL('http://localhost:' + (websql ? CLIENT_DEV_WEBSQL_APP_PORT : CLIENT_DEV_NORMAL_APP_PORT));
} else {
// Path when running electron executable
let pathIndex = './index.html';

async function startElectron() {
try {
// 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.
// Added 400 ms to fix the black background issue while using transparent window. More detais at https://github.com/electron/electron/issues/15947
app.on('ready', () => setTimeout(createWindow, 400));

// Quit when all windows are closed.
app.on('window-all-closed', () => {
// On OS X it is common for applications and their menu bar
// to stay active until the user quits explicitly with Cmd + Q
if (process.platform !== 'darwin') {
app.quit();
if (fse.existsSync(path.join(__dirname, '../dist/index.html'))) {
// Path when running electron in local folder
pathIndex = '../dist/index.html';
}
});

app.on('activate', () => {
// On OS X 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 (win === null) {
createWindow();
}
const url = new URL(path.join('file:', __dirname, pathIndex));
win.loadURL(url.href);
}

// Emitted when the window is closed.
win.on('closed', () => {
// Dereference the window object, usually you would store window
// in an array if your app supports multi windows, this is the time
// when you should delete the corresponding element.
win = null;
});

} catch (e) {
// Catch Error
// throw e;
return win;
}

async function startElectron() {
await start();

try {

// 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.
// Added 400 ms to fix the black background issue while using transparent window. More detais at https://github.com/electron/electron/issues/15947
setTimeout(createWindow, 400)
// app.removeAllListeners('ready')
// app.on('ready', () => {
// // createWindow()
// setTimeout(createWindow, 400)
// });

// Quit when all windows are closed.
app.on('window-all-closed', () => {
console.log('QUIT!')
// On OS X it is common for applications and their menu bar
// to stay active until the user quits explicitly with Cmd + Q
if (process.platform !== 'darwin') {
app.quit();
}
});

app.on('activate', () => {
// On OS X it's common to re-create a window in the app when the
// dock icon is clicked and there are no other windows open.
console.log('WIN ACTIVATED')
if (win === null) {
createWindow();
}
});

} catch (e) {
// Catch Error
throw e;
}
}

startElectron();
//#endregion
//#endregion
Loading

0 comments on commit 1b8454f

Please sign in to comment.