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 9e444f8 commit 321cc00
Show file tree
Hide file tree
Showing 11 changed files with 88 additions and 51 deletions.
10 changes: 5 additions & 5 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
{
"type": "node",
"request": "launch",
"name": "Launch Server standalone",
"name": "Debug/Start Server",
"program": "${workspaceFolder}/run.js",
"args": [
"port=4504",
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
6 changes: 2 additions & 4 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 @@ -530,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 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
21 changes: 15 additions & 6 deletions src/app.electron.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ 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;
Expand All @@ -26,21 +25,22 @@ function createWindow(): BrowserWindow {
x: 0,
y: 0,
autoHideMenuBar: true,
width: size.width / 1.5,
height: size.height / 1.5,
width: size.width,
height: size.height,
webPreferences: {
nodeIntegration: true,
allowRunningInsecureContent: (serve),
contextIsolation: false,
},
});
win.webContents.openDevTools();

console.log('serve wind')
if (serve) {
const debug = require('electron-debug');
debug();

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
Expand Down Expand Up @@ -68,15 +68,23 @@ function createWindow(): BrowserWindow {

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
app.on('ready', () => setTimeout(createWindow, 400));
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') {
Expand All @@ -87,14 +95,15 @@ async function startElectron() {
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;
throw e;
}
}

Expand Down
17 changes: 14 additions & 3 deletions src/app.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Firedev } from 'firedev';
import { EMPTY, Observable, catchError, map, of, startWith } from 'rxjs';
import { Helpers } from 'tnp-core/src';
import { Helpers, _ } from 'tnp-core/src';
//#region @notForNpm
import { HOST_BACKEND_PORT } from './app.hosts';
//#region @browser
Expand Down Expand Up @@ -41,25 +41,34 @@ export class FiredevModule { }

@Firedev.Entity({ className: 'User' })
class User extends Firedev.Base.Entity {
static from(user: Partial<User>) {
return _.merge(new User(), user);
}
public static ctrl?: UserController;
//#region @websql
@Firedev.Orm.Column.Generated()
//#endregion
id?: string | number;

//#region @websql
@Firedev.Orm.Column.Custom({ type: 'varchar', length: 100 })
//#endregion
name?: string;
}

@Firedev.Controller({ className: 'UserController', entity: User })
class UserController extends Firedev.Base.Controller<User> {

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

async function start() {
async function start(portForBackend?: string) {
console.log({ portForBackend })
console.log('hello world');
console.log('Helpers.isElectron', Helpers.isElectron)
console.log('Your server will start on port ' + HOST_BACKEND_PORT);
Expand All @@ -84,6 +93,8 @@ async function start() {
//#endregion
});

console.log('APP INITED')

if (Firedev.isBrowser) {
// const users = (await User.ctrl.getAll().received).body.json;
// console.log({
Expand Down
60 changes: 38 additions & 22 deletions src/lib/framework/framework-start.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,27 @@ export function start(options: Omit<StartOptions,

delete config.database;
}

// @ts-ignore
// console.log('INITING LOCATION WEBSQL DB ' + config?.location)
//#endregion

if (Helpers.isElectron) {
//#region @backend
// @ts-ignore
config.type = 'sqljs';
// @ts-ignore
config.autoSave = true;
// config['useLocalForage'] = !!window['localforage']

// @ts-ignore
config.location = (config.database || '').replace('.sqlite', '');

// delete config.database;
//#endregion
}


// config['useLocalForage'] = false; // TODO REMOVE
// console.log('USING LOCAL FORAGE', config['useLocalForage'])

Expand Down Expand Up @@ -146,30 +163,29 @@ export function start(options: Omit<StartOptions,
context.initBrowser();
// console.log('browser init done')

if (Helpers.isBrowser) {
if (Helpers.isBrowser && !Helpers.isElectron) {
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);
// }

// `, true, true)
// }
// @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)
}
});

}

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

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

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

// @ts-ignore;
Expand Down

0 comments on commit 321cc00

Please sign in to comment.