Skip to content

Commit

Permalink
feat: splash screen (#182)
Browse files Browse the repository at this point in the history
  • Loading branch information
AuHau committed Jul 1, 2022
1 parent 4900169 commit 250af98
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 0 deletions.
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())
})
})
}

0 comments on commit 250af98

Please sign in to comment.