Skip to content

Commit a164be0

Browse files
committed
Disable left over timers
When a plugin timer exists and the plugin is deleted (without disabling it) we should delete the reduntant timer.
1 parent bc8104a commit a164be0

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

app/lib/blocs/plugin_manager_bloc.dart

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,15 @@ class PluginManagerBloc extends Bloc<PluginManagerEvent, PluginManagerState> {
5454
}
5555

5656
void _initTimers(List<PluginManifestPluginState> plugins) {
57+
final pluginNames = <String>[];
5758
for (final plugin in plugins) {
5859
final name = pluginInstanceManifestName(manifest: plugin);
5960
final enabled = pluginInstanceManifestEnabled(manifest: plugin);
6061
final event = pluginInstanceManifestEvent(manifest: plugin);
6162
final timer = event.timer;
6263

64+
pluginNames.add(name);
65+
6366
if (!enabled || timer == null) {
6467
final record = _timers.remove(name);
6568
record?.timer.cancel();
@@ -81,13 +84,22 @@ class PluginManagerBloc extends Bloc<PluginManagerEvent, PluginManagerState> {
8184
duration: duration,
8285
timer: Timer.periodic(
8386
duration,
84-
(timer) => pm.emit(
87+
(timer) async => pm.emit(
8588
event: HostEvent.timer(interval: interval),
8689
pluginName: name,
8790
),
8891
),
8992
);
9093
}
94+
95+
for (final name in _timers.keys.toList()) {
96+
if (pluginNames.contains(name)) {
97+
continue;
98+
}
99+
100+
final record = _timers.remove(name);
101+
record?.timer.cancel();
102+
}
91103
}
92104

93105
Future<void> _processHostEvents(void _) async {

0 commit comments

Comments
 (0)