Skip to content
Open
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
3 changes: 2 additions & 1 deletion commet/lib/client/alert.dart
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import 'package:commet/utils/notifying_list.dart';
import 'package:flutter/widgets.dart';

enum AlertType { info, warning, critical }

class Alert {
late String Function() _messageGetter;
late String Function() _titleGetter;
late Function()? action;
late Function(BuildContext context)? action;
AlertType type;

String get title => _titleGetter();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class NotificationManager {
messageGetter: () =>
"The last attempt to start the notification updating service failed. Push notifications will not be updated in the background until this is resolved. Tap for more info",
titleGetter: () => "Couldn't update notifications in background",
action: () => LinkUtils.open(Uri.parse(
action: (_) => LinkUtils.open(Uri.parse(
"https://commet.chat/troubleshoot/android-background-service-failed/")),
);

Expand Down
6 changes: 6 additions & 0 deletions commet/lib/config/build_config.dart
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,12 @@ class BuildConfig {

static Uri donationRewardsApiHost = Uri.https("stripe-rewards.commet.chat");

static const String _BUILD_DATE =
String.fromEnvironment('BUILD_DATE', defaultValue: "0");

static DateTime get BUILD_DATE =>
DateTime.fromMillisecondsSinceEpoch(int.parse(_BUILD_DATE));

// IM SO SORRY
static const String appName = MOBILE
? (ANDROID
Expand Down
7 changes: 7 additions & 0 deletions commet/lib/config/preferences.dart
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ class Preferences {

static const String _hideRoomSidePanel = "hide_room_side_panel";

static const String _checkForUpdates = "check_for_updates";
static const String _runningDonationCheckFlow = "running_donation_check_flow";

final StreamController _onSettingChanged = StreamController.broadcast();
Expand Down Expand Up @@ -474,6 +475,12 @@ class Preferences {
_onSettingChanged.add(null);
}

bool? get checkForUpdates => _preferences!.getBool(_checkForUpdates);

Future<void> setCheckForUpdates(bool value) async {
await _preferences!.setBool(_checkForUpdates, value);
}

(String, DateTime)? get runningDonationCheckFlow {
var result = _preferences!.getString(_runningDonationCheckFlow);

Expand Down
8 changes: 8 additions & 0 deletions commet/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,17 @@ import 'package:commet/ui/pages/bubble/bubble_page.dart';
import 'package:commet/ui/pages/fatal_error/fatal_error_page.dart';
import 'package:commet/ui/pages/login/login_page.dart';
import 'package:commet/ui/pages/main/main_page.dart';
import 'package:commet/ui/pages/setup/menus/check_for_updates.dart';
import 'package:commet/utils/android_intent_helper.dart';
import 'package:commet/utils/custom_uri.dart';
import 'package:commet/utils/background_tasks/background_task_manager.dart';
import 'package:commet/utils/database/database_server.dart';
import 'package:commet/utils/emoji/unicode_emoji.dart';
import 'package:commet/utils/event_bus.dart';
import 'package:commet/utils/first_time_setup.dart';
import 'package:commet/utils/scaled_app.dart';
import 'package:commet/utils/shortcuts_manager.dart';
import 'package:commet/utils/update_checker.dart';
import 'package:commet/utils/window_management.dart';
import 'package:device_info_plus/device_info_plus.dart';
import 'package:flutter/foundation.dart';
Expand Down Expand Up @@ -251,6 +254,11 @@ Future<void> startGui() async {

var initialTheme = await preferences.resolveTheme();

if (preferences.checkForUpdates == null &&
UpdateChecker.shouldCheckForUpdates) {
FirstTimeSetup.registerPostLoginSetup(UpdateCheckerSetup());
}

runApp(App(
clientManager: clientManager!,
initialTheme: initialTheme,
Expand Down
2 changes: 1 addition & 1 deletion commet/lib/ui/molecules/alert_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class AlertView extends StatelessWidget {
return Material(
color: Colors.transparent,
child: InkWell(
onTap: alert.action,
onTap: alert.action == null ? null : () => alert.action?.call(context),
child: Row(children: [
Padding(
padding: const EdgeInsets.all(8.0),
Expand Down
7 changes: 7 additions & 0 deletions commet/lib/ui/organisms/home_screen/home_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ import 'dart:async';

import 'package:commet/client/client.dart';
import 'package:commet/client/client_manager.dart';
import 'package:commet/main.dart';
import 'package:commet/ui/organisms/invitation_view/incoming_invitations_view.dart';
import 'package:commet/utils/event_bus.dart';
import 'package:commet/ui/organisms/home_screen/home_screen_view.dart';
import 'package:commet/utils/update_checker.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';

Expand All @@ -28,6 +30,11 @@ class _HomeScreenState extends State<HomeScreen> {
@override
void initState() {
syncSub = widget.clientManager.onSync.stream.listen(onSync);

if (preferences.checkForUpdates == true) {
UpdateChecker.checkForUpdates();
}

updateRecent();
super.initState();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import 'package:flutter/material.dart' as m;
import 'package:tiamat/tiamat.dart' as tiamat;

import 'package:vodozemac/vodozemac.dart' as vod;
import 'package:intl/intl.dart' as intl;

class SettingsCategoryAbout implements SettingsCategory {
String get labelSettingsAppLogs => Intl.message("Logs",
Expand Down Expand Up @@ -142,6 +143,9 @@ class _AppInfoState extends State<_AppInfo> {
BuildConfig.VERSION_TAG),
tiamat.Text.labelLow(
"${BuildConfig.GIT_HASH.substring(0, 7)} ${BuildConfig.BUILD_DETAIL}"),
tiamat.Text.labelLow("Built: " +
intl.DateFormat(intl.DateFormat.YEAR_MONTH_DAY)
.format(BuildConfig.BUILD_DATE)),
if (deviceInfo != null)
Row(
children: [
Expand Down Expand Up @@ -214,7 +218,7 @@ Platform: `${BuildConfig.PLATFORM}`
Version: `${BuildConfig.VERSION_TAG}`
Git Hash: `${BuildConfig.GIT_HASH}`
Detail: `${BuildConfig.BUILD_DETAIL}`

Build Timestamp: `${BuildConfig.BUILD_DATE.millisecondsSinceEpoch} (${intl.DateFormat(intl.DateFormat.YEAR_MONTH_DAY).format(BuildConfig.BUILD_DATE)})`

**System Info**
${deviceInfo?.data["name"] is String ? "Name: `${deviceInfo!.data["name"]}`" : ""}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import 'package:commet/main.dart';
import 'package:commet/ui/pages/setup/menus/check_for_updates.dart';
import 'package:commet/utils/update_checker.dart';
import 'package:flutter/widgets.dart';
import 'package:intl/intl.dart';

Expand Down Expand Up @@ -127,6 +129,8 @@ class GeneralSettingsPageState extends State<GeneralSettingsPage> {
});
},
),
if (UpdateChecker.shouldCheckForUpdates)
CheckForUpdatesSettingWidget(),
]),
),
const SizedBox(
Expand Down
75 changes: 75 additions & 0 deletions commet/lib/ui/pages/setup/menus/check_for_updates.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import 'dart:async';

import 'package:commet/main.dart';
import 'package:commet/ui/pages/settings/categories/app/general_settings_page.dart';
import 'package:commet/ui/pages/setup/setup_menu.dart';
import 'package:flutter/material.dart';
import 'package:tiamat/tiamat.dart' as tiamat;

class UpdateCheckerSetup implements SetupMenu {
StreamController<SetupMenuState> controller = StreamController();

GlobalKey key = GlobalKey();

@override
Widget builder(BuildContext context) {
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
tiamat.Text.largeTitle("Check for updates"),
tiamat.Text.label(
"Would you like Commet to automatically check for new updates?"),
Padding(
padding: const EdgeInsets.all(8.0),
child: Container(
decoration: BoxDecoration(
color: ColorScheme.of(context).surfaceContainerLowest,
borderRadius: BorderRadius.circular(8),
),
child: Padding(
padding: const EdgeInsets.all(8.0),
child: CheckForUpdatesSettingWidget(),
)),
),
],
);
}

@override
Stream<SetupMenuState> get onStateChanged => controller.stream;

@override
SetupMenuState state = SetupMenuState.canProgress;

@override
Future<void> submit() async {
if (preferences.checkForUpdates == null) {
preferences.setCheckForUpdates(false);
}
}
}

class CheckForUpdatesSettingWidget extends StatefulWidget {
const CheckForUpdatesSettingWidget({super.key});

@override
State<CheckForUpdatesSettingWidget> createState() =>
_CheckForUpdatesSettingWidgetState();
}

class _CheckForUpdatesSettingWidgetState
extends State<CheckForUpdatesSettingWidget> {
@override
Widget build(BuildContext context) {
return GeneralSettingsPageState.settingToggle(
preferences.checkForUpdates ?? false,
title: "Check for updates",
description:
"Automatically check if there is a newer version of Commet available",
onChanged: (v) {
preferences.setCheckForUpdates(v);
setState(() {});
},
);
}
}
6 changes: 0 additions & 6 deletions commet/lib/ui/pages/setup/setup_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ import 'package:commet/config/build_config.dart';
import 'package:commet/ui/atoms/scaled_safe_area.dart';
import 'package:commet/ui/pages/setup/setup_menu.dart';
import 'package:flutter/material.dart';
import 'package:intl/intl.dart';

import 'package:tiamat/tiamat.dart';
import 'package:tiamat/tiamat.dart' as tiamat;

Expand All @@ -19,9 +17,6 @@ class _SetupPageState extends State<SetupPage> {
int currentMenuIndex = 0;
late SetupMenu currentMenu;

String get setupPageBeforeYouBegin => Intl.message("Before you begin...",
name: "setupPageBeforeYouBegin", desc: "Title for first time setup page");

@override
void initState() {
super.initState();
Expand All @@ -40,7 +35,6 @@ class _SetupPageState extends State<SetupPage> {
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisSize: MainAxisSize.max,
children: [
tiamat.Text.largeTitle(setupPageBeforeYouBegin),
Flexible(
child: ClipRRect(
borderRadius: BorderRadius.circular(10),
Expand Down
Loading