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: splash screen #182

Merged
merged 1 commit into from
Jul 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions assets/splash.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<!DOCTYPE html>
<html lang='en'>
<head>
<meta charset='UTF-8'>
<title>Splash</title>
</head>
<body>
<img src='./splash.png' style='width: 100%;' alt=''>
</body>
</html>
Binary file added assets/splash.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { ensureApiKey } from './api-key'
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
import squirrelInstallingExecution from 'electron-squirrel-startup'
import { initSplash } from './splash'

if (squirrelInstallingExecution) {
app.quit()
Expand Down Expand Up @@ -69,6 +70,7 @@ async function main() {
// },
})
}
const hideSplash = await initSplash()

// Auto updaterg
// @ts-ignore: https://github.com/electron/update-electron-app/pull/96
Expand Down Expand Up @@ -99,6 +101,8 @@ async function main() {
} else {
if (process.env.NODE_ENV !== 'development') openInstallerInBrowser()
}

hideSplash()
runKeepAliveLoop()
}

Expand Down
17 changes: 17 additions & 0 deletions src/splash.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { BrowserWindow, app } from 'electron'
import * as path from 'path'
import { logger } from './logger'

export async function initSplash(): Promise<() => void> {
return new Promise((resolve, reject) => {
app.on('ready', () => {
const splashImage = path.resolve(__dirname, '..', '..', '..', 'assets', 'splash.html')
logger.info(`Serving splash screen from path ${splashImage}`)

const splash = new BrowserWindow({ width: 810, height: 610, transparent: true, frame: false, alwaysOnTop: true })
splash.loadURL(`file://${splashImage}`).catch(reject)

resolve(() => splash.hide())
})
})
}