Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: splashscreen #175

Merged
merged 9 commits into from
Sep 25, 2024
1 change: 1 addition & 0 deletions forge.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const config: ForgeConfig = {
'./resources/json_output.py',
'./resources/group_snippet.js',
'./resources/checks_snippet.js',
'./resources/splashscreen.html',
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the splashscreen is a simple html file so that we don't need to wait any kind of react loading to show it. It has to be quick and visible and simple~

'./resources/' + getPlatform() + '/' + getArch(),
],
osxSign: {
Expand Down
11 changes: 11 additions & 0 deletions resources/splashscreen.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!doctype html>
<html>
<head>
<meta charset="UTF-8" />
<meta http-equiv="Content-Security-Policy" content="script-src 'self'" />
<title>k6 Studio (experimental)</title>
</head>
<body>
I AM SPLASHING
</body>
</html>
5 changes: 5 additions & 0 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ import { queryClient } from './utils/query'
export function App() {
const theme = useTheme()

setTimeout(() => {
console.log('REPLACE ME')
window.studio.app.closeSplashscreen()
}, 1000)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to be replaced: example of how to close the splashscreen and show the app


return (
<QueryClientProvider client={queryClient}>
<Theme accentColor="orange" appearance={theme}>
Expand Down
45 changes: 38 additions & 7 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,39 @@ export let proxyPort = 6000
let currentBrowserProcess: Process | null
let currentk6Process: K6Process | null
let watcher: FSWatcher
let splashscreenWindow: BrowserWindow

// Handle creating/removing shortcuts on Windows when installing/uninstalling.
if (require('electron-squirrel-startup')) {
app.quit()
}

const createSplashWindow = async () => {
splashscreenWindow = new BrowserWindow({
width: 500,
height: 300,
// transparent: true,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if we want the window transparent , will depend on the splashscreen we use

frame: false,
alwaysOnTop: true,
})

let splashscreenFile: string

// if we are in dev server we take resources directly, otherwise look in the app resources folder.
if (MAIN_WINDOW_VITE_DEV_SERVER_URL) {
splashscreenFile = path.join(
app.getAppPath(),
'resources',
'splashscreen.html'
)
} else {
splashscreenFile = path.join(process.resourcesPath, 'splashscreen.html')
}

splashscreenWindow.loadFile(splashscreenFile)
splashscreenWindow.center()
}

const createWindow = async () => {
const icon = getAppIcon(process.env.NODE_ENV === 'development')
if (getPlatform() === 'mac') {
Expand Down Expand Up @@ -97,13 +124,6 @@ const createWindow = async () => {
)
}

// wait for the window to be ready before showing it. It prevents showing a white page on longer load times.
mainWindow.once('ready-to-show', () => {
// maximize will also show the window so mainWindow.show() is unneeded
mainWindow.maximize()
mainWindow.focus()
})

// Open the DevTools.
if (process.env.NODE_ENV === 'development') {
mainWindow.webContents.openDevTools({ mode: 'detach' })
Expand All @@ -113,6 +133,7 @@ const createWindow = async () => {
}

app.whenReady().then(async () => {
await createSplashWindow()
const mainWindow = await createWindow()
setupProjectStructure()

Expand Down Expand Up @@ -463,6 +484,16 @@ ipcMain.handle('browser:open:external:link', (_, url: string) => {
shell.openExternal(url)
})

ipcMain.on('splashscreen:close', (event) => {
console.info('splashscreen:close event received')

const browserWindow = browserWindowFromEvent(event)

splashscreenWindow.close()
browserWindow.show()
browserWindow.focus()
})

const browserWindowFromEvent = (
event: Electron.IpcMainEvent | Electron.IpcMainInvokeEvent
) => {
Expand Down
7 changes: 7 additions & 0 deletions src/preload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,13 +138,20 @@ const generator = {
},
} as const

const app = {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've added it as app as I think it made more sense, feel free to let me know if you think otherwise 🤔

closeSplashscreen: () => {
ipcRenderer.send('splashscreen:close')
},
} as const

const studio = {
proxy,
browser,
script,
har,
ui,
generator,
app,
} as const

contextBridge.exposeInMainWorld('studio', studio)
Expand Down
Loading