add desktop and read bnb balance from user seed
This commit is contained in:
@@ -0,0 +1,111 @@
|
||||
import {
|
||||
ApplicationMenu,
|
||||
BrowserView,
|
||||
BrowserWindow,
|
||||
Updater,
|
||||
defineElectrobunRPC,
|
||||
type RPCSchema,
|
||||
} from 'electrobun/bun'
|
||||
|
||||
const DEV_SERVER_PORT = 5173
|
||||
const DEV_SERVER_URL = `http://localhost:${DEV_SERVER_PORT}`
|
||||
|
||||
async function getMainViewUrl(): Promise<string> {
|
||||
const channel = await Updater.localInfo.channel()
|
||||
if (channel === 'dev') {
|
||||
try {
|
||||
await fetch(DEV_SERVER_URL, { method: 'HEAD' })
|
||||
console.log(
|
||||
`HMR enabled: Using Vite dev server at ${DEV_SERVER_URL}`,
|
||||
)
|
||||
return DEV_SERVER_URL
|
||||
} catch {
|
||||
console.log(
|
||||
"Vite dev server not running. Run 'bun run dev:hmr' for HMR support.",
|
||||
)
|
||||
}
|
||||
}
|
||||
return 'views://mainview/index.html'
|
||||
}
|
||||
|
||||
ApplicationMenu.setApplicationMenu([
|
||||
{
|
||||
label: 'File',
|
||||
submenu: [{ role: 'quit' }],
|
||||
},
|
||||
{
|
||||
label: 'Edit',
|
||||
submenu: [
|
||||
{ role: 'undo' },
|
||||
{ role: 'redo' },
|
||||
{ type: 'divider' },
|
||||
{ role: 'cut' },
|
||||
{ role: 'copy' },
|
||||
{ role: 'paste' },
|
||||
{ role: 'delete' },
|
||||
{ type: 'divider' },
|
||||
{ role: 'selectAll' },
|
||||
],
|
||||
},
|
||||
{
|
||||
label: 'Window',
|
||||
submenu: [{ role: 'minimize' }, { role: 'zoom' }],
|
||||
},
|
||||
])
|
||||
|
||||
const url = await getMainViewUrl()
|
||||
|
||||
type RPC = {
|
||||
bun: RPCSchema<{
|
||||
requests: {
|
||||
getSecret: {
|
||||
params: {
|
||||
service: string
|
||||
name: string
|
||||
}
|
||||
response: Promise<string | null>
|
||||
}
|
||||
setSecret: {
|
||||
params: {
|
||||
service: string
|
||||
name: string
|
||||
value: string
|
||||
}
|
||||
response: Promise<void>
|
||||
}
|
||||
}
|
||||
messages: {}
|
||||
}>
|
||||
webview: RPCSchema<{
|
||||
requests: {}
|
||||
messages: {}
|
||||
}>
|
||||
}
|
||||
const rpc = BrowserView.defineRPC<RPC>({
|
||||
maxRequestTime: 10000,
|
||||
handlers: {
|
||||
requests: {
|
||||
getSecret: async ({ name, service }) => {
|
||||
return await Bun.secrets.get({ name, service })
|
||||
},
|
||||
setSecret: async ({ name, service, value }) => {
|
||||
await Bun.secrets.set({ name, service, value })
|
||||
},
|
||||
},
|
||||
messages: {},
|
||||
},
|
||||
})
|
||||
|
||||
const win = new BrowserWindow({
|
||||
title: 'Koins',
|
||||
url,
|
||||
rpc,
|
||||
frame: {
|
||||
width: 900,
|
||||
height: 700,
|
||||
x: 200,
|
||||
y: 200,
|
||||
},
|
||||
})
|
||||
|
||||
console.log('Svelte app started!')
|
||||
Reference in New Issue
Block a user