mirror of
https://github.com/electron-vite/electron-vite-vue
synced 2025-03-14 04:40:10 +08:00
add electron-preload/
This commit is contained in:
parent
58c4898929
commit
2cec8d810c
19
electron-preload/index.ts
Normal file
19
electron-preload/index.ts
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
import { useLoading } from './loading'
|
||||||
|
|
||||||
|
function domReady(condition: DocumentReadyState[] = ['complete', 'interactive']) {
|
||||||
|
return new Promise(resolve => {
|
||||||
|
if (condition.includes(document.readyState)) {
|
||||||
|
resolve(true)
|
||||||
|
} else {
|
||||||
|
document.addEventListener('readystatechange', () => {
|
||||||
|
if (condition.includes(document.readyState)) {
|
||||||
|
resolve(true)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
const { appendLoading, removeLoading } = useLoading()
|
||||||
|
window.removeLoading = removeLoading
|
||||||
|
domReady().then(appendLoading)
|
67
electron-preload/loading.ts
Normal file
67
electron-preload/loading.ts
Normal file
@ -0,0 +1,67 @@
|
|||||||
|
/**
|
||||||
|
* https://tobiasahlin.com/spinkit
|
||||||
|
* https://connoratherton.com/loaders
|
||||||
|
* https://projects.lukehaas.me/css-loaders
|
||||||
|
* https://matejkustec.github.io/SpinThatShit
|
||||||
|
*/
|
||||||
|
export function useLoading() {
|
||||||
|
const className = `loaders-css__square-spin`
|
||||||
|
const styleContent = `
|
||||||
|
@keyframes square-spin {
|
||||||
|
25% { transform: perspective(100px) rotateX(180deg) rotateY(0); }
|
||||||
|
50% { transform: perspective(100px) rotateX(180deg) rotateY(180deg); }
|
||||||
|
75% { transform: perspective(100px) rotateX(0) rotateY(180deg); }
|
||||||
|
100% { transform: perspective(100px) rotateX(0) rotateY(0); }
|
||||||
|
}
|
||||||
|
.${className} > div {
|
||||||
|
animation-fill-mode: both;
|
||||||
|
width: 50px;
|
||||||
|
height: 50px;
|
||||||
|
background: #fff;
|
||||||
|
animation: square-spin 3s 0s cubic-bezier(0.09, 0.57, 0.49, 0.9) infinite;
|
||||||
|
}
|
||||||
|
.app-loading-wrap {
|
||||||
|
position: fixed;
|
||||||
|
top: 0;
|
||||||
|
left: 0;
|
||||||
|
width: 100vw;
|
||||||
|
height: 100vh;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
background: #282c34;
|
||||||
|
z-index: 9;
|
||||||
|
}
|
||||||
|
`
|
||||||
|
const oStyle = document.createElement('style')
|
||||||
|
const oDiv = document.createElement('div')
|
||||||
|
|
||||||
|
oStyle.id = 'app-loading-style'
|
||||||
|
oStyle.innerHTML = styleContent
|
||||||
|
oDiv.className = 'app-loading-wrap'
|
||||||
|
oDiv.innerHTML = `<div class="${className}"><div></div></div>`
|
||||||
|
|
||||||
|
return {
|
||||||
|
appendLoading() {
|
||||||
|
safe.append(document.head, oStyle)
|
||||||
|
safe.append(document.body, oDiv)
|
||||||
|
},
|
||||||
|
removeLoading() {
|
||||||
|
safe.remove(document.head, oStyle)
|
||||||
|
safe.remove(document.body, oDiv)
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const safe = {
|
||||||
|
append(parent: HTMLElement, child: HTMLElement) {
|
||||||
|
if (!Array.from(parent.children).find(e => e === child)) {
|
||||||
|
return parent.appendChild(child)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
remove(parent: HTMLElement, child: HTMLElement) {
|
||||||
|
if (Array.from(parent.children).find(e => e === child)) {
|
||||||
|
return parent.removeChild(child)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user