Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/ISSUE_TEMPLATE/bug_report.yml
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ body:
- Gluetun
- AdGuard Home
- Cleanuparr
- Gotify
- Unraid
- Something else
validations:
Expand Down
Binary file added app/assets/service_icons/gotify.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 8 additions & 0 deletions app/lib/src/dashboard/dashboard_board.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import 'package:service_adguard_home/service_adguard_home.dart';
import 'package:service_dashdot/service_dashdot.dart';
import 'package:service_emby/service_emby.dart' as emby;
import 'package:service_glances/service_glances.dart';
import 'package:service_gotify/service_gotify.dart';
import 'package:service_jellyfin/service_jellyfin.dart' as jf;
import 'package:service_deluge/service_deluge.dart';
import 'package:service_nzbget/service_nzbget.dart';
Expand Down Expand Up @@ -37,6 +38,7 @@ import 'widgets/cleanuparr_widget.dart';
import 'widgets/dashdot_widget.dart';
import 'widgets/downloads_widget.dart';
import 'widgets/gluetun_status_widget.dart';
import 'widgets/gotify_widget.dart';
import 'widgets/myspeed_widget.dart';
import 'widgets/recently_added_widget.dart';
import 'widgets/recently_downloaded_widget.dart';
Expand Down Expand Up @@ -218,6 +220,10 @@ class DashboardBoard extends ConsumerWidget {
return DashboardCleanuparrWidget(
instances: _byKind(instances, ServiceKind.cleanuparr),
);
case DashboardWidgetKind.gotify:
return DashboardGotifyWidget(
instances: _byKind(instances, ServiceKind.gotify),
);
case DashboardWidgetKind.wakeOnLan:
return const DashboardWakeOnLanWidget();
}
Expand Down Expand Up @@ -295,6 +301,8 @@ class DashboardBoard extends ConsumerWidget {
ref.invalidate(cleanuparrStrikesProvider(i));
ref.invalidate(cleanuparrStrikesCountProvider(i));
ref.invalidate(cleanuparrJobsProvider(i));
case ServiceKind.gotify:
ref.invalidate(gotifyMessagesProvider((instance: i, appId: null)));
case ServiceKind.slskd:
ref.invalidate(slskdDownloadsProvider(i));
ref.invalidate(slskdUploadsProvider(i));
Expand Down
4 changes: 4 additions & 0 deletions app/lib/src/dashboard/dashboard_widget_kind.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ enum DashboardWidgetKind {
adguardHome,
wakeOnLan,
cleanuparr,
gotify,
}

extension DashboardWidgetKindX on DashboardWidgetKind {
Expand All @@ -35,6 +36,7 @@ extension DashboardWidgetKindX on DashboardWidgetKind {
DashboardWidgetKind.adguardHome => 'AdGuard Home',
DashboardWidgetKind.wakeOnLan => 'Wake on LAN',
DashboardWidgetKind.cleanuparr => 'Cleanuparr',
DashboardWidgetKind.gotify => 'Gotify',
};

IconData get icon => switch (this) {
Expand All @@ -52,6 +54,7 @@ extension DashboardWidgetKindX on DashboardWidgetKind {
DashboardWidgetKind.adguardHome => Icons.gpp_good_outlined,
DashboardWidgetKind.wakeOnLan => Icons.power_settings_new_rounded,
DashboardWidgetKind.cleanuparr => Icons.cleaning_services_outlined,
DashboardWidgetKind.gotify => Icons.notifications_active_outlined,
};

/// Service kinds whose presence makes this widget "configured".
Expand Down Expand Up @@ -108,6 +111,7 @@ extension DashboardWidgetKindX on DashboardWidgetKind {
DashboardWidgetKind.cleanuparr => const <ServiceKind>[
ServiceKind.cleanuparr
],
DashboardWidgetKind.gotify => const <ServiceKind>[ServiceKind.gotify],
// Wake-on-LAN answers to no service. Its targets are machines on the
// network, kept on the profile beside the instances, so there is no
// service whose presence could stand in for being set up.
Expand Down
236 changes: 236 additions & 0 deletions app/lib/src/dashboard/widgets/gotify_widget.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,236 @@
import 'package:core_models/core_models.dart';
import 'package:core_router/core_router.dart';
import 'package:core_ui/core_ui.dart';
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:go_router/go_router.dart';
import 'package:service_gotify/service_gotify.dart';

import '../dashboard_widget_card.dart';
import '../dashboard_widget_kind.dart';

/// Compact dashboard widget for Gotify.
///
/// Shows how many messages are on the server, how many of them are high
/// priority, and the newest message.
class DashboardGotifyWidget extends StatelessWidget {
const DashboardGotifyWidget({
required this.instances,
super.key,
});

final List<Instance> instances;

@override
Widget build(BuildContext context) {
final Color accent = ServiceVisuals.accent(ServiceKind.gotify);

return DashboardWidgetCard(
kind: DashboardWidgetKind.gotify,
accent: accent,
onTap:
instances.length == 1 ? () => _open(context, instances.first) : null,
child: instances.isEmpty
? const DashboardIdleRow(text: 'No Gotify instances configured')
: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
for (int index = 0; index < instances.length; index++) ...<Widget>[
if (index > 0) const Divider(height: Insets.lg),
_GotifyInstanceBlock(
instance: instances[index],
showName: instances.length > 1,
onTap: instances.length > 1
? () => _open(context, instances[index])
: null,
),
],
],
),
);
}

void _open(BuildContext context, Instance instance) {
context.go(
AtriumRoutes.servicePath(instance.kind.name, instance.id),
);
}
}

class _GotifyInstanceBlock extends ConsumerWidget {
const _GotifyInstanceBlock({
required this.instance,
required this.showName,
required this.onTap,
});

final Instance instance;
final bool showName;
final VoidCallback? onTap;

@override
Widget build(BuildContext context, WidgetRef ref) {
final ColorScheme colorScheme = Theme.of(context).colorScheme;
final TextTheme textTheme = Theme.of(context).textTheme;
// Unfiltered: an application picked on the Gotify screen is not the card's.
final GotifyFeedKey key = (instance: instance, appId: null);
final AsyncValue<GotifyMessageFeed> feedAsync =
ref.watch(gotifyMessagesProvider(key));

final Widget content = Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
if (showName) ...<Widget>[
Text(
instance.name,
style: textTheme.labelMedium?.copyWith(
fontWeight: FontWeight.bold,
color: colorScheme.onSurfaceVariant,
),
),
const SizedBox(height: Insets.xs),
],
feedAsync.when(
skipLoadingOnReload: true,
skipLoadingOnRefresh: true,
loading: () => const Padding(
padding: EdgeInsets.symmetric(vertical: Insets.sm),
child: SizedBox(
height: 20,
width: 20,
child: ExpressiveProgressIndicator(strokeWidth: 2),
),
),
error: (err, _) => DashboardErrorRow(
onRetry: () => ref.invalidate(gotifyMessagesProvider(key)),
),
data: (GotifyMessageFeed feed) => _GotifyContent(feed: feed),
),
],
);

if (onTap == null) return content;

return InkWell(
onTap: onTap,
borderRadius: Radii.card,
child: content,
);
}
}

class _GotifyContent extends StatelessWidget {
const _GotifyContent({required this.feed});

final GotifyMessageFeed feed;

@override
Widget build(BuildContext context) {
final ColorScheme colorScheme = Theme.of(context).colorScheme;
final TextTheme textTheme = Theme.of(context).textTheme;
final List<GotifyMessage> messages = feed.messages;

if (messages.isEmpty) {
return const DashboardIdleRow(text: 'No messages');
}

final GotifyMessage newest = messages.first;
final int highPriority = messages
.where((GotifyMessage m) => m.level == GotifyPriority.high)
.length;
final String title = newest.title?.trim().isNotEmpty == true
? newest.title!.trim()
: newest.message;

return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Wrap(
spacing: Insets.xs,
runSpacing: Insets.xs,
children: <Widget>[
_MiniStatPill(
icon: Icons.notifications_outlined,
label: feed.hasMore
? '${messages.length}+ messages'
: '${messages.length} messages',
color: colorScheme.surfaceContainerHighest,
textColor: colorScheme.onSurfaceVariant,
),
_MiniStatPill(
icon: Icons.priority_high_rounded,
label: feed.hasMore
? '$highPriority+ high priority'
: '$highPriority high priority',
color: highPriority > 0
? colorScheme.errorContainer
: colorScheme.surfaceContainerHighest,
textColor: highPriority > 0
? colorScheme.onErrorContainer
: colorScheme.onSurfaceVariant,
),
],
),
const SizedBox(height: Insets.sm),
Text(
title,
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: textTheme.bodyMedium?.copyWith(fontWeight: FontWeight.w600),
),
if (newest.date != null)
Text(
gotifyRelativeTime(newest.date!, DateTime.now()),
style: textTheme.bodySmall?.copyWith(
color: colorScheme.onSurfaceVariant,
),
),
],
);
}
}

class _MiniStatPill extends StatelessWidget {
const _MiniStatPill({
required this.icon,
required this.label,
required this.color,
required this.textColor,
});

final IconData icon;
final String label;
final Color color;
final Color textColor;

@override
Widget build(BuildContext context) {
final TextTheme textTheme = Theme.of(context).textTheme;

return Container(
padding: const EdgeInsets.symmetric(
horizontal: Insets.xs + 2,
vertical: Insets.xxs,
),
decoration: BoxDecoration(
color: color,
borderRadius: Radii.chip,
),
child: Row(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
Icon(icon, size: 12, color: textColor),
const SizedBox(width: Insets.xxs + 1),
Text(
label,
style: textTheme.labelSmall?.copyWith(
color: textColor,
fontSize: 11,
fontWeight: FontWeight.w600,
),
),
],
),
);
}
}
23 changes: 22 additions & 1 deletion app/lib/src/screens/instance_form_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -666,7 +666,8 @@ class _InstanceFormScreenState extends ConsumerState<InstanceFormScreen> {
_kind == ServiceKind.dashdot ||
_kind == ServiceKind.gluetun ||
_kind == ServiceKind.qbittorrent ||
_kind == ServiceKind.slskd) ...<Widget>[
_kind == ServiceKind.slskd ||
_kind == ServiceKind.gotify) ...<Widget>[
const SizedBox(height: Insets.md),
TextFormField(
controller: _pollingInterval,
Expand Down Expand Up @@ -924,6 +925,26 @@ class _InstanceFormScreenState extends ConsumerState<InstanceFormScreen> {
),
];
}
if (_kind == ServiceKind.gotify) {
return <Widget>[
TextFormField(
controller: _apiKey,
decoration: const InputDecoration(
border: OutlineInputBorder(),
labelText: 'Client token',
helperText: 'Create one under Clients in Gotify. An app '
'token can only send messages, not read them.',
helperMaxLines: 2,
),
obscureText: true,
autocorrect: false,
enableSuggestions: false,
onChanged: _clearConnectionTest,
validator: (String? v) =>
(v == null || v.trim().isEmpty) ? 'Required' : null,
),
];
}
// Gluetun's control server and slskd can run without auth, through a role with
// auth = "none" or SLSKD_NO_AUTH=true, and then there is no key to give.
final bool keyOptional =
Expand Down
2 changes: 2 additions & 0 deletions app/lib/src/screens/service_detail_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import 'package:service_qbittorrent/service_qbittorrent.dart';
import 'package:service_radarr/service_radarr.dart';
import 'package:service_sabnzbd/service_sabnzbd.dart';
import 'package:service_glances/service_glances.dart';
import 'package:service_gotify/service_gotify.dart';
import 'package:service_beszel/service_beszel.dart';
import 'package:service_sonarr/service_sonarr.dart';
import 'package:service_speedtest_tracker/service_speedtest_tracker.dart';
Expand Down Expand Up @@ -416,6 +417,7 @@ class _ServiceDetailScreenState extends ConsumerState<ServiceDetailScreen> {
ServiceKind.cleanuparr => const SizedBox.shrink(),
// Owns its own scaffold, handled above.
ServiceKind.slskd => const SizedBox.shrink(),
ServiceKind.gotify => GotifyHome(instance: instance),
};
}
}
Expand Down
1 change: 1 addition & 0 deletions app/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ dependencies:
service_sabnzbd:
service_sonarr:
service_glances:
service_gotify:
service_beszel:
service_dashdot:
service_speedtest_tracker:
Expand Down
18 changes: 18 additions & 0 deletions app/test/gotify_brand_icon_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import 'package:core_models/core_models.dart';
import 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.dart';

/// Gotify has its own icon in the service picker.
///
/// The picker loads `assets/service_icons/<kind>.png` and falls back to a
/// generic icon when there is none.
void main() {
TestWidgetsFlutterBinding.ensureInitialized();

test('the icon the picker asks for is bundled', () async {
final ByteData icon = await rootBundle
.load('assets/service_icons/${ServiceKind.gotify.name}.png');

expect(icon.lengthInBytes, greaterThan(0));
});
}
Loading
Loading