From 54409d839bfd4c2ff54a3dbf7f66180872df6f3f Mon Sep 17 00:00:00 2001 From: Kananek Thongkam Date: Sun, 31 Mar 2024 14:10:27 +0700 Subject: [PATCH] refactor: code init for gokub app --- README.md | 2 +- docs/project.json | 4 +- electron-builder.json5 | 4 +- electron/main/event/anypoint/index.ts | 46 ------------------- electron/main/event/gocd/index.ts | 17 ------- electron/main/event/ipc-main.ts | 45 ++---------------- electron/main/index.ts | 30 ++++++------ index.html | 2 +- package.json | 16 +++---- src/App.vue | 16 +++---- src/components/HelloWorld.vue | 4 +- src/main.ts | 2 +- src/views/SetupPage.vue | 66 +++++++++++++-------------- tsconfig.json | 29 +++++++----- tsconfig.node.json | 6 +-- vite.config.ts | 2 +- 16 files changed, 98 insertions(+), 193 deletions(-) delete mode 100644 electron/main/event/anypoint/index.ts delete mode 100644 electron/main/event/gocd/index.ts diff --git a/README.md b/README.md index 1837fcc..ca152af 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# MuBu-App +# GOKub App 🥳 Really simple `Electron` + `Vue` + `Vite` boilerplate. diff --git a/docs/project.json b/docs/project.json index 619d8e0..e8dee09 100644 --- a/docs/project.json +++ b/docs/project.json @@ -1,8 +1,8 @@ { "id": "proj_fd96334478e24e3895ff3f4b918afa82", - "name": "mubu-app", + "name": "gokub-app", "remoteId": null, "workspaceIds": [ "wrk_5b13e316942f43c2a980a209a8b7276e" ] -} \ No newline at end of file +} diff --git a/electron-builder.json5 b/electron-builder.json5 index 58296e9..0fea96e 100644 --- a/electron-builder.json5 +++ b/electron-builder.json5 @@ -1,9 +1,9 @@ /** * @see https://www.electron.build/configuration/configuration */ -{ + { "$schema": "https://raw.githubusercontent.com/electron-userland/electron-builder/master/packages/app-builder-lib/scheme.json", - "appId": "com.scg-wedo.mubu-app", + "appId": "com.dvgamerr.app.gokub", "asar": true, "directories": { "output": "release/${version}" diff --git a/electron/main/event/anypoint/index.ts b/electron/main/event/anypoint/index.ts deleted file mode 100644 index 66162a7..0000000 --- a/electron/main/event/anypoint/index.ts +++ /dev/null @@ -1,46 +0,0 @@ -import { request } from 'gaxios' -import settings from 'electron-settings' -import dayjs from 'dayjs' -const validateStatus = () => true -const endpointAnypoint = 'https://anypoint.mulesoft.com' - -export interface OAuthData { - access_token: string - expires_in: number - token_type: string -} - -export const oAuth2 = async ():Promise => { - const anypoint = await settings.get('mubu-token.anypoint') - const { data, statusText }:{data: OAuthData, statusText:string } = await request({ - validateStatus, - method: 'POST', - url: `${endpointAnypoint}/accounts/api/v2/oauth2/token`, - headers: { 'Content-Type': 'application/json' }, - data: anypoint - }) - data.expires_in = +new Date()+(data.expires_in as number * 1000) - if (statusText === 'OK') await settings.set('mubu-token.anypoint.auth', data as any) - return data -} -export const getOAuth2 = async (): Promise => { - let auth: OAuthData = await settings.get('mubu-token.anypoint.auth') as any - if (dayjs().diff(dayjs(auth.expires_in), 'seconds') <= 0) { - return `${auth.token_type} ${auth.access_token}` - } - auth = await oAuth2() - return `${auth.token_type} ${auth.access_token}` -} - -export const getAccountMe = async (): Promise => { - const { data, statusText } = await request({ - validateStatus, - method: 'GET', - url: `${endpointAnypoint}/accounts/api/me`, - headers: { 'Content-Type': 'application/json', 'Authorization': await getOAuth2() }, - }) - - return (statusText === 'OK') ? data as object : null -} - - // /accounts/api/me diff --git a/electron/main/event/gocd/index.ts b/electron/main/event/gocd/index.ts deleted file mode 100644 index 4e650e6..0000000 --- a/electron/main/event/gocd/index.ts +++ /dev/null @@ -1,17 +0,0 @@ -import { request } from 'gaxios' -import settings from 'electron-settings' -const validateStatus = () => true - -export const getCurrentUser = async () => { - const gocd: any = await settings.get('mubu-token.gocd') - - const { data, statusText } = await request({ - validateStatus, - url: `${new URL(gocd.domain).origin}/go/api/current_user`, - headers: { - 'Accept': 'application/vnd.go.cd.v1+json', - 'Authorization': `bearer ${gocd.token}` - } - }) - return { data, statusText } -} diff --git a/electron/main/event/ipc-main.ts b/electron/main/event/ipc-main.ts index dca329f..2c50931 100644 --- a/electron/main/event/ipc-main.ts +++ b/electron/main/event/ipc-main.ts @@ -1,10 +1,7 @@ import { initilizeApp } from '../../user-config' -import settings from 'electron-settings' +// import settings from 'electron-settings' import log from 'electron-log/renderer' -import { getOAuth2, getAccountMe } from './anypoint' -import { getCurrentUser } from './gocd' - export interface AnypointToken { grant_type: String client_id: String @@ -21,41 +18,7 @@ export default { 'APP-OPEN-MENU': () => { log.log('backend') }, - 'MUBU-TOKEN-GET': () => settings.getSync('mubu-token') as any, - 'MUBU-TOKEN-VERIFY': async (e: Electron.IpcMainInvokeEvent, data: any) => { - const checkError = { anypoint: false, gocd: false } - const { anypoint, gocd } = JSON.parse(data) - - await settings.set('mubu-token', { - gocd, - anypoint: { - grant_type: 'client_credentials', - client_id: anypoint.clientId, - client_secret: anypoint.clientSecret - } - }) - - const token = await getAccountMe() - log.verbose({ 'anypoint-token': token }) - if (!token) { - await settings.unset('mubu-token') - checkError.anypoint = true - } - - if (gocd.token) { - const user = await getCurrentUser() - log.verbose({ 'gocd-user': user }) - - if (user.statusText !== 'OK') { - await settings.unset('mubu-token.gocd.domain') - await settings.unset('mubu-token.gocd.token') - checkError.gocd = true - } - } - - return checkError - }, - 'CHECK-GOCD_HEATH': async (e: Electron.IpcMainInvokeEvent, gocdDomain: string) => { + 'CHECK-GOCD_HEATH': async (_: Electron.IpcMainInvokeEvent, gocdDomain: string) => { try { const res = await fetch(`https://${(new URL(gocdDomain)).hostname}/go/api/v1/health`, { headers: { 'Content-Type': 'application/vnd.go.cd.v1+json; charset=utf-8' } @@ -66,7 +29,7 @@ export default { } }, 'MULESOFT-FETCH': async () => { - const oauth = await getAccountMe() - await settings.set('mulesoft.account', oauth as any) + // const oauth = await getAccountMe() + // await settings.set('mulesoft.account', oauth as any) } } diff --git a/electron/main/index.ts b/electron/main/index.ts index 451e20f..5e496f3 100644 --- a/electron/main/index.ts +++ b/electron/main/index.ts @@ -7,7 +7,7 @@ import { initilizeApp } from '../user-config' import settings from 'electron-settings' import { onWindowPositionEvent } from './event/settings' -import ipcEvent from './event/ipc-main' +// import ipcEvent from './event/ipc-main' log.initialize({ preload: true }) @@ -49,10 +49,10 @@ if (!app.requestSingleInstanceLock()) { // Read more on https://www.electronjs.org/docs/latest/tutorial/security // process.env['ELECTRON_DISABLE_SECURITY_WARNINGS'] = 'true' -let win: BrowserWindow | null = null +let win: BrowserWindow // Here, you can also use other preload const preload = join(__dirname, '../preload/index.js') -const url = process.env.VITE_DEV_SERVER_URL +const url = process.env.VITE_DEV_SERVER_URL || '' const indexHtml = join(process.env.DIST, 'index.html') async function createWindow() { @@ -116,19 +116,19 @@ async function createWindow() { win.on('maximize', onWindowPositionEvent(win)) win.on('moved', onWindowPositionEvent(win)) - ipcMain.handle('APP-RELOAD', async (e, ...args) => { + ipcMain.handle('APP-RELOAD', async () => { win.reload() }) - const ipcLog = log.scope('IPC'); - for (const eventName in ipcEvent) { - ipcMain.handle(eventName, async (e, ...args) => { - ipcLog.verbose(eventName, args) - const result = await ipcEvent[eventName](e, ...args) - ipcLog.verbose({ eventName, args, result }) - return result - }) - } + // const ipcLog = log.scope('IPC'); + // for (const eventName in ipcEvent) { + // ipcMain.handle(eventName, async (e, ...args) => { + // ipcLog.verbose(eventName, args) + // const result = await ipcEvent[eventName](e, ...args) + // ipcLog.verbose({ eventName, args, result }) + // return result + // }) + // } if (app.isPackaged) { win.loadFile(indexHtml) @@ -153,7 +153,7 @@ async function createWindow() { app.whenReady().then(createWindow) app.on('window-all-closed', () => { - win = null + win.close() if (process.platform !== 'darwin') app.quit() }) @@ -175,7 +175,7 @@ app.on('activate', () => { }) // new window example arg: new windows url -ipcMain.handle('open-win', (event, arg) => { +ipcMain.handle('open-win', (_, arg) => { const childWindow = new BrowserWindow({ webPreferences: { preload, diff --git a/index.html b/index.html index 57d0953..c373518 100644 --- a/index.html +++ b/index.html @@ -5,7 +5,7 @@ - MuBu App + GOKub App
diff --git a/package.json b/package.json index 3bae245..8ff623a 100644 --- a/package.json +++ b/package.json @@ -1,8 +1,8 @@ { - "name": "mubu-app", + "name": "gokub-app", "version": "0.1.0-beta", "main": "dist-electron/main/index.js", - "description": "a MuBu (mulesoft platfrom + gocd + anypointstudio package) bundle systems.", + "description": "A cryptocurrency cross platfrom app that uses bitkub.com.", "author": "Kananek T. ", "license": "MIT", "private": true, @@ -29,18 +29,18 @@ "@fortawesome/free-regular-svg-icons": "^6.4.2", "@fortawesome/free-solid-svg-icons": "^6.4.2", "@fortawesome/vue-fontawesome": "^3.0.3", - "@vitejs/plugin-vue": "^4.1.0", + "@vitejs/plugin-vue": "^5.0.4", "bootstrap": "^5.2.3", - "electron": "^25.4.0", + "electron": "^29.1.6", "electron-builder": "^24.4.0", "sass": "^1.64.2", - "typescript": "^5.1.6", - "vite": "^4.4.8", - "vite-plugin-electron": "^0.28.3", + "typescript": "^5.4.3", + "vite": "^5.2.7", + "vite-plugin-electron": "^0.28.4", "vite-plugin-electron-renderer": "^0.14.5", "vue": "^3.3.4", "vue-router": "^4.2.4", - "vue-tsc": "^1.8.8" + "vue-tsc": "^2.0.7" }, "dependencies": { "dayjs": "^1.11.7", diff --git a/src/App.vue b/src/App.vue index 7ac86a0..3d6235a 100644 --- a/src/App.vue +++ b/src/App.vue @@ -1,14 +1,14 @@