Tienson Qin 2 years ago
parent
commit
3b399d3bfe

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

@@ -18,6 +18,7 @@ dependencies {
     implementation project(':capacitor-share')
     implementation project(':capacitor-splash-screen')
     implementation project(':capacitor-status-bar')
+    implementation project(':capawesome-capacitor-background-task')
     implementation project(':logseq-capacitor-file-sync')
     implementation project(':capacitor-voice-recorder')
     implementation project(':send-intent')

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

@@ -35,6 +35,10 @@
 		"pkg": "@capacitor/status-bar",
 		"classpath": "com.capacitorjs.plugins.statusbar.StatusBarPlugin"
 	},
+	{
+		"pkg": "@capawesome/capacitor-background-task",
+		"classpath": "io.capawesome.capacitorjs.plugins.backgroundtask.BackgroundTaskPlugin"
+	},
 	{
 		"pkg": "@logseq/capacitor-file-sync",
 		"classpath": "com.logseq.app.filesync.FileSyncPlugin"

+ 3 - 0
android/capacitor.settings.gradle

@@ -29,6 +29,9 @@ project(':capacitor-splash-screen').projectDir = new File('../node_modules/@capa
 include ':capacitor-status-bar'
 project(':capacitor-status-bar').projectDir = new File('../node_modules/@capacitor/status-bar/android')
 
+include ':capawesome-capacitor-background-task'
+project(':capawesome-capacitor-background-task').projectDir = new File('../node_modules/@capawesome/capacitor-background-task/android')
+
 include ':logseq-capacitor-file-sync'
 project(':logseq-capacitor-file-sync').projectDir = new File('../node_modules/@logseq/capacitor-file-sync/android')
 

+ 1 - 0
ios/App/App/Info.plist

@@ -81,6 +81,7 @@
 	<key>UIBackgroundModes</key>
 	<array>
 		<string>audio</string>
+		<string>processing</string>
 	</array>
 	<key>UILaunchStoryboardName</key>
 	<string>LaunchScreen</string>

+ 1 - 0
ios/App/Podfile

@@ -20,6 +20,7 @@ def capacitor_pods
   pod 'CapacitorShare', :path => '../../node_modules/@capacitor/share'
   pod 'CapacitorSplashScreen', :path => '../../node_modules/@capacitor/splash-screen'
   pod 'CapacitorStatusBar', :path => '../../node_modules/@capacitor/status-bar'
+  pod 'CapawesomeCapacitorBackgroundTask', :path => '../../node_modules/@capawesome/capacitor-background-task'
   pod 'LogseqCapacitorFileSync', :path => '../../node_modules/@logseq/capacitor-file-sync'
   pod 'CapacitorVoiceRecorder', :path => '../../node_modules/capacitor-voice-recorder'
   pod 'SendIntent', :path => '../../node_modules/send-intent'

+ 14 - 11
src/main/frontend/fs/sync.cljs

@@ -2939,7 +2939,7 @@
                                                     base-path
                                                     repo *sync-state remoteapi-with-stop
                                                     (if (mobile-util/native-platform?)
-                                                      2000
+                                                      10000
                                                       10000)
                                                     *txid nil (chan) *stopped? *paused?
                                                     (chan 1) (chan 1))
@@ -3000,16 +3000,19 @@
                (mobile-util/native-ios?)
                (let [*task-id (atom nil)]
                  (when (and (not is-active?) (state/get-current-file-sync-graph-uuid))
-                   (go
-                     ;; Wait for file watcher events
-                     (<! (timeout 2000))
-                     (<! (<sync-local->remote-now))
-
-                     (p/let [task-id (.beforeExit ^js BackgroundTask
-                                                 (fn []
-                                                   (<! finished-local->remote-chan)
-                                                   (.finish ^js BackgroundTask @*task-id)))]
-                      (reset! *task-id task-id)))))
+                   (p/let [task-id (.beforeExit ^js BackgroundTask
+                                                (fn []
+                                                  (prn "before exit")
+                                                  (go
+                                                    ;; Wait for file watcher events
+                                                    (<! (timeout 2000))
+                                                    (<! (<sync-local->remote-now))
+                                                    (<! finished-local->remote-chan)
+                                                    (prn "finish task: " @*task-id)
+                                                    (let [opt #js {:taskId @*task-id}]
+                                                      (.finish ^js BackgroundTask opt)))))]
+
+                     (reset! *task-id task-id))))
 
                :else
                nil)))