Browse Source

启动进度加载动画

lilei 3 years ago
parent
commit
6772779ff5
4 changed files with 60 additions and 4 deletions
  1. 1 1
      package.json
  2. BIN
      public/_.gif
  3. 27 0
      public/loading.html
  4. 32 3
      src/background.js

+ 1 - 1
package.json

@@ -1,6 +1,6 @@
 {
   "name": "electron-jg",
-  "version": "0.1.0",
+  "version": "1.0.0",
   "private": true,
   "scripts": {
     "serve": "vue-cli-service serve",

BIN
public/_.gif


+ 27 - 0
public/loading.html

@@ -0,0 +1,27 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+    <meta charset="UTF-8">
+    <meta http-equiv="X-UA-Compatible" content="IE=edge">
+    <meta name="viewport" content="width=device-width, initial-scale=1.0">
+    <title>Document</title>
+    <style>
+        body{
+            margin: 0;
+            padding: 0;
+            overflow: hidden;
+            background:rgba(0,0,0,.5)
+        }
+        body::-webkit-scrollbar{
+            display: none;
+        }
+        img{
+            width: 400px;
+            height: 300px;
+        }
+    </style>
+</head>
+<body>
+    <img src="./_.gif" alt="" srcset="">
+</body>
+</html>

+ 32 - 3
src/background.js

@@ -5,7 +5,34 @@ import { createProtocol } from 'vue-cli-plugin-electron-builder/lib'
 import installExtension, { VUEJS_DEVTOOLS } from 'electron-devtools-installer'
 import { updateHandle } from './update'
 const isDevelopment = process.env.NODE_ENV !== 'production'
-let mainWindow
+
+if (!isDevelopment) {
+  global.__static = require("path")
+    .join(__dirname, "/static")
+    .replace(/\\/g, "\\\\");
+}
+let mainWindow, loadingWindow;
+
+const loadingURL =
+  isDevelopment //加载loading.html页面地址
+    ? require("path").join(__static, "loading.html")
+    : `file://${__static}/loading.html`;
+
+const showLoading = (cb) => {
+  loadingWindow = new BrowserWindow({
+    show: false,
+    frame: false, // 无边框(窗口、工具栏等),只包含网页内容
+    width: 400,
+    height: 300,
+    resizable: false,
+    transparent: true, // 窗口是否支持透明,如果想做高级效果最好为true
+  });
+ 
+  loadingWindow.once("show", cb);
+  loadingWindow.loadURL(loadingURL);
+  loadingWindow.show();
+};
+
 // Scheme must be registered before the app is ready
 protocol.registerSchemesAsPrivileged([
   { scheme: 'app', privileges: { secure: true, standard: true } }
@@ -41,8 +68,10 @@ async function createWindow() {
     createProtocol('app')
 	win.loadURL(process.env.VUE_APP_API_BASE_URL)
 	win.on('ready-to-show', function () {
+		loadingWindow.hide();
+		loadingWindow.close();
 		win.show() // 初始化后再显示
-	  })
+	})
   }
   // 在开发环境和生产环境均可通过快捷键打开devTools
   globalShortcut.register('CommandOrControl+Shift+i', function () {
@@ -92,7 +121,7 @@ if (!gotTheLock) {
         console.error('Vue Devtools failed to install:', e.toString())
       }
     }
-    createWindow()
+	showLoading(createWindow);
   })
 }