Skip to content

Commit

Permalink
working on udpater screen
Browse files Browse the repository at this point in the history
  • Loading branch information
codezerro committed Nov 10, 2024
1 parent b3a80a2 commit bb7e4ae
Show file tree
Hide file tree
Showing 5 changed files with 297 additions and 2 deletions.
43 changes: 43 additions & 0 deletions src/main/appWindow.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { app, BrowserWindow } from 'electron'
import { join } from 'path'

export function createUpdaterWindow(): BrowserWindow {
const win = new BrowserWindow({
width: 500,
height: 250,
frame: false,
transparent: true,
alwaysOnTop: true,
x: 0,
y: 0,
webPreferences: {
preload: join(__dirname, './../preload/index.js'),
nodeIntegration: false,
webSecurity: true,
sandbox: false,
contextIsolation: true
}
})

const updaterScreenSrc = app.isPackaged
? join(process.resourcesPath, 'updaterScreen.html')
: join(__dirname, './../../', 'updaterScreen.html')

win.loadFile(updaterScreenSrc)

// win.webContents.on('did-finish-load', () => {
// win.webContents
// .executeJavaScript(
// `
// const version = document.getElementById('version')
// version.textContent = '${appVersion}'
// `
// )
// .then((result) => {
// console.log('Executed in renderer:', result)
// })
// .catch(console.error)
// })

return win
}
15 changes: 14 additions & 1 deletion src/main/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,11 @@ import {
updateCommands,
updateCommandUtils
} from './db'
import { createUpdaterWindow } from './appWindow'

const isMac = process.platform === 'darwin'
let mainWindow: BrowserWindow | null = null
let updaterWindow: BrowserWindow | null = null
const appVersion = `v${app.getVersion()}`

// disable auto-update download
Expand Down Expand Up @@ -80,6 +82,8 @@ function createSplashWindow(): BrowserWindow {
return win
}

// updater window

// main window
const createWindow = async (): Promise<BrowserWindow> => {
mainWindow = new BrowserWindow({
Expand Down Expand Up @@ -392,15 +396,24 @@ app.whenReady().then(async () => {
}
}
)

// Updater Window
ipcMain.handle('updater:CLOSE_WINDOW', (_event) => {
try {
if (updaterWindow) updaterWindow.destroy()
} catch (error) {}
})
//@ Disappering splash screen and show main screen after 3 seconds.
try {
const splashScreen: BrowserWindow = createSplashWindow()
updaterWindow = createUpdaterWindow()
const mainScreen: BrowserWindow = await createWindow()

updaterWindow.show()
mainScreen.once('ready-to-show', () => {
setTimeout(
() => {
mainScreen.show()
// mainScreen.show()
splashScreen.destroy()
},
app.isPackaged ? 3000 : 0
Expand Down
4 changes: 4 additions & 0 deletions src/preload/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,11 @@ interface ApiInterface {
) => Promise<DatabaseFetching<ResponseStatus, null, string[]>>
//! DELETE
deleteCommandConfig: (id: number) => Promise<DatabaseFetching<ResponseStatus, null, string[]>>

// updater-window
updaterWindowClose: () => void
}

declare global {
interface Window {
electron: ElectronAPI
Expand Down
5 changes: 4 additions & 1 deletion src/preload/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,10 @@ const api = {
ipcRenderer.invoke('database:UPDATE_COMMAND_UTILS', id, image),
//! DELETE
deleteCommandConfig: (id: number): Promise<DatabaseFetching<ResponseStatus, null, string[]>> =>
ipcRenderer.invoke('database:DELETE_COMMAND_CONFIG', id)
ipcRenderer.invoke('database:DELETE_COMMAND_CONFIG', id),

// Updater Window
updaterWindowClose: () => ipcRenderer.invoke('updater:CLOSE_WINDOW')
}

// Use `contextBridge` APIs to expose Electron APIs to
Expand Down
232 changes: 232 additions & 0 deletions updaterScreen.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,232 @@
<!doctype html>
<html>
<head>
<meta charset="UTF-8" />
<!-- <meta
http-equiv="Content-Security-Policy"
content="script-src 'self' 'sha256-nIcnn83YNljR5yr5x/oVAdAFNemfHxxTO3zjtez52do='"
/> -->
<title>Robotics Academy</title>
<style>
body {
position: absolute;
top: 0;
left: 0;
height: 100%;
width: 100%;
overflow: hidden !important;
margin: 0;
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 'Ubuntu',
'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue', sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
user-select: none !important;
}

html {
color: #333333;
}

h1 {
margin-left: 0px;
}

.updater-container {
height: 100%;
display: flex;
flex-direction: column;
justify-content: start;
align-items: center;
background-color: white;
}
.loading-area {
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
}
.loading-logo {
width: 170px;
}
.loading-dots {
position: relative;
top: -5px;
width: 45px;
}
.developer {
font-size: 12px;
margin: 4px;
padding: 0;
color: #a4a4a4;
display: flex;
justify-content: end;
align-items: center;
width: 100%;
}
.developer > span {
font-size: 15px;
font-weight: 500;
margin: 2px;
}
.version {
position: absolute;
top: 88%;
left: 90%;
color: #f3f3f3;
font-size: 12px;
}

.orginzationText {
/* font-size: 150px; */
font-weight: 800;
outline: none;
background: linear-gradient(
135deg,
#5335cf 0%,
#de005e 25%,
#f66e48 50%,
#de005e 75%,
#5335cf 100%
);
background-size: 400%;
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
animation: textAnimate 20s linear infinite;
}
@keyframes textAnimate {
to {
background-position: 400%;
}
}

/* start */
/* header */
.header {
width: 100%;
height: 2.5rem;
display: flex;
justify-content: space-between;
align-items: center;
padding: 0px 12px;
background-color: #d9d9d9;
box-shadow: 0px 5px 10px 0px rgba(0, 0, 0, 0.2);
}
.header > .header-logo {
margin-left: 12px;
height: 2rem;
width: 2rem;
}
.header > .header-title {
font-size: 16px;
font-weight: 500;
opacity: 80%;
margin-left: -60px;
}
.header > .header-close {
padding: 7px 20px;
fill: #333;
cursor: pointer;
transition-duration: 300ms;
transition-property: fill;
}
.header > .header-close:hover {
background: red;
fill: white;
}

/* updater-body */
.updater-body {
margin-top: 20px;
display: flex;
gap: 16px;
font-size: 16px;
color: rgba(51, 51, 51, 100);
font-weight: 400;
align-items: self-start;
width: 100%;
justify-content: center;
}
.updater-body > .updater-body-download-icon {
}
.updater-body > .updater-body-update-info {
display: flex;
flex-direction: column;
gap: 8px;
}
.updater-body > .updater-body-update-info > p {
margin: 0px !important;
}
</style>
<script>
window.onload = async function () {
// get current version
try {
const c_version = await window.api.getAppVersion()
const version = document.getElementById('current-version')
if (c_version.status === 'SUCCESS') {
version.textContent = c_version.data
}
} catch (err) {
console.log(err)
}
}
</script>
</head>
<body>
<div class="updater-container">
<!-- header -->
<div class="header">
<img src="./resources/icons/icon.png" alt="jdeRobot" class="header-logo" />
<span class="header-title">Robotics Academy Desktop Update Available</span>
<div class="header-close" id="close-window">
<svg
xmlns="http://www.w3.org/2000/svg"
height="24px"
viewBox="0 -960 960 960"
width="25px"
>
<path
d="m256-200-56-56 224-224-224-224 56-56 224 224 224-224 56 56-224 224 224 224-56 56-224-224-224 224Z"
/>
</svg>
</div>
</div>
<!-- updater-body -->
<div class="updater-body">
<!-- download-icon -->
<div class="updater-body-download-icon">
<svg
xmlns="http://www.w3.org/2000/svg"
height="48px"
viewBox="0 -960 960 960"
width="48px"
fill="#0C94FB"
>
<path
d="M260-120v-73l47-47H140q-24 0-42-18t-18-42v-480q0-24 18-42t42-18h397v60H140v480h680v-139h60v139q0 24-18 42t-42 18H652l48 47v73H260Zm367-226L434-539l42-42 121 120v-379h60v379l121-120 42 42-193 193Z"
/>
</svg>
</div>
<!-- update informations -->
<div class="updater-body-update-info">
<p>A new version of Robotics Academy Desktop Available.</p>
<p>Do you want to download version 2.0.1 ?</p>
<p>Current Version <span id="current-version">2.0.0</span></p>
</div>
</div>
<!-- button -->
<!-- footer -->
</div>

<script>
const closeButton = document.getElementById('close-window')
closeButton.addEventListener('click', async () => {
try {
window.api.updaterWindowClose()
} catch (err) {
console.log(err)
}
})
</script>
</body>
</html>

0 comments on commit bb7e4ae

Please sign in to comment.