Skip to content

Commit

Permalink
Add local notification when closing
Browse files Browse the repository at this point in the history
Instead of showing pop-up dialogue
  • Loading branch information
KevinX8 committed Mar 1, 2023
1 parent 7e9bf91 commit fe32209
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 19 deletions.
5 changes: 5 additions & 0 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import 'package:fl_chart/fl_chart.dart';
import 'package:flutter/services.dart';
import 'package:flutter_foreground_task/flutter_foreground_task.dart';
import 'package:intl/intl.dart';
import 'package:local_notifier/local_notifier.dart';
import 'package:negate/logger/android_logger.dart';
import 'package:negate/logger/logger_factory.dart';
import 'package:negate/sentiment_analysis.dart';
Expand Down Expand Up @@ -85,6 +86,10 @@ Future<void> main() async {
// as desktop hooks require their own constantly running thread
// otherwise the hooks will not be called
await loggerUI.initSystemTray();
await localNotifier.setup(
appName: 'Negate',
shortcutPolicy: ShortcutPolicy.requireCreate,
);
await Isolate.spawn(LoggerFactory.startLoggerFactory,
TfliteRequest(rPort.sendPort, dbString, tfp, prefs));
}
Expand Down
25 changes: 6 additions & 19 deletions lib/ui/window_decorations.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'package:bitsdojo_window/bitsdojo_window.dart';
import 'package:flutter/material.dart';
import 'package:local_notifier/local_notifier.dart';

class WindowButtons extends StatelessWidget {
WindowButtons({Key? key}) : super(key: key);
Expand Down Expand Up @@ -29,26 +30,12 @@ class WindowButtons extends StatelessWidget {
CloseWindowButton(
colors: closeButtonColors,
onPressed: () {
showDialog<void>(
context: context,
barrierDismissible: false,
builder: (BuildContext context) {
return AlertDialog(
title: const Text('Exit Program?'),
content: const Text(
('The window will be hidden, to exit the program you can use the system menu.')),
actions: <Widget>[
TextButton(
child: const Text('OK'),
onPressed: () {
Navigator.of(context).pop();
appWindow.hide();
},
),
],
);
},
appWindow.hide();
LocalNotification notification = LocalNotification(
title: "Negate",
body: "running in the background",
);
notification.show();
},
),
],
Expand Down
8 changes: 8 additions & 0 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -544,6 +544,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "2.0.1"
local_notifier:
dependency: "direct main"
description:
name: local_notifier
sha256: cc855aa6362c8840e3d3b35b1c3b058a3a8becdb2b03d5a9aa3f3a1e861f0a03
url: "https://pub.dev"
source: hosted
version: "0.1.5"
logging:
dependency: transitive
description:
Expand Down
1 change: 1 addition & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ dependencies:
file_picker: ^5.2.5
google_mlkit_language_id: ^0.5.0
google_mlkit_translation: ^0.5.0
local_notifier: ^0.1.5

dev_dependencies:
drift_dev: ^2.4.0
Expand Down
3 changes: 3 additions & 0 deletions windows/flutter/generated_plugin_registrant.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <bitsdojo_window_windows/bitsdojo_window_plugin.h>
#include <dynamic_color/dynamic_color_plugin_c_api.h>
#include <file_saver/file_saver_plugin.h>
#include <local_notifier/local_notifier_plugin.h>
#include <permission_handler_windows/permission_handler_windows_plugin.h>
#include <sqlite3_flutter_libs/sqlite3_flutter_libs_plugin.h>
#include <system_tray/system_tray_plugin.h>
Expand All @@ -21,6 +22,8 @@ void RegisterPlugins(flutter::PluginRegistry* registry) {
registry->GetRegistrarForPlugin("DynamicColorPluginCApi"));
FileSaverPluginRegisterWithRegistrar(
registry->GetRegistrarForPlugin("FileSaverPlugin"));
LocalNotifierPluginRegisterWithRegistrar(
registry->GetRegistrarForPlugin("LocalNotifierPlugin"));
PermissionHandlerWindowsPluginRegisterWithRegistrar(
registry->GetRegistrarForPlugin("PermissionHandlerWindowsPlugin"));
Sqlite3FlutterLibsPluginRegisterWithRegistrar(
Expand Down
1 change: 1 addition & 0 deletions windows/flutter/generated_plugins.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ list(APPEND FLUTTER_PLUGIN_LIST
bitsdojo_window_windows
dynamic_color
file_saver
local_notifier
permission_handler_windows
sqlite3_flutter_libs
system_tray
Expand Down

0 comments on commit fe32209

Please sign in to comment.