-
Notifications
You must be signed in to change notification settings - Fork 378
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: electron splash screen (#4119)
* splash screen * Fix css * Fixes logo * Fix blank window * Fixes mac * fix splash screen flashing on linux * Added comments Co-authored-by: Soroush <sorgh@microsoft.com> Co-authored-by: Chris Whitten <christopher.whitten@microsoft.com> Co-authored-by: Geoff Cox (Microsoft) <gcox@microsoft.com>
- Loading branch information
1 parent
f5c30f3
commit cf5544b
Showing
5 changed files
with
262 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
92 changes: 92 additions & 0 deletions
92
Composer/packages/electron-server/src/splash/splashScreen.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT License. | ||
|
||
import { BrowserWindow, systemPreferences } from 'electron'; | ||
|
||
import { getSplashScreenContent, statusElmId } from './template'; | ||
|
||
export type SplashScreenProps = { | ||
getMainWindow: () => BrowserWindow | undefined; | ||
color?: string; | ||
icon?: string; | ||
width?: number; | ||
height?: number; | ||
productName?: string; | ||
productFamily?: string; | ||
logo?: string; | ||
website?: string; | ||
status?: string; | ||
}; | ||
|
||
export const initSplashScreen = async ({ | ||
getMainWindow, | ||
color: initColor, | ||
icon, | ||
width = 600, | ||
height = 400, | ||
productName, | ||
productFamily, | ||
logo, | ||
website, | ||
status, | ||
}: SplashScreenProps) => { | ||
// If no color is provided, uses OS accent color | ||
const color = initColor || (systemPreferences.getAccentColor && `#${systemPreferences.getAccentColor()}`); | ||
|
||
const splashScreenWindow = new BrowserWindow({ | ||
parent: getMainWindow(), | ||
show: false, | ||
width, | ||
height, | ||
modal: true, | ||
transparent: true, | ||
skipTaskbar: true, | ||
frame: false, | ||
autoHideMenuBar: true, | ||
alwaysOnTop: true, | ||
resizable: false, | ||
movable: false, | ||
icon, | ||
webPreferences: { | ||
// This is necessary to enable loading local images in the url protocol (window.loadURL) | ||
webSecurity: false, | ||
}, | ||
}); | ||
|
||
const args = { | ||
productName, | ||
productFamily, | ||
logo, | ||
website, | ||
color, | ||
status, | ||
}; | ||
|
||
// This prevents window visual flash | ||
splashScreenWindow.on('ready-to-show', () => { | ||
splashScreenWindow.show(); | ||
}); | ||
|
||
const file = 'data:text/html;charset=UTF-8,' + encodeURIComponent(getSplashScreenContent(args)); | ||
await splashScreenWindow.loadURL(file); | ||
|
||
/** | ||
* Displays the main windows of the app and destroys the splash screen. | ||
*/ | ||
const startApp = () => { | ||
setTimeout(() => splashScreenWindow.destroy(), 500); | ||
getMainWindow()?.show(); | ||
}; | ||
|
||
/** | ||
* Updates the loading status on the splash screen. | ||
* @param status New status text. | ||
*/ | ||
const updateStatus = async (status: string) => { | ||
await splashScreenWindow.webContents.executeJavaScript( | ||
`document.querySelector('#${statusElmId}').textContent = '${status}';` | ||
); | ||
}; | ||
|
||
return { startApp, updateStatus }; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT License. | ||
|
||
export const statusElmId = 'status-txt'; | ||
|
||
export const getSplashScreenContent = ({ | ||
logo = '', | ||
productName = 'Product', | ||
productFamily = 'Product Family', | ||
text = 'Loading ...', | ||
website = 'www.website.com', | ||
color = '#666', | ||
}) => ` | ||
<!DOCTYPE html> | ||
<meta charset="utf-8"> | ||
<html> | ||
<head> | ||
<style> | ||
html, | ||
body | ||
{ | ||
margin: 0; | ||
overflow: hidden; | ||
} | ||
#box { | ||
position: absolute; | ||
user-select: none; | ||
width: 100%; | ||
height: 100%; | ||
overflow: hidden; | ||
margin: auto; | ||
display: flex; | ||
align-items: center; | ||
justify-content: center; | ||
flex-direction: column | ||
} | ||
#logo { | ||
position: absolute; | ||
display: flex; | ||
align-items: center; | ||
justify-content: center; | ||
top: 0; | ||
left: 0; | ||
} | ||
#logo img { | ||
height: 60px | ||
} | ||
#box .text { | ||
color: white; | ||
font-weight: 400; | ||
margin: 0; | ||
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol"; | ||
} | ||
#box h1 { | ||
color: white; | ||
font-size: 36px; | ||
} | ||
#box h2 { | ||
color: white; | ||
font-size: 18px; | ||
} | ||
#box h4 { | ||
font-size: 12px; | ||
font-weight: 400; | ||
opacity: 50%; | ||
} | ||
#${statusElmId} { | ||
position: absolute; | ||
left: 20px; | ||
bottom: 16px; | ||
} | ||
#website-url { | ||
position: absolute; | ||
right: 20px; | ||
bottom: 16px; | ||
} | ||
</style> | ||
</head> | ||
<body style="background-color:${color}"> | ||
<div id="box" style="background-color:${color}"> | ||
<span id="logo"> | ||
<img id="logo-img" src="${logo}" /> | ||
</span> | ||
<h1 id="product" class="text">${productName}</h1> | ||
${productFamily ? `<h2 id="product-family" class="text">${productFamily}</h2>` : ''} | ||
<h4 class="text" id="${statusElmId}">${text}</h4> | ||
<h4 class="text" id="website-url">${website}</h4> | ||
</div> | ||
</body> | ||
</html> | ||
`; |