init studio launcher frontend
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
import { contextBridge, ipcRenderer } from 'electron'
|
||||
import { electronAPI } from '@electron-toolkit/preload'
|
||||
|
||||
const argv = process.argv
|
||||
const isAppWindow = argv.includes('--app-window')
|
||||
const appName = decodeURIComponent(
|
||||
argv.find((a) => a.startsWith('--app-name='))?.slice('--app-name='.length) ?? ''
|
||||
)
|
||||
const appUrl = decodeURIComponent(
|
||||
argv.find((a) => a.startsWith('--app-url='))?.slice('--app-url='.length) ?? ''
|
||||
)
|
||||
|
||||
const appWindowMeta = { isAppWindow, appName, url: appUrl }
|
||||
const launcherTailscale = {
|
||||
status: () => ipcRenderer.invoke('launcher-tailscale-status'),
|
||||
login: (authKey: string, loginServer: string, hostname?: string, forceReset?: boolean) =>
|
||||
ipcRenderer.invoke('launcher-tailscale-login', authKey, loginServer, hostname, forceReset),
|
||||
logout: () => ipcRenderer.invoke('launcher-tailscale-logout'),
|
||||
}
|
||||
const launcherSshKey = {
|
||||
ensure: () => ipcRenderer.invoke('launcher-ssh-key-ensure'),
|
||||
}
|
||||
|
||||
if (process.contextIsolated) {
|
||||
try {
|
||||
contextBridge.exposeInMainWorld('electron', electronAPI)
|
||||
contextBridge.exposeInMainWorld('appWindowMeta', appWindowMeta)
|
||||
contextBridge.exposeInMainWorld('launcherTailscale', launcherTailscale)
|
||||
contextBridge.exposeInMainWorld('launcherSshKey', launcherSshKey)
|
||||
} catch (error) {
|
||||
console.error(error)
|
||||
}
|
||||
} else {
|
||||
// @ts-ignore
|
||||
window.electron = electronAPI
|
||||
// @ts-ignore
|
||||
window.appWindowMeta = appWindowMeta
|
||||
// @ts-ignore
|
||||
window.launcherTailscale = launcherTailscale
|
||||
// @ts-ignore
|
||||
window.launcherSshKey = launcherSshKey
|
||||
}
|
||||
Reference in New Issue
Block a user