Browse Source

fix: fix white screen after splash

Weihua Lu 4 years ago
parent
commit
f09a928778

+ 1 - 0
android/app/capacitor.build.gradle

@@ -10,6 +10,7 @@ android {
 apply from: "../capacitor-cordova-android-plugins/cordova.variables.gradle"
 dependencies {
     implementation project(':capacitor-filesystem')
+    implementation project(':capacitor-splash-screen')
 
 }
 

+ 5 - 3
android/app/src/main/assets/capacitor.config.json

@@ -3,8 +3,10 @@
 	"appName": "Logseq",
 	"bundledWebRuntime": false,
 	"webDir": "public",
-	"server": {
-		"url": "http://192.168.1.59:3001",
-		"cleartext": true
+	"plugins": {
+		"SplashScreen": {
+			"launchShowDuration": 3000,
+			"launchAutoHide": false
+		}
 	}
 }

+ 4 - 0
android/app/src/main/assets/capacitor.plugins.json

@@ -2,5 +2,9 @@
 	{
 		"pkg": "@capacitor/filesystem",
 		"classpath": "com.capacitorjs.plugins.filesystem.FilesystemPlugin"
+	},
+	{
+		"pkg": "@capacitor/splash-screen",
+		"classpath": "com.capacitorjs.plugins.splashscreen.SplashScreenPlugin"
 	}
 ]

+ 3 - 0
android/capacitor.settings.gradle

@@ -4,3 +4,6 @@ project(':capacitor-android').projectDir = new File('../node_modules/@capacitor/
 
 include ':capacitor-filesystem'
 project(':capacitor-filesystem').projectDir = new File('../node_modules/@capacitor/filesystem/android')
+
+include ':capacitor-splash-screen'
+project(':capacitor-splash-screen').projectDir = new File('../node_modules/@capacitor/splash-screen/android')

+ 16 - 8
capacitor.config.ts

@@ -1,14 +1,22 @@
 import { CapacitorConfig } from '@capacitor/cli';
 
 const config: CapacitorConfig = {
-  appId: 'com.logseq.app',
-  appName: 'Logseq',
-  bundledWebRuntime: false,
-  webDir: 'public',
-  server: {
-    url: process.env.LOGSEQ_APP_SERVER_URL,
-    cleartext: true
-  }
+    appId: 'com.logseq.app',
+    appName: 'Logseq',
+    bundledWebRuntime: false,
+    webDir: 'public',
+    plugins: {
+        SplashScreen: {
+            launchShowDuration: 3000,
+            launchAutoHide: false
+        },
+    }
+    // do not commit this into source control
+    // source: https://capacitorjs.com/docs/guides/live-reload
+    // , server: {
+    //     url: process.env.LOGSEQ_APP_SERVER_URL,
+    //     cleartext: true
+    // }
 };
 
 export = config;

+ 1 - 0
package.json

@@ -63,6 +63,7 @@
         "@capacitor/core": "^3.2.2",
         "@capacitor/filesystem": "^1.0.3",
         "@capacitor/ios": "^3.2.2",
+        "@capacitor/splash-screen": "^1.1.3",
         "@excalidraw/excalidraw": "^0.4.2",
         "@kanru/rage-wasm": "^0.2.1",
         "@sentry/browser": "^6.4.1",

+ 4 - 1
src/main/frontend/handler.cljs

@@ -16,6 +16,7 @@
             [frontend.handler.page :as page-handler]
             [frontend.handler.repo :as repo-handler]
             [frontend.handler.ui :as ui-handler]
+            [frontend.mobile.util :as mobile]
             [frontend.idb :as idb]
             [frontend.modules.instrumentation.core :as instrument]
             [frontend.modules.shortcut.core :as shortcut]
@@ -197,7 +198,9 @@
 
     (p/let [repos (get-repos)]
       (state/set-repos! repos)
-      (restore-and-setup! me repos logged? db-schema))
+      (restore-and-setup! me repos logged? db-schema)
+      (when (mobile/is-native-platform?)
+        (p/do! (mobile/hide-splash))))
 
     (reset! db/*sync-search-indice-f search/sync-search-indice!)
     (db/run-batch-txs!)

+ 5 - 1
src/main/frontend/mobile/util.cljs

@@ -1,5 +1,6 @@
 (ns frontend.mobile.util
-  (:require ["@capacitor/core" :refer [Capacitor registerPlugin]]))
+  (:require ["@capacitor/core" :refer [Capacitor registerPlugin]]
+            ["@capacitor/splash-screen" :refer [SplashScreen]]))
 
 (defn platform []
   (.getPlatform Capacitor))
@@ -14,3 +15,6 @@
   (.isPluginAvailable Capacitor name))
 
 (defonce folder-picker (registerPlugin "FolderPicker"))
+
+(defn hide-splash []
+  (.hide SplashScreen))

+ 7 - 0
yarn.lock

@@ -955,6 +955,11 @@
   resolved "https://registry.yarnpkg.com/@capacitor/ios/-/ios-3.2.2.tgz#0417cf89df23f651c6a1e20a8fb98294a918ce1f"
   integrity sha512-Eq17Y+UDHFmYGaZcObvxHAcHw0fF9TCBAg1f5f6qdV8ab3cKKEUB9xMvoCSZAueBfxFARrD18TsZJKoxh2YsLA==
 
+"@capacitor/splash-screen@^1.1.3":
+  version "1.1.3"
+  resolved "https://registry.yarnpkg.com/@capacitor/splash-screen/-/splash-screen-1.1.3.tgz#024bc91b2b521b9f1d5e86f16a114f294bf326fa"
+  integrity sha512-DJh1w9872UofZWAxPLgd5yWi09W0IoWPVBdVd8Ku1mrPfFvtcMeguZHGLEIo+A6DkdCTWzMrh26TLCIympws2g==
+
 "@cypress/[email protected]":
   version "3.0.1"
   resolved "https://registry.yarnpkg.com/@cypress/browserify-preprocessor/-/browserify-preprocessor-3.0.1.tgz#ab86335b0c061d11f5ad7df03f06b1877b836f71"
@@ -7861,6 +7866,8 @@ react-icons@^2.2.7:
   version "2.2.7"
   resolved "https://registry.yarnpkg.com/react-icons/-/react-icons-2.2.7.tgz#d7860826b258557510dac10680abea5ca23cf650"
   integrity sha512-0n4lcGqzJFcIQLoQytLdJCE0DKSA9dkwEZRYoGrIDJZFvIT6Hbajx5mv9geqhqFiNjUgtxg8kPyDfjlhymbGFg==
+  dependencies:
+    react-icon-base "2.1.0"
 
 react-is@^16.3.1, react-is@^16.8.1:
   version "16.13.1"