#139 fix
This commit is contained in:
@@ -55,5 +55,7 @@
|
|||||||
android:name="android.appwidget.provider"
|
android:name="android.appwidget.provider"
|
||||||
android:resource="@xml/home_widget" />
|
android:resource="@xml/home_widget" />
|
||||||
</receiver>
|
</receiver>
|
||||||
|
|
||||||
|
<service android:name=".KeepAliveService"/>
|
||||||
</application>
|
</application>
|
||||||
</manifest>
|
</manifest>
|
||||||
|
|||||||
@@ -0,0 +1,18 @@
|
|||||||
|
package tech.lolli.toolbox
|
||||||
|
|
||||||
|
import android.app.Service
|
||||||
|
import android.content.Intent
|
||||||
|
|
||||||
|
import android.os.IBinder
|
||||||
|
import org.jetbrains.annotations.Nullable
|
||||||
|
|
||||||
|
class KeepAliveService : Service() {
|
||||||
|
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
|
||||||
|
return START_STICKY
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
override fun onBind(intent: Intent?): IBinder? {
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
package tech.lolli.toolbox
|
package tech.lolli.toolbox
|
||||||
|
|
||||||
|
import android.content.Intent
|
||||||
import io.flutter.embedding.android.FlutterActivity
|
import io.flutter.embedding.android.FlutterActivity
|
||||||
import io.flutter.embedding.engine.FlutterEngine
|
import io.flutter.embedding.engine.FlutterEngine
|
||||||
import io.flutter.plugin.common.MethodChannel
|
import io.flutter.plugin.common.MethodChannel
|
||||||
@@ -11,11 +12,18 @@ class MainActivity : FlutterActivity() {
|
|||||||
|
|
||||||
MethodChannel(binaryMessenger, "tech.lolli.toolbox/app_retain").apply {
|
MethodChannel(binaryMessenger, "tech.lolli.toolbox/app_retain").apply {
|
||||||
setMethodCallHandler { method, result ->
|
setMethodCallHandler { method, result ->
|
||||||
if (method.method == "sendToBackground") {
|
when (method.method) {
|
||||||
moveTaskToBack(true)
|
"sendToBackground" -> {
|
||||||
result.success(null)
|
moveTaskToBack(true)
|
||||||
} else {
|
result.success(null)
|
||||||
result.notImplemented()
|
}
|
||||||
|
"startService" -> {
|
||||||
|
val intent = Intent(this@MainActivity, KeepAliveService::class.java)
|
||||||
|
startService(intent)
|
||||||
|
}
|
||||||
|
else -> {
|
||||||
|
result.notImplemented()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import 'package:logging/logging.dart';
|
|||||||
import 'package:macos_window_utils/window_manipulator.dart';
|
import 'package:macos_window_utils/window_manipulator.dart';
|
||||||
import 'package:provider/provider.dart';
|
import 'package:provider/provider.dart';
|
||||||
import 'package:shared_preferences/shared_preferences.dart';
|
import 'package:shared_preferences/shared_preferences.dart';
|
||||||
|
import 'package:toolbox/data/res/misc.dart';
|
||||||
import 'package:toolbox/view/widget/custom_appbar.dart';
|
import 'package:toolbox/view/widget/custom_appbar.dart';
|
||||||
|
|
||||||
import 'app.dart';
|
import 'app.dart';
|
||||||
@@ -92,8 +93,13 @@ Future<void> initApp() async {
|
|||||||
final settings = locator<SettingStore>();
|
final settings = locator<SettingStore>();
|
||||||
loadFontFile(settings.fontPath.fetch());
|
loadFontFile(settings.fontPath.fetch());
|
||||||
|
|
||||||
// SharedPreferences is only used on Android for saving home widgets settings.
|
// Android only
|
||||||
if (!isAndroid) return;
|
if (!isAndroid) return;
|
||||||
|
// Only start service when [bgRun] is true.
|
||||||
|
if (locator<SettingStore>().bgRun.fetch() ?? false) {
|
||||||
|
bgRunChannel.invokeMethod('startService');
|
||||||
|
}
|
||||||
|
// SharedPreferences is only used on Android for saving home widgets settings.
|
||||||
SharedPreferences.setPrefix('');
|
SharedPreferences.setPrefix('');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user