forked from firka/firka
firka(android): fix widget refresh via GlanceAppWidget.updateAll
This commit is contained in:
@@ -6,9 +6,14 @@ import android.content.pm.PackageManager
|
||||
import android.os.Build
|
||||
import android.os.Bundle
|
||||
import android.util.Log
|
||||
import app.firka.naplo.glance.TimetableWidget
|
||||
import io.flutter.embedding.android.FlutterActivity
|
||||
import io.flutter.embedding.engine.FlutterEngine
|
||||
import io.flutter.plugin.common.MethodChannel
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.SupervisorJob
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlin.system.exitProcess
|
||||
|
||||
class MainActivity : FlutterActivity() {
|
||||
@@ -97,7 +102,17 @@ class MainActivity : FlutterActivity() {
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
}
|
||||
result.success(true)
|
||||
result.success(true)
|
||||
}
|
||||
"refreshTimetableWidget" -> {
|
||||
CoroutineScope(SupervisorJob() + Dispatchers.Default).launch {
|
||||
try {
|
||||
TimetableWidget().updateAll(context.applicationContext)
|
||||
result.success(true)
|
||||
} catch (e: Exception) {
|
||||
result.error("refresh_failed", e.message, null)
|
||||
}
|
||||
}
|
||||
}
|
||||
else -> {
|
||||
result.notImplemented()
|
||||
|
||||
@@ -18,7 +18,7 @@ import 'package:firka/core/state/firka_state.dart';
|
||||
import 'package:firka/data/widget.dart';
|
||||
import 'package:firka/ui/shared/firka_icon.dart';
|
||||
import 'package:firka/ui/theme/style.dart';
|
||||
import 'package:home_widget/home_widget.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:path/path.dart' as p;
|
||||
import 'package:path_provider/path_provider.dart';
|
||||
|
||||
@@ -148,10 +148,9 @@ class _DebugScreen extends FirkaState<DebugScreen> {
|
||||
widget.data.client,
|
||||
);
|
||||
if (Platform.isAndroid) {
|
||||
await HomeWidget.updateWidget(
|
||||
qualifiedAndroidName:
|
||||
'app.firka.naplo.glance.TimetableWidgetReceiver',
|
||||
);
|
||||
await const MethodChannel(
|
||||
'firka.app/main',
|
||||
).invokeMethod<void>('refreshTimetableWidget');
|
||||
}
|
||||
if (!context.mounted) return;
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
|
||||
Reference in New Issue
Block a user