Skip to content

Commit

Permalink
Done all kinds of things.. Debugging for a couple hours mostly
Browse files Browse the repository at this point in the history
  • Loading branch information
unknownskl committed Sep 25, 2024
1 parent 3251779 commit f2e0a7d
Show file tree
Hide file tree
Showing 22 changed files with 253 additions and 149 deletions.
12 changes: 12 additions & 0 deletions app/.babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"presets": [
["next/babel", {
"preset-env": {
"targets": {
"node": "current" // Ensures Babel is targeting the correct Node.js version for Electron
}
}
}]
]
}

40 changes: 0 additions & 40 deletions app/main/background.ts

This file was deleted.

82 changes: 82 additions & 0 deletions app/main/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
import path from 'path'
import { app, ipcMain } from 'electron'
import serve from 'electron-serve'
import { createWindow } from './helpers'
import Platform from '@greenlight/platform'
import Logger from '@greenlight/logger'
// const Platform = require('@greenlight/platform')
const Logger2 = require('@greenlight/logger')
import pkg from '../package.json'

console.log('Fucking logger kanker shit:', Logger, Logger2.default)

// export default class Application {

// public isProduction: boolean = process.env.NODE_ENV === 'production'

// private _platform:Platform
// public logger:Logger = new Logger('GreenlightApp')

// constructor() {
// this.logger.log('constructor() Application booting... Greenlight App version', pkg.version)

// if(this.isProduction === true){
// serve({ directory: 'app' })
// } else {
// app.setPath('userData', `${app.getPath('userData')} (development)`)
// }
// }

// async isReady() {
// await app.whenReady()
// }

// loadPlatform(){
// return new Promise((resolve, reject) => {
// // const Platform = require('@greenlight/platform');
// this._platform = new Platform()

// this._platform.loadWorker('./app/worker.js').then((authenticated:boolean) => {
// this.logger.log('loadPlatform() Platform loaded and authenticated')
// resolve(authenticated)
// }).catch((error:any) => {
// this.logger.error('loadPlatform() Platform failed to load. Critical error: '+error)
// reject(error)
// })
// })
// }

// async spawnMainWindow() {
// const mainWindow = createWindow('main', {
// width: 1280,
// height: (this.isProduction) ? 800 : 1200,
// title: 'Greenlight',
// backgroundColor: 'rgb(26, 27, 30)',
// webPreferences: {
// preload: path.join(__dirname, 'preload.js'),
// },
// })

// if (this.isProduction) {
// await mainWindow.loadURL('app://./boot')
// } else {
// const port = process.argv[2]
// await mainWindow.loadURL(`http://localhost:${port}/boot`)
// mainWindow.webContents.openDevTools({
// mode: 'bottom'
// })
// }
// this.logger.log('spawnMainWindow() Main application windows drawn')


// return mainWindow
// }
// }

// const main = new Application()
// ;(async () => {
// await main.isReady()

// await main.spawnMainWindow()
// await main.loadPlatform()
// })()
27 changes: 27 additions & 0 deletions app/main/worker.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import worker from 'node:worker_threads'
import GreenlightWorker from '@greenlight/platform/src/worker'
import Logger from '@greenlight/logger'

export default class Worker {
private _platformWorker:GreenlightWorker
public logger = new Logger('GreenlightWorker:main')

constructor() {
worker.parentPort?.once('message', (handler) => {
try {
this._platformWorker = new GreenlightWorker(this.logger, handler.port)
this._platformWorker.once('ready', (result) => {
if(result === true)
worker.parentPort?.postMessage('ok');
else
worker.parentPort?.postMessage('unauthenticated');
})
} catch (error) {
worker.parentPort?.postMessage('error');
}
})
}
}

new Worker()

14 changes: 14 additions & 0 deletions app/nextron.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
const path = require('path')

module.exports = {
webpack: (config, env) => {
config.entry.background = './main/main.ts'
config.entry.worker = './main/worker.ts'
config.entry.preload = './main/preload.ts'
config.module.rules.push({
test: /\.node$/,
loader: "node-loader",
})
return config;
},
};
8 changes: 6 additions & 2 deletions app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,27 @@
"url": "git+https://github.com/unknownskl/greenlight.git"
},
"scripts": {
"dev": "nextron",
"dev": "yarn build:deps && DEBUG_GREENLIGHT='*' nextron",
"build": "nextron build",
"build:deps": "yarn workspace @greenlight/logger build && yarn workspace @greenlight/authentication build",
"flatpak-build": "nextron build --no-pack && electron-builder --dir",
"postinstall:disabled": "DEBUG='electron-builder' electron-builder install-app-deps"
"postinstall": "electron-builder install-app-deps"
},
"dependencies": {
"electron-serve": "^1.3.0",
"electron-store": "^8.2.0"
},
"devDependencies": {
"@greenlight/logger": "^1.0.0",
"@greenlight/platform": "^1.0.0",
"@types/node": "^20.11.16",
"@types/react": "^18.2.52",
"autoprefixer": "^10.4.19",
"electron": "31.6.0",
"electron-builder": "^24.13.3",
"next": "^14.2.4",
"nextron": "^9.1.0",
"node-loader": "^2.0.0",
"postcss": "^8.4.38",
"react": "^18.3.1",
"react-dom": "^18.3.1",
Expand Down
17 changes: 17 additions & 0 deletions app/renderer/pages/boot.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import React from 'react'
import Head from 'next/head'
import Link from 'next/link'
import Image from 'next/image'

export default function BootPage() {
return (
<React.Fragment>
<Head>
<title>Greenlight - Loading...</title>
</Head>
<div className="grid grid-col-1 text-2xl w-full text-center">
Loading...
</div>
</React.Fragment>
)
}
2 changes: 1 addition & 1 deletion app/renderer/postcss.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ module.exports = {
},
autoprefixer: {},
},
}
}
3 changes: 2 additions & 1 deletion app/renderer/styles/globals.css
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@

@layer base {
body {
@apply bg-gray-900 text-white;
@apply text-white;
background: rgb(26, 27, 30)
}
}

Expand Down
14 changes: 12 additions & 2 deletions app/renderer/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
{
"extends": "../tsconfig.json",
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx"],
"exclude": ["node_modules"]
"include": [
"next-env.d.ts",
"**/*.ts",
"**/*.tsx"
],
"exclude": [
"node_modules"
],
"compilerOptions": {
"noEmit": true,
"incremental": true
}
}
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"xcloudapi": "yarn workspace @greenlight/xcloudapi",
"webapi": "yarn workspace @greenlight/webapi",
"platform": "yarn workspace @greenlight/platform",
"build:deps": "yarn workspace @greenlight/logger build && yarn workspace @greenlight/authentication build && yarn workspace @greenlight/xcloudapi build && yarn workspace @greenlight/storeapi build && yarn workspace @greenlight/webapi build && yarn workspace @greenlight/platform build",
"test": "yarn logger test && yarn authentication test && yarn xcloudapi test && yarn storeapi test && yarn webapi test && yarn platform test"
},
"workspaces": [
Expand Down
2 changes: 1 addition & 1 deletion packages/authentication/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"compilerOptions": {
/* Basic Options */
"target": "es6",
"target": "esnext",
"module": "commonjs",
"strict": true,
"esModuleInterop": true,
Expand Down
1 change: 0 additions & 1 deletion packages/logger/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
"name": "@greenlight/logger",
"version": "1.0.0",
"dependencies": {
"debug": "^4.3.4",
"ts-node": "^10.9.2"
},
"license": "MIT",
Expand Down
4 changes: 2 additions & 2 deletions packages/logger/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import Debug from 'debug'
import Sink, { SinkData } from './sink'

export default class Logger {
Expand All @@ -12,7 +11,8 @@ export default class Logger {
this._sink = new Sink(name)
this.name = name

const debugArgs = process.env.DEBUG?.split(',')
const debugSelector = (process.env.DEBUG_GREENLIGHT !== undefined) ? process.env.DEBUG_GREENLIGHT : process.env.DEBUG
const debugArgs = debugSelector?.split(',')
if(debugArgs !== undefined && (debugArgs.includes(this.name) || debugArgs.includes('*'))) {
this._enableStdout = true
}
Expand Down
11 changes: 6 additions & 5 deletions packages/platform/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@ export default class GreenlightPlatform {
this.logger.log('constructor() Creating new GreenlightPlatform instance')
}

loadWorker() {
loadWorker(file = __filename) {
return new Promise((resolve, reject) => {
if(! worker.isMainThread)
throw new Error('Cannot load worker in worker thread, need to be loaded in the main thread.')

this._worker = new worker.Worker(__filename);
this._worker = new worker.Worker(file);
this._worker.once('message', (msg:'ok'|'unauthenticated'|'error') => {
(msg !== 'error') ? resolve(msg === 'ok' ? true : false) : reject(false)
(['ok', 'unauthenticated'].includes(msg)) ? resolve(msg === 'ok' ? true : false) : reject(msg)

this._worker.on('message', (msg:string) => {
this.logger.error('Worker message:', msg)
Expand Down Expand Up @@ -60,15 +60,16 @@ export default class GreenlightPlatform {

worker.parentPort?.once('message', (handler) => {
try {
this._platformWorker = new PlatformWorker(this, handler.port)
this._platformWorker = new PlatformWorker(this.logger, handler.port)
this._platformWorker.once('ready', (result) => {
if(result === true)
worker.parentPort?.postMessage('ok');
else
worker.parentPort?.postMessage('unauthenticated');
})
} catch (error) {
worker.parentPort?.postMessage('error');
this.logger.error('startWorker() Error starting worker:', error)
worker.parentPort?.postMessage(error);
}
})
}
Expand Down
6 changes: 2 additions & 4 deletions packages/platform/src/worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,18 @@ interface Modules {
export default class Worker extends EventEmitter {

private _channel:MessagePort
private _platform:GreenlightPlatform

public logger:Logger

public controllers:Modules = {
Authentication: new Authentication()
}

constructor(platform:GreenlightPlatform, port:MessagePort) {
constructor(logger:Logger, port:MessagePort) {
super()

this._channel = port
this._platform = platform
this.logger = this._platform.logger.extend('thread-'+process.pid)
this.logger = logger.extend('thread-'+process.pid)

this._channel.on('message', async (event) => await this.message(event))

Expand Down
2 changes: 0 additions & 2 deletions packages/storeapi/src/bin/example.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@ class Cli {
this._store?.getTitleId('9NZC09NNR93L').then((item) => {
// this._store?.getTitleId('9PKW4GMX4J8K').then((item) => {
console.log('Item:', item)
const product = this._store?.parseTitle(item)
console.log('Parsed:', product)
}).catch((error) => {
this.logger.error('Failed to find title id:', error)
})
Expand Down
Loading

0 comments on commit f2e0a7d

Please sign in to comment.