Skip to content

Commit

Permalink
fix: 启动动画卡顿
Browse files Browse the repository at this point in the history
  • Loading branch information
caoxiemeihao committed Jun 23, 2021
1 parent 0f390de commit 118cc7d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 12 deletions.
12 changes: 6 additions & 6 deletions src/preload/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ function domReady(...args) {
}

/** 插入 loading */
function insertLoading() {
function loadingBootstrap() {
const loadingStyle = document.createElement('style');
const loadingBox = document.createElement('div');

Expand Down Expand Up @@ -114,16 +114,16 @@ function insertLoading() {
; (async function () {
await domReady();

let _isCallClosePreloadLoading = false;
const { removeLoading, appendLoading } = insertLoading();
let _isCallRemoveLoading = false;
const { removeLoading, appendLoading } = loadingBootstrap();

window.ClosePreloadLoading = () => {
_isCallClosePreloadLoading = true;
window.removeLoading = () => {
_isCallRemoveLoading = true;
removeLoading();
};

// 5 秒超时自动关闭
setTimeout(() => !_isCallClosePreloadLoading && removeLoading(), 4999);
setTimeout(() => !_isCallRemoveLoading && removeLoading(), 4999);

appendLoading();
})();
17 changes: 11 additions & 6 deletions src/render/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,17 @@ import { ipcRenderer } from 'electron'
import Store from 'electron-store'
import './index.css'

console.log('ipcRenderer:', ipcRenderer)
// Configuration name causes hot updates to be slow | 传递 name 后会导致热更新很慢
// console.log('electron-store', new Store({ name: 'electron-vue' }))
// https://github.com/caoxiemeihao/electron-vue-vite/issues/10
console.log('electron-store', new Store())

setTimeout(() => {
console.log('ipcRenderer:', ipcRenderer)
// Configuration name causes hot updates to be slow | 传递 name 后会导致热更新很慢
// console.log('electron-store', new Store({ name: 'electron-vue' }))
// https://github.com/caoxiemeihao/electron-vue-vite/issues/10
console.log('electron-store', new Store())

// new Store 会阻塞线程,导致 preload 动画卡顿
}, 2999)

createApp(App)
.mount('#app')
.$nextTick(window.ClosePreloadLoading)
.$nextTick(window.removeLoading)

0 comments on commit 118cc7d

Please sign in to comment.