Skip to content

Commit

Permalink
refactor: code init for gokub app
Browse files Browse the repository at this point in the history
  • Loading branch information
dvgamerr committed Mar 31, 2024
1 parent 54cef6f commit 54409d8
Show file tree
Hide file tree
Showing 16 changed files with 98 additions and 193 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# MuBu-App
# GOKub App

🥳 Really simple `Electron` + `Vue` + `Vite` boilerplate.

Expand Down
4 changes: 2 additions & 2 deletions docs/project.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"id": "proj_fd96334478e24e3895ff3f4b918afa82",
"name": "mubu-app",
"name": "gokub-app",
"remoteId": null,
"workspaceIds": [
"wrk_5b13e316942f43c2a980a209a8b7276e"
]
}
}
4 changes: 2 additions & 2 deletions electron-builder.json5
Original file line number Diff line number Diff line change
@@ -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}"
Expand Down
46 changes: 0 additions & 46 deletions electron/main/event/anypoint/index.ts

This file was deleted.

17 changes: 0 additions & 17 deletions electron/main/event/gocd/index.ts

This file was deleted.

45 changes: 4 additions & 41 deletions electron/main/event/ipc-main.ts
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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' }
Expand All @@ -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)
}
}
30 changes: 15 additions & 15 deletions electron/main/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 })

Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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)
Expand All @@ -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()
})

Expand All @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<link rel="icon" type="image/svg+xml" href="/logo.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="Content-Security-Policy" content="script-src 'self' 'unsafe-inline';" />
<title>MuBu App</title>
<title>GOKub App</title>
</head>
<body>
<div id="app"></div>
Expand Down
16 changes: 8 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
@@ -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. <kananek.dev@touno.io>",
"license": "MIT",
"private": true,
Expand All @@ -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",
Expand Down
16 changes: 8 additions & 8 deletions src/App.vue
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
<script async setup lang="ts">
// import { ref } from 'vue'
import { useRouter } from 'vue-router'
import { ipcRenderer } from 'electron'
// import { useRouter } from 'vue-router'
// import { ipcRenderer } from 'electron'
// import { version } from '../package.json'
const router = useRouter()
// const router = useRouter()
ipcRenderer.invoke('MUBU-TOKEN-GET').then(foundClient => {
if (!foundClient) return router.replace('/setup')
})
// ipcRenderer.invoke('MUBU-TOKEN-GET').then(foundClient => {
// if (!foundClient) return router.replace('/setup')
// })
// import UIDropdownItem from './components/ui/DropdownItem.vue'
Expand All @@ -19,8 +19,8 @@ ipcRenderer.invoke('MUBU-TOKEN-GET').then(foundClient => {
<header class="title">
<div class="bar d-flex position-relative align-items-stretch px-2">
<div class="logo d-flex align-items-center flex-fill" style="column-gap: 0.4em; padding:0 .5em">
<img src="./assets/icon.png" height="20" width="20" alt="MuBu App" />
<span class="text">MuBu App</span>
<img src="./assets/icon.png" height="20" width="20" alt="GOKub App" />
<span class="text">GOKub App</span>
</div>
</div>
</header>
Expand Down
4 changes: 2 additions & 2 deletions src/components/HelloWorld.vue
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<script setup lang="ts">
import { ref } from 'vue'
// import { ref } from 'vue'
defineProps<{ msg: string }>()
const count = ref(0)
// const count = ref(0)
</script>

<template>
Expand Down
2 changes: 1 addition & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const initMsg = async (msg: string) => {
postMessage({ payload: 'init-msg', msg }, '*')
}

initMsg('Initialize MuBu')
initMsg('Initialize GOKub')
console.time('Initialize')
Promise.all([
ipcRenderer.invoke('INIT-CONFIG'),
Expand Down
Loading

0 comments on commit 54409d8

Please sign in to comment.