Skip to content

Commit

Permalink
fix for stopping all tasks on window close
Browse files Browse the repository at this point in the history
  • Loading branch information
juri117 committed Jun 8, 2023
1 parent 915132a commit 14fc1b4
Show file tree
Hide file tree
Showing 8 changed files with 64 additions and 12 deletions.
1 change: 1 addition & 0 deletions ReleaseNotes.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
**bug-fixes:**
* [x] fix bug in log list trim
* [x] make logs selectable
* [x] kill tasks on windows close did not work

## 0.00.004

Expand Down
28 changes: 22 additions & 6 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import 'package:flutter/material.dart';
import 'package:multi_split_view/multi_split_view.dart';
import 'package:task_launcher/log_view.dart';
import 'package:task_launcher/models/task.dart';
import 'package:window_manager/window_manager.dart';

const String versionName = "0.00.005";

Expand Down Expand Up @@ -41,7 +42,7 @@ class MyHomePage extends StatefulWidget {
State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
class _MyHomePageState extends State<MyHomePage> with WindowListener {
Timer? _timer;
final MultiSplitViewController _splitViewController =
MultiSplitViewController(areas: Area.weights([0.4, 0.6]));
Expand All @@ -54,12 +55,29 @@ class _MyHomePageState extends State<MyHomePage> {
@override
void initState() {
super.initState();
windowManager.addListener(this);
_loadJsonFile();
startTimer();
}

@override
void dispose() {
windowManager.removeListener(this);
super.dispose();
}

//@override
//void onWindowEvent(String eventName) {
// print('[WindowManager] onWindowEvent: $eventName');
//}

@override
void onWindowClose() {
//print("win close");
cleanupOnCLose();
}

void cleanupOnCLose() {
if (_timer != null) {
_timer?.cancel();
_timer = null;
Expand All @@ -71,7 +89,6 @@ class _MyHomePageState extends State<MyHomePage> {
print("${task.name}: failed to kill");
}
}
super.dispose();
}

void startTimer() {
Expand Down Expand Up @@ -120,7 +137,7 @@ class _MyHomePageState extends State<MyHomePage> {
_appendOutputToTask(task,
"\n*${'=' * 40}*\n*running command: ${task.cmd} ${task.params.join(" ")}*\n*${'-' * 40}*\n",
level: "D");
print("${task.name} start...");
//print("${task.name} start...");
try {
if (task.profile.isNotEmpty) {
if (!tasks.profiles.containsKey(task.profile)) {
Expand Down Expand Up @@ -177,7 +194,7 @@ class _MyHomePageState extends State<MyHomePage> {
print("${task.name} onError stderr error: $error, $stack");
_appendOutputToTask(task, "error: $error", level: "E");
}, cancelOnError: false);
print("${task.name} listener added");
// print("${task.name} listener added");
final int? exitCode = await completer.future;
print("${task.name} completed $exitCode");
_appendOutputToTask(task, "*exit code: $exitCode*\n", level: "D");
Expand All @@ -200,7 +217,6 @@ class _MyHomePageState extends State<MyHomePage> {
level: "E");
_appendOutputToTask(task, "$e\n", level: "E");
}
print('${task.name} finish...');
task.finished();
print('${task.name} finished');
}
Expand All @@ -221,7 +237,7 @@ class _MyHomePageState extends State<MyHomePage> {
}
}

Future<void> _killTask(Task task) async {
void _killTask(Task task) {
var pid = task.process?.pid;
if (pid != null) {
task.process?.kill(ProcessSignal.sigint);
Expand Down
8 changes: 8 additions & 0 deletions linux/flutter/generated_plugin_registrant.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@

#include "generated_plugin_registrant.h"

#include <screen_retriever/screen_retriever_plugin.h>
#include <window_manager/window_manager_plugin.h>

void fl_register_plugins(FlPluginRegistry* registry) {
g_autoptr(FlPluginRegistrar) screen_retriever_registrar =
fl_plugin_registry_get_registrar_for_plugin(registry, "ScreenRetrieverPlugin");
screen_retriever_plugin_register_with_registrar(screen_retriever_registrar);
g_autoptr(FlPluginRegistrar) window_manager_registrar =
fl_plugin_registry_get_registrar_for_plugin(registry, "WindowManagerPlugin");
window_manager_plugin_register_with_registrar(window_manager_registrar);
}
2 changes: 2 additions & 0 deletions linux/flutter/generated_plugins.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
#

list(APPEND FLUTTER_PLUGIN_LIST
screen_retriever
window_manager
)

list(APPEND FLUTTER_FFI_PLUGIN_LIST
Expand Down
28 changes: 22 additions & 6 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ packages:
dependency: transitive
description:
name: args
sha256: c372bb384f273f0c2a8aaaa226dad84dc27c8519a691b888725dec59518ad53a
sha256: eef6c46b622e0494a36c5a12d10d77fb4e855501a91c1b9ef9339326e58f0596
url: "https://pub.dev"
source: hosted
version: "2.4.1"
version: "2.4.2"
async:
dependency: transitive
description:
Expand Down Expand Up @@ -159,10 +159,10 @@ packages:
dependency: transitive
description:
name: lints
sha256: "6b0206b0bf4f04961fc5438198ccb3a885685cd67d4d4a32cc20ad7f8adbe015"
sha256: "0a217c6c989d21039f1498c3ed9f3ed71b354e69873f13a8dfc3c9fe76f1b452"
url: "https://pub.dev"
source: hosted
version: "2.1.0"
version: "2.1.1"
matcher:
dependency: transitive
description:
Expand Down Expand Up @@ -227,6 +227,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "1.2.0"
screen_retriever:
dependency: transitive
description:
name: screen_retriever
sha256: "4931f226ca158123ccd765325e9fbf360bfed0af9b460a10f960f9bb13d58323"
url: "https://pub.dev"
source: hosted
version: "0.1.6"
sky_engine:
dependency: transitive
description: flutter
Expand Down Expand Up @@ -296,6 +304,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "2.1.4"
window_manager:
dependency: "direct main"
description:
name: window_manager
sha256: "95096fede562cbb65f30d38b62d819a458f59ba9fe4a317f6cee669710f6676b"
url: "https://pub.dev"
source: hosted
version: "0.3.4"
xml:
dependency: transitive
description:
Expand All @@ -313,5 +329,5 @@ packages:
source: hosted
version: "3.1.2"
sdks:
dart: ">=3.0.0-417 <4.0.0"
flutter: ">=1.17.0"
dart: ">=3.0.0 <4.0.0"
flutter: ">=3.3.0"
1 change: 1 addition & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ dependencies:
intl: ^0.18.0
multi_split_view: ^2.1.0
rich_text_view: ^1.1.0
window_manager: ^0.3.4

dev_dependencies:
flutter_test:
Expand Down
6 changes: 6 additions & 0 deletions windows/flutter/generated_plugin_registrant.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@

#include "generated_plugin_registrant.h"

#include <screen_retriever/screen_retriever_plugin.h>
#include <window_manager/window_manager_plugin.h>

void RegisterPlugins(flutter::PluginRegistry* registry) {
ScreenRetrieverPluginRegisterWithRegistrar(
registry->GetRegistrarForPlugin("ScreenRetrieverPlugin"));
WindowManagerPluginRegisterWithRegistrar(
registry->GetRegistrarForPlugin("WindowManagerPlugin"));
}
2 changes: 2 additions & 0 deletions windows/flutter/generated_plugins.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
#

list(APPEND FLUTTER_PLUGIN_LIST
screen_retriever
window_manager
)

list(APPEND FLUTTER_FFI_PLUGIN_LIST
Expand Down

0 comments on commit 14fc1b4

Please sign in to comment.