Skip to content

Commit

Permalink
Add context menu on right-click, design improvement using HoverButton
Browse files Browse the repository at this point in the history
  • Loading branch information
Vonarian committed Jul 31, 2022
1 parent 5b55642 commit ebb40c4
Show file tree
Hide file tree
Showing 10 changed files with 213 additions and 175 deletions.
17 changes: 3 additions & 14 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ import 'package:firebase_dart_flutter/firebase_dart_flutter.dart';
import 'package:fluent_ui/fluent_ui.dart';
import 'package:flutter_acrylic/flutter_acrylic.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:local_notifier/local_notifier.dart';
import 'package:path/path.dart' as p;
import 'package:sentry_flutter/sentry_flutter.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:system_info2/system_info2.dart';
import 'package:win_toast/win_toast.dart';
import 'package:window_manager/window_manager.dart';
import 'package:wtnews/pages/loading.dart';
import 'package:wtnews/providers.dart';
Expand All @@ -34,7 +34,6 @@ final String newSound = p.joinAll([
final provider = MyProvider();
final deviceInfo = DeviceInfoPlugin();
final Dio dio = Dio();
final winToast = WinToast.instance();
late final String appVersion;

Future<void> main(List<String> args) async {
Expand Down Expand Up @@ -63,8 +62,8 @@ Future<void> main(List<String> args) async {

await windowManager.show();
});
await winToast.initialize(
appName: 'WTNews', productName: 'WTNews', companyName: 'Vonarian');
await localNotifier.setup(
appName: 'WTNews', shortcutPolicy: ShortcutPolicy.ignore);
await FirebaseDartFlutter.setup();
app = await Firebase.initializeApp(
options: FirebaseOptions.fromMap(firebaseConfig), name: 'wtnews-54364');
Expand All @@ -73,7 +72,6 @@ Future<void> main(List<String> args) async {
username: prefs.getString('userName'),
ipAddress: scope.user?.ipAddress)));
appVersion = await File(pathToVersion).readAsString();

await SentryFlutter.init(
(options) {
options.dsn = dsn;
Expand All @@ -87,15 +85,6 @@ Future<void> main(List<String> args) async {
};
},
);
if (prefs.getString('userName') != null &&
prefs.getString('userName') != '' &&
prefs.getBool('additionalNotif') != null &&
prefs.getBool('additionalNotif')!) {
winToast.showToast(
type: ToastType.text04,
subtitle: 'Welcome back ${prefs.getString('userName')} :)',
title: 'Hi!');
}
runApp(ProviderScope(
overrides: [provider.prefsProvider.overrideWithValue(prefs)],
child: App(startup: args.isNotEmpty, child: Loading(prefs)),
Expand Down
17 changes: 7 additions & 10 deletions lib/pages/custom_feed.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ import 'dart:io';
import 'package:dio/dio.dart';
import 'package:fluent_ui/fluent_ui.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:local_notifier/local_notifier.dart';
import 'package:path/path.dart' as p;
import 'package:shared_preferences/shared_preferences.dart';
import 'package:url_launcher/url_launcher.dart';
import 'package:webfeed/domain/rss_feed.dart';
import 'package:webfeed/domain/rss_item.dart';
import 'package:win_toast/win_toast.dart';

import '../main.dart';
import '../services/utility.dart';
Expand Down Expand Up @@ -75,15 +75,12 @@ class CustomRSSViewState extends ConsumerState<CustomRSSView> {
Future<void> sendNotification(
{required String? newTitle, required String url}) async {
if (newTitle != null) {
var toast = await winToast.showToast(
type: ToastType.text04,
title: 'New content in the feed',
subtitle: newTitle);
toast?.eventStream.listen((event) async {
if (event is ActivatedEvent) {
await launchUrl(Uri.parse(url));
}
});
var toast =
LocalNotification(title: 'New content in the feed', body: newTitle)
..show();
toast.onClick = () {
launchUrl(Uri.parse(url));
};
}
}

Expand Down
128 changes: 77 additions & 51 deletions lib/pages/datamine.dart
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import 'dart:async';

import 'package:contextmenu/contextmenu.dart';
import 'package:fluent_ui/fluent_ui.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/services.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:local_notifier/local_notifier.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:url_launcher/url_launcher.dart';
import 'package:webfeed/domain/rss_feed.dart';
import 'package:webfeed/domain/rss_item.dart';
import 'package:win_toast/win_toast.dart';

import '../main.dart';
import '../services/utility.dart';
Expand Down Expand Up @@ -52,31 +54,25 @@ class DataMineState extends ConsumerState<DataMine> {
}

AppUtil.playSound(newSound);
final toast = await winToast.showToast(
final toast = LocalNotification(
title: 'New Data Mine',
type: ToastType.text04,
subtitle: 'Click to launch in browser',
);
toast?.eventStream.listen((event) {
if (event is ActivatedEvent) {
launchUrl(Uri.parse(url));
}
});
body: 'Click to launch in browser',
)..show();
toast.onClick = () {
launchUrl(Uri.parse(url));
};
}
} else {
if (kDebugMode) {
print('Null');
}
AppUtil.playSound(newSound);
final toast = await winToast.showToast(
title: 'New Data Mine',
type: ToastType.text04,
subtitle: 'New Data Mine from gszabi');
toast?.eventStream.listen((event) {
if (event is ActivatedEvent) {
launchUrl(Uri.parse(url));
}
});
final toast = LocalNotification(
title: 'New Data Mine', body: 'New Data Mine from gszabi')
..show();
toast.onClick = () {
launchUrl(Uri.parse(url));
};
}
}

Expand Down Expand Up @@ -106,43 +102,73 @@ class DataMineState extends ConsumerState<DataMine> {
mainAxisAlignment: MainAxisAlignment.start,
children: [
HoverButton(
builder: (context, set) => ListTile(
title: Row(
children: [
Text(
data.title ?? '',
style: TextStyle(
color: theme.accentColor.light,
fontWeight: FontWeight.bold),
builder: (context, set) => Container(
color: set.isHovering ? Colors.grey[200] : null,
child: ContextMenuArea(
builder: (context) {
return <Widget>[
HoverButton(
builder: (context, set2) {
late final Color color;
if (set2.isHovering) {
color = theme.accentColor
.withOpacity(0.11);
} else {
color = theme.scaffoldBackgroundColor;
}
return ListTile(
title: const Text('Copy Link'),
contentPadding:
const EdgeInsets.only(left: 20),
tileColor: color,
);
},
onPressed: () async {
await Clipboard.setData(
ClipboardData(text: data.link));
if (!mounted) return;
Navigator.of(context).pop();
},
focusEnabled: true,
cursor: SystemMouseCursors.click,
),
];
},
child: ListTile(
title: Row(
children: [
Text(
data.title ?? '',
style: TextStyle(
color: theme.accentColor.light,
fontWeight: FontWeight.bold),
),
Text(
' 📰By gszabi99_HUN📰',
style: TextStyle(
color: theme.accentColor.lightest,
fontWeight: FontWeight.bold),
),
],
),
Text(
' 📰By gszabi99_HUN📰',
style: TextStyle(
color: theme.accentColor.lightest,
fontWeight: FontWeight.bold),
subtitle: Text(
description
?.replaceAll('\n', '')
.replaceAll(' ', '') ??
'',
overflow: TextOverflow.ellipsis,
maxLines: 2,
style: const TextStyle(
letterSpacing: 0.52, fontSize: 14),
),
],
),
subtitle: Text(
description
?.replaceAll('\n', '')
.replaceAll(' ', '') ??
'',
overflow: TextOverflow.ellipsis,
maxLines: 2,
style: const TextStyle(
letterSpacing: 0.52, fontSize: 14),
contentPadding: EdgeInsets.zero,
isThreeLine: true,
),
),
contentPadding: EdgeInsets.zero,
isThreeLine: true,
),
onPressed: () {
if (data.link != null) {
launchUrl(Uri.parse(data.link!));
}
onPressed: () async {
await launchUrl(Uri.parse(data.link!));
},
focusEnabled: true,
cursor: SystemMouseCursors.click,
),
const Divider(),
],
Expand Down
22 changes: 11 additions & 11 deletions lib/pages/downloader.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ import 'package:archive/archive.dart';
import 'package:blinking_text/blinking_text.dart';
import 'package:fluent_ui/fluent_ui.dart';
import 'package:flutter/material.dart' show SnackBarAction;
import 'package:local_notifier/local_notifier.dart';
import 'package:path/path.dart' as p;
import 'package:path_provider/path_provider.dart';
import 'package:percent_indicator/circular_percent_indicator.dart';
import 'package:sentry_flutter/sentry_flutter.dart';
import 'package:tray_manager/tray_manager.dart' as tray;
import 'package:win_toast/win_toast.dart';
import 'package:window_manager/window_manager.dart';

import '../main.dart';
Expand Down Expand Up @@ -41,11 +41,11 @@ class DownloaderState extends State<Downloader>
}

Future<void> downloadUpdate() async {
await winToast.showToast(
type: ToastType.text04,
title: 'Updating WTNews...',
subtitle:
'WTNews is downloading update, please do not close the application');
LocalNotification(
title: 'Updating WTNews...',
body:
'WTNews is downloading update, please do not close the application')
.show();
await windowManager.setMinimumSize(const Size(230, 300));
await windowManager.setMaximumSize(const Size(600, 600));
await windowManager.setSize(const Size(230, 300));
Expand Down Expand Up @@ -94,11 +94,11 @@ class DownloaderState extends State<Downloader>
'installer.bat'
]));

await winToast.showToast(
type: ToastType.text04,
title: 'Update process starting in a moment',
subtitle:
'Do not close the application until the update process is finished');
LocalNotification(
title: 'Update process starting in a moment',
body:
'Do not close the application until the update process is finished')
.show();
text = 'Installing';
setState(() {});
await Process.run(installer, [tempWtnews.path],
Expand Down
Loading

0 comments on commit ebb40c4

Please sign in to comment.