Skip to content

Commit

Permalink
Remove electron-store from platform worker
Browse files Browse the repository at this point in the history
  • Loading branch information
unknownskl committed Sep 25, 2024
1 parent 62bb56f commit cf4b6c1
Show file tree
Hide file tree
Showing 8 changed files with 105 additions and 52 deletions.
48 changes: 24 additions & 24 deletions app/main/background.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
import path from 'path'
import { app, ipcMain, dialog } from 'electron'
import serve from 'electron-serve'
import { createWindow } from './helpers'
import Platform from '@greenlight/platform'
import Logger from '@greenlight/logger'
import pkg from '../package.json'
import MainWindow from './windows/main'

export default class Application {

public isProduction: boolean = process.env.NODE_ENV === 'production'
public logger:Logger = new Logger('GreenlightApp')

private _platform?:Platform
public logger:Logger = new Logger('GreenlightApp')
private _mainWindow?:MainWindow

constructor() {
this.logger.log('constructor() Application booting... Greenlight App version', pkg.version)
Expand All @@ -31,7 +32,7 @@ export default class Application {
return new Promise((resolve, reject) => {
this._platform = new Platform()

this._platform.loadWorker('./app/worker.js').then((authenticated:boolean) => {
this._platform.loadWorker(path.join(__dirname, 'worker.js')).then((authenticated:boolean) => {
this.logger.log('loadPlatform() Platform loaded and authenticated')
dialog.showErrorBox('Worker success', 'Platform worker loaded!')
resolve(authenticated)
Expand All @@ -44,29 +45,28 @@ export default class Application {
}

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'),
},
})
// 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')

// 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
this._mainWindow = new MainWindow(this)
}
}

Expand Down
32 changes: 32 additions & 0 deletions app/main/windows/auth.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import path from 'path'
import Application from '../background'
import { createWindow } from '../helpers'

export default class AuthWindow {
private _app:Application
public window

constructor(app:Application) {
this._app = app

this.window = createWindow('main', {
width: 400,
height: 600,
title: 'Greenlight - Authentication',
backgroundColor: 'rgb(26, 27, 30)',
webPreferences: {
preload: path.join(__dirname, 'preload.js'),
},
})

// if (this._app.isProduction) {
// this.window.loadURL('app://./boot')
// } else {
// const port = process.argv[2]
// this.window.loadURL(`http://localhost:${port}/boot`)
// this.window.webContents.openDevTools({
// mode: 'bottom'
// })
// }
}
}
6 changes: 6 additions & 0 deletions app/main/windows/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import MainWindow from './main'
import AuthWindow from './auth'

export default {
MainWindow
}
32 changes: 32 additions & 0 deletions app/main/windows/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import path from 'path'
import Application from '../background'
import { createWindow } from '../helpers'

export default class MainWindow {
private _app:Application
public window

constructor(app:Application) {
this._app = app

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

if (this._app.isProduction) {
this.window.loadURL('app://./boot')
} else {
const port = process.argv[2]
this.window.loadURL(`http://localhost:${port}/boot`)
this.window.webContents.openDevTools({
mode: 'bottom'
})
}
}
}
2 changes: 0 additions & 2 deletions packages/authentication/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
"version": "1.0.0",
"dependencies": {
"@greenlight/logger": "^1.0.0",
"electron-store": "^8.0.1",
"electron": "32.1.2",
"xal-node": "^1.0.2"
},
"license": "MIT",
Expand Down
18 changes: 9 additions & 9 deletions packages/authentication/src/authstore.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { TokenStore } from 'xal-node'
import Store from 'electron-store'
import { app } from 'electron'
// import Store from 'electron-store'
// import { app } from 'electron'
import fs from 'fs'

export default class AuthStore extends TokenStore {

private _store = new Store({ cwd: getAppBasePath() });
// private _store = new Store({ cwd: getAppBasePath() });

load() {
const tokens = this._store.get('authentication.tokens', '{}') as string
this.loadJson(tokens)
// const tokens = this._store.get('authentication.tokens', '{}') as string
// this.loadJson(tokens)

return true
}
Expand All @@ -21,11 +21,11 @@ export default class AuthStore extends TokenStore {
jwtKeys: this._jwtKeys,
})

this._store.set('authentication.tokens', tokens)
// this._store.set('authentication.tokens', tokens)
}

clear() {
this._store.delete('authentication.tokens')
// this._store.delete('authentication.tokens')
this._userToken = undefined
this._sisuToken = undefined
this._jwtKeys = undefined
Expand All @@ -41,8 +41,8 @@ const getAppBasePath = () => {
if(process.env.NODE_ENV === 'production')
ElectronAppName = '@greenlight/app'

if(app !== undefined && app.getPath !== undefined)
return app.getPath('userData')
// if(app !== undefined && app.getPath !== undefined)
// return app.getPath('userData')

// if (!process.platform || !['win32', 'darwin'].includes(process.platform)) {
// // console.log(`Unsupported OS: ${process.platform}`)
Expand Down
8 changes: 1 addition & 7 deletions packages/authentication/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,5 @@
"outDir": "./dist",
"rootDir": "./src"
},
"include": ["src"],
"electron": {
"esm": true
},
"electron-store": {
"esm": true
}
"include": ["src"]
}
11 changes: 1 addition & 10 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2857,7 +2857,7 @@ electron-serve@^1.3.0:
resolved "https://registry.yarnpkg.com/electron-serve/-/electron-serve-1.3.0.tgz#94f7fbdc398d1f187f0ebeb4630b2d03acb83d59"
integrity sha512-OEC/48ZBJxR6XNSZtCl4cKPyQ1lvsu8yp8GdCplMWwGS1eEyMcEmzML5BRs/io/RLDnpgyf+7rSL+X6ICifRIg==

electron-store@^8.0.1, electron-store@^8.2.0:
electron-store@^8.2.0:
version "8.2.0"
resolved "https://registry.yarnpkg.com/electron-store/-/electron-store-8.2.0.tgz#114e6e453e8bb746ab4ccb542424d8c881ad2ca1"
integrity sha512-ukLL5Bevdil6oieAOXz3CMy+OgaItMiVBg701MNlG6W5RaC0AHN7rvlqTCmeb6O7jP0Qa1KKYTE0xV0xbhF4Hw==
Expand All @@ -2879,15 +2879,6 @@ [email protected]:
"@types/node" "^20.9.0"
extract-zip "^2.0.1"

[email protected]:
version "32.1.2"
resolved "https://registry.yarnpkg.com/electron/-/electron-32.1.2.tgz#84d1efd95d41224e58a6a9bbd1db4ba80154fc02"
integrity sha512-CXe6doFzhmh1U7daOvUzmF6Cj8hssdYWMeEPRnRO6rB9/bbwMlWctcQ7P8NJXhLQ88/vYUJQrJvlJPh8qM0BRQ==
dependencies:
"@electron/get" "^2.0.0"
"@types/node" "^20.9.0"
extract-zip "^2.0.1"

emoji-regex@^8.0.0:
version "8.0.0"
resolved "https://registry.yarnpkg.com/emoji-regex/-/emoji-regex-8.0.0.tgz#e818fd69ce5ccfcb404594f842963bf53164cc37"
Expand Down

0 comments on commit cf4b6c1

Please sign in to comment.