Skip to content

Commit

Permalink
$$$ update $$$
Browse files Browse the repository at this point in the history
  • Loading branch information
darekf77 committed Apr 17, 2024
1 parent 59e86da commit 9e444f8
Show file tree
Hide file tree
Showing 7 changed files with 118 additions and 102 deletions.
2 changes: 1 addition & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"name": "Launch Server standalone",
"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 Down
4 changes: 2 additions & 2 deletions projects/container-v4/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,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 @@ -545,8 +546,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
149 changes: 77 additions & 72 deletions src/app.electron.ts
Original file line number Diff line number Diff line change
@@ -1,97 +1,102 @@

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');

console.log('Helpers.isElectron', Helpers.isElectron)
function createWindow(): BrowserWindow {

const size = screen.getPrimaryDisplay().workAreaSize;
const size = screen.getPrimaryDisplay().workAreaSize;

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

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

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';

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';
}

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

return win;
return win;
}

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

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

} catch (e) {
// Catch Error
// throw e;
}
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
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();
}
});

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

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

startElectron();
//#endregion
//#endregion
21 changes: 13 additions & 8 deletions src/app.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import { Firedev } from 'firedev';
import { Observable, map } from 'rxjs';
import { EMPTY, Observable, catchError, map, of, startWith } from 'rxjs';
import { Helpers } from 'tnp-core/src';
//#region @notForNpm
import { HOST_BACKEND_PORT } from './app.hosts';
//#region @browser
import { NgModule } from '@angular/core';
import { Component, OnInit } from '@angular/core';
import { CommonModule } from '@angular/common';


@Component({
selector: 'app-firedev',
template: `hello from firedev<br>
Expand All @@ -20,7 +22,9 @@ import { CommonModule } from '@angular/common';
})
export class FiredevComponent implements OnInit {
users$: Observable<User[]> = User.ctrl.getAll().received.observable
.pipe(map(data => data.body.json));
.pipe(
map(data => data.body.json),
);

constructor() { }
ngOnInit() { }
Expand Down Expand Up @@ -50,14 +54,15 @@ class UserController extends Firedev.Base.Controller<User> {

//#region @websql
async initExampleDbData(): Promise<void> {
await this.repository.save(new User())
// await this.repository.save(new User())
}
//#endregion
}

async function start() {
console.log('hello world');
console.log('Your server will start on port '+ HOST_BACKEND_PORT);
console.log('Helpers.isElectron', Helpers.isElectron)
console.log('Your server will start on port ' + HOST_BACKEND_PORT);
const host = 'http://localhost:' + HOST_BACKEND_PORT;

const context = await Firedev.init({
Expand All @@ -80,10 +85,10 @@ async function start() {
});

if (Firedev.isBrowser) {
const users = (await User.ctrl.getAll().received).body.json;
console.log({
'users from backend': users
})
// const users = (await User.ctrl.getAll().received).body.json;
// console.log({
// 'users from backend': users
// })
}
}

Expand Down
38 changes: 19 additions & 19 deletions src/lib/framework/framework-start.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,26 +148,26 @@ export function start(options: Omit<StartOptions,

if (Helpers.isBrowser) {
setTimeout(() => {
// @ts-ignore
let angularVer = _.first(getAllAngularRootElements()[0].attributes['ng-version']?.value?.split('.'));
// console.log('Angular version: ' + angularVer)
const verNum = Number(angularVer);

if (!isNaN(verNum) && !FrameworkContext.isNgZoneInited) {
Helpers.error(`
[Firedev] Angular ${verNum} version detected...
[Firedev] NgZone instance is not inited... please use:
constructor(
...
ngzone:NgZone
...
) {
Firedev.initNgZone(ngzone);
}
// // @ts-ignore
// let angularVer = _.first(getAllAngularRootElements()[0].attributes['ng-version']?.value?.split('.'));
// // console.log('Angular version: ' + angularVer)
// const verNum = Number(angularVer);

// if (!isNaN(verNum) && !FrameworkContext.isNgZoneInited) {
// Helpers.error(`
// [Firedev] Angular ${verNum} version detected...
// [Firedev] NgZone instance is not inited... please use:

// constructor(
// ...
// ngzone:NgZone
// ...
// ) {
// Firedev.initNgZone(ngzone);
// }

`, true, true)
}
// `, true, true)
// }
});

}
Expand Down
3 changes: 3 additions & 0 deletions src/lib/realtime/realtime-browser-rxjs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ export class RealtimeBrowserRxjs {
constructor(private context: FrameworkContext) {

const base = RealtimeBase.by(context);
if (Helpers.isElectron) {
return;
}
// Helpers.log('INITING SOCKETS')
if (!context.disabledRealtime) {

Expand Down
3 changes: 3 additions & 0 deletions src/lib/realtime/realtime-nodejs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ export class RealtimeNodejs {
constructor(private context: FrameworkContext) {
//#region @websql
const base = RealtimeBase.by(context);
if (Helpers.isElectron) {
return;
}
if (!context.disabledRealtime) {

// @ts-ignore;
Expand Down

0 comments on commit 9e444f8

Please sign in to comment.