Skip to content

Commit

Permalink
feat: add option to open url with internal browser
Browse files Browse the repository at this point in the history
  • Loading branch information
poppingmoon committed Jun 29, 2024
1 parent 6ce46b5 commit 875cdac
Show file tree
Hide file tree
Showing 44 changed files with 194 additions and 121 deletions.
1 change: 1 addition & 0 deletions lib/i18n/aria/aria.i18n.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -125,3 +125,4 @@ userSaysSomething(rich): "{name} said something"
userSaysSomethingSensitive(rich): "Post by {name} contains sensitive content"
vibrateNote: "Vibrate on new note"
vibrateNotification: "Vibrate on new notification"
webBrowser: "Web browser"
1 change: 1 addition & 0 deletions lib/i18n/aria/aria_ja-JP.i18n.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -121,3 +121,4 @@ userSaysSomething(rich): "{name}が何かを言いました"
userSaysSomethingSensitive(rich): "{name}のセンシティブなファイルを含む投稿"
vibrateNote: "ノートを受信したときに振動する"
vibrateNotification: "通知を受信したときに振動する"
webBrowser: "ウェブブラウザ"
1 change: 1 addition & 0 deletions lib/i18n/aria/aria_ja-KS.i18n.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -121,3 +121,4 @@ userSaysSomething(rich): "{name}が何か言うとるわ"
userSaysSomethingSensitive(rich): "{name}のセンシティブなファイルを含む投稿"
vibrateNote: "ノートを受信したときに振動する"
vibrateNotification: "通知を受信したときに振動する"
webBrowser: "ウェブブラウザ"
2 changes: 1 addition & 1 deletion lib/i18n/strings.g.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
/// To regenerate, run: `dart run slang`
///
/// Locales: 31
/// Strings: 51591 (1664 per locale)
/// Strings: 51594 (1664 per locale)
// coverage:ignore-file
// ignore_for_file: type=lint
Expand Down
1 change: 1 addition & 0 deletions lib/i18n/strings_en_US.g.dart
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ class _StringsAriaEnUs {
]);
String get vibrateNote => 'Vibrate on new note';
String get vibrateNotification => 'Vibrate on new notification';
String get webBrowser => 'Web browser';
}

// Path: misskey
Expand Down
1 change: 1 addition & 0 deletions lib/i18n/strings_ja_JP.g.dart
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ class _StringsAriaJaJp extends _StringsAriaEnUs {
]);
@override String get vibrateNote => 'ノートを受信したときに振動する';
@override String get vibrateNotification => '通知を受信したときに振動する';
@override String get webBrowser => 'ウェブブラウザ';
}

// Path: misskey
Expand Down
1 change: 1 addition & 0 deletions lib/i18n/strings_ja_KS.g.dart
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ class _StringsAriaJaKs extends _StringsAriaEnUs {
]);
@override String get vibrateNote => 'ノートを受信したときに振動する';
@override String get vibrateNotification => '通知を受信したときに振動する';
@override String get webBrowser => 'ウェブブラウザ';
}

// Path: misskey
Expand Down
2 changes: 2 additions & 0 deletions lib/model/general_settings.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'package:flutter/material.dart';
import 'package:freezed_annotation/freezed_annotation.dart';
import 'package:url_launcher/url_launcher.dart';

import '../i18n/strings.g.dart';

Expand Down Expand Up @@ -104,6 +105,7 @@ class GeneralSettings with _$GeneralSettings {
@Default(true) bool confirmBeforePost,
@Default(true) bool confirmBeforeReact,
@Default(true) bool confirmBeforeFollow,
@Default(LaunchMode.externalApplication) LaunchMode launchMode,

// Theme
@Default(ThemeMode.system) ThemeMode themeMode,
Expand Down
26 changes: 24 additions & 2 deletions lib/model/general_settings.freezed.dart
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,8 @@ mixin _$GeneralSettings {
NoteActionType get noteLongPressAction => throw _privateConstructorUsedError;
bool get confirmBeforePost => throw _privateConstructorUsedError;
bool get confirmBeforeReact => throw _privateConstructorUsedError;
bool get confirmBeforeFollow => throw _privateConstructorUsedError; // Theme
bool get confirmBeforeFollow => throw _privateConstructorUsedError;
LaunchMode get launchMode => throw _privateConstructorUsedError; // Theme
ThemeMode get themeMode => throw _privateConstructorUsedError;
String get lightThemeId => throw _privateConstructorUsedError;
String get darkThemeId => throw _privateConstructorUsedError;
Expand Down Expand Up @@ -175,6 +176,7 @@ abstract class $GeneralSettingsCopyWith<$Res> {
bool confirmBeforePost,
bool confirmBeforeReact,
bool confirmBeforeFollow,
LaunchMode launchMode,
ThemeMode themeMode,
String lightThemeId,
String darkThemeId});
Expand Down Expand Up @@ -256,6 +258,7 @@ class _$GeneralSettingsCopyWithImpl<$Res, $Val extends GeneralSettings>
Object? confirmBeforePost = null,
Object? confirmBeforeReact = null,
Object? confirmBeforeFollow = null,
Object? launchMode = null,
Object? themeMode = null,
Object? lightThemeId = null,
Object? darkThemeId = null,
Expand Down Expand Up @@ -513,6 +516,10 @@ class _$GeneralSettingsCopyWithImpl<$Res, $Val extends GeneralSettings>
? _value.confirmBeforeFollow
: confirmBeforeFollow // ignore: cast_nullable_to_non_nullable
as bool,
launchMode: null == launchMode
? _value.launchMode
: launchMode // ignore: cast_nullable_to_non_nullable
as LaunchMode,
themeMode: null == themeMode
? _value.themeMode
: themeMode // ignore: cast_nullable_to_non_nullable
Expand Down Expand Up @@ -602,6 +609,7 @@ abstract class _$$GeneralSettingsImplCopyWith<$Res>
bool confirmBeforePost,
bool confirmBeforeReact,
bool confirmBeforeFollow,
LaunchMode launchMode,
ThemeMode themeMode,
String lightThemeId,
String darkThemeId});
Expand Down Expand Up @@ -681,6 +689,7 @@ class __$$GeneralSettingsImplCopyWithImpl<$Res>
Object? confirmBeforePost = null,
Object? confirmBeforeReact = null,
Object? confirmBeforeFollow = null,
Object? launchMode = null,
Object? themeMode = null,
Object? lightThemeId = null,
Object? darkThemeId = null,
Expand Down Expand Up @@ -938,6 +947,10 @@ class __$$GeneralSettingsImplCopyWithImpl<$Res>
? _value.confirmBeforeFollow
: confirmBeforeFollow // ignore: cast_nullable_to_non_nullable
as bool,
launchMode: null == launchMode
? _value.launchMode
: launchMode // ignore: cast_nullable_to_non_nullable
as LaunchMode,
themeMode: null == themeMode
? _value.themeMode
: themeMode // ignore: cast_nullable_to_non_nullable
Expand Down Expand Up @@ -1022,6 +1035,7 @@ class _$GeneralSettingsImpl implements _GeneralSettings {
this.confirmBeforePost = true,
this.confirmBeforeReact = true,
this.confirmBeforeFollow = true,
this.launchMode = LaunchMode.externalApplication,
this.themeMode = ThemeMode.system,
this.lightThemeId = 'a58a0abb-ff8c-476a-8dec-0ad7837e7e96',
this.darkThemeId = '66e7e5a9-cd43-42cd-837d-12f47841fa34'});
Expand Down Expand Up @@ -1223,6 +1237,9 @@ class _$GeneralSettingsImpl implements _GeneralSettings {
@override
@JsonKey()
final bool confirmBeforeFollow;
@override
@JsonKey()
final LaunchMode launchMode;
// Theme
@override
@JsonKey()
Expand All @@ -1236,7 +1253,7 @@ class _$GeneralSettingsImpl implements _GeneralSettings {

@override
String toString() {
return 'GeneralSettings(locale: $locale, collapseRenotes: $collapseRenotes, sensitive: $sensitive, highlightSensitiveMedia: $highlightSensitiveMedia, animatedMfm: $animatedMfm, advancedMfm: $advancedMfm, showReactionsCount: $showReactionsCount, loadRawImages: $loadRawImages, instanceTicker: $instanceTicker, showNoteCreatedAt: $showNoteCreatedAt, showAvatarsInNote: $showAvatarsInNote, showAvatarsInSubNote: $showAvatarsInSubNote, squareAvatars: $squareAvatars, showAvatarDecorations: $showAvatarDecorations, showQuoteButtonInNoteFooter: $showQuoteButtonInNoteFooter, showLikeButtonInNoteFooter: $showLikeButtonInNoteFooter, showClipButtonInNoteFooter: $showClipButtonInNoteFooter, showTranslateButtonInNoteFooter: $showTranslateButtonInNoteFooter, showNoteReactionsViewer: $showNoteReactionsViewer, showSubNoteReactionsViewer: $showSubNoteReactionsViewer, showNoteFooter: $showNoteFooter, showSubNoteFooter: $showSubNoteFooter, emojiStyle: $emojiStyle, fontFamily: $fontFamily, fontSize: $fontSize, lineHeight: $lineHeight, avatarScale: $avatarScale, reactionsDisplayScale: $reactionsDisplayScale, limitWidthOfReaction: $limitWidthOfReaction, noteFooterScale: $noteFooterScale, noteVerticalPadding: $noteVerticalPadding, noteHorizontalPadding: $noteHorizontalPadding, publicNoteBackgroundColor: $publicNoteBackgroundColor, homeNoteBackgroundColor: $homeNoteBackgroundColor, followersNoteBackgroundColor: $followersNoteBackgroundColor, specifiedNoteBackgroundColor: $specifiedNoteBackgroundColor, emojiPickerUseDialog: $emojiPickerUseDialog, emojiPickerScale: $emojiPickerScale, emojiPickerAutofocus: $emojiPickerAutofocus, emojiPickerKeepOpen: $emojiPickerKeepOpen, dataSaverMedia: $dataSaverMedia, dataSaverAvatar: $dataSaverAvatar, dataSaverUrlPreview: $dataSaverUrlPreview, disableDataSaverWhenOnWifi: $disableDataSaverWhenOnWifi, disableShowingAnimatedImages: $disableShowingAnimatedImages, forceShowAds: $forceShowAds, useGroupedNotifications: $useGroupedNotifications, showTimelineTabBarAtBottom: $showTimelineTabBarAtBottom, showMenuButtonInTabBar: $showMenuButtonInTabBar, alwaysShowTabHeader: $alwaysShowTabHeader, showTimelineLastViewedAt: $showTimelineLastViewedAt, vibrateNote: $vibrateNote, vibrateNotification: $vibrateNotification, enableInfiniteScroll: $enableInfiniteScroll, keepScreenOn: $keepScreenOn, enableHorizontalSwipe: $enableHorizontalSwipe, openSensitiveMediaOnDoubleTap: $openSensitiveMediaOnDoubleTap, noteTapAction: $noteTapAction, noteDoubleTapAction: $noteDoubleTapAction, noteLongPressAction: $noteLongPressAction, confirmBeforePost: $confirmBeforePost, confirmBeforeReact: $confirmBeforeReact, confirmBeforeFollow: $confirmBeforeFollow, themeMode: $themeMode, lightThemeId: $lightThemeId, darkThemeId: $darkThemeId)';
return 'GeneralSettings(locale: $locale, collapseRenotes: $collapseRenotes, sensitive: $sensitive, highlightSensitiveMedia: $highlightSensitiveMedia, animatedMfm: $animatedMfm, advancedMfm: $advancedMfm, showReactionsCount: $showReactionsCount, loadRawImages: $loadRawImages, instanceTicker: $instanceTicker, showNoteCreatedAt: $showNoteCreatedAt, showAvatarsInNote: $showAvatarsInNote, showAvatarsInSubNote: $showAvatarsInSubNote, squareAvatars: $squareAvatars, showAvatarDecorations: $showAvatarDecorations, showQuoteButtonInNoteFooter: $showQuoteButtonInNoteFooter, showLikeButtonInNoteFooter: $showLikeButtonInNoteFooter, showClipButtonInNoteFooter: $showClipButtonInNoteFooter, showTranslateButtonInNoteFooter: $showTranslateButtonInNoteFooter, showNoteReactionsViewer: $showNoteReactionsViewer, showSubNoteReactionsViewer: $showSubNoteReactionsViewer, showNoteFooter: $showNoteFooter, showSubNoteFooter: $showSubNoteFooter, emojiStyle: $emojiStyle, fontFamily: $fontFamily, fontSize: $fontSize, lineHeight: $lineHeight, avatarScale: $avatarScale, reactionsDisplayScale: $reactionsDisplayScale, limitWidthOfReaction: $limitWidthOfReaction, noteFooterScale: $noteFooterScale, noteVerticalPadding: $noteVerticalPadding, noteHorizontalPadding: $noteHorizontalPadding, publicNoteBackgroundColor: $publicNoteBackgroundColor, homeNoteBackgroundColor: $homeNoteBackgroundColor, followersNoteBackgroundColor: $followersNoteBackgroundColor, specifiedNoteBackgroundColor: $specifiedNoteBackgroundColor, emojiPickerUseDialog: $emojiPickerUseDialog, emojiPickerScale: $emojiPickerScale, emojiPickerAutofocus: $emojiPickerAutofocus, emojiPickerKeepOpen: $emojiPickerKeepOpen, dataSaverMedia: $dataSaverMedia, dataSaverAvatar: $dataSaverAvatar, dataSaverUrlPreview: $dataSaverUrlPreview, disableDataSaverWhenOnWifi: $disableDataSaverWhenOnWifi, disableShowingAnimatedImages: $disableShowingAnimatedImages, forceShowAds: $forceShowAds, useGroupedNotifications: $useGroupedNotifications, showTimelineTabBarAtBottom: $showTimelineTabBarAtBottom, showMenuButtonInTabBar: $showMenuButtonInTabBar, alwaysShowTabHeader: $alwaysShowTabHeader, showTimelineLastViewedAt: $showTimelineLastViewedAt, vibrateNote: $vibrateNote, vibrateNotification: $vibrateNotification, enableInfiniteScroll: $enableInfiniteScroll, keepScreenOn: $keepScreenOn, enableHorizontalSwipe: $enableHorizontalSwipe, openSensitiveMediaOnDoubleTap: $openSensitiveMediaOnDoubleTap, noteTapAction: $noteTapAction, noteDoubleTapAction: $noteDoubleTapAction, noteLongPressAction: $noteLongPressAction, confirmBeforePost: $confirmBeforePost, confirmBeforeReact: $confirmBeforeReact, confirmBeforeFollow: $confirmBeforeFollow, launchMode: $launchMode, themeMode: $themeMode, lightThemeId: $lightThemeId, darkThemeId: $darkThemeId)';
}

@override
Expand Down Expand Up @@ -1337,6 +1354,7 @@ class _$GeneralSettingsImpl implements _GeneralSettings {
(identical(other.confirmBeforePost, confirmBeforePost) || other.confirmBeforePost == confirmBeforePost) &&
(identical(other.confirmBeforeReact, confirmBeforeReact) || other.confirmBeforeReact == confirmBeforeReact) &&
(identical(other.confirmBeforeFollow, confirmBeforeFollow) || other.confirmBeforeFollow == confirmBeforeFollow) &&
(identical(other.launchMode, launchMode) || other.launchMode == launchMode) &&
(identical(other.themeMode, themeMode) || other.themeMode == themeMode) &&
(identical(other.lightThemeId, lightThemeId) || other.lightThemeId == lightThemeId) &&
(identical(other.darkThemeId, darkThemeId) || other.darkThemeId == darkThemeId));
Expand Down Expand Up @@ -1409,6 +1427,7 @@ class _$GeneralSettingsImpl implements _GeneralSettings {
confirmBeforePost,
confirmBeforeReact,
confirmBeforeFollow,
launchMode,
themeMode,
lightThemeId,
darkThemeId
Expand Down Expand Up @@ -1495,6 +1514,7 @@ abstract class _GeneralSettings implements GeneralSettings {
final bool confirmBeforePost,
final bool confirmBeforeReact,
final bool confirmBeforeFollow,
final LaunchMode launchMode,
final ThemeMode themeMode,
final String lightThemeId,
final String darkThemeId}) = _$GeneralSettingsImpl;
Expand Down Expand Up @@ -1634,6 +1654,8 @@ abstract class _GeneralSettings implements GeneralSettings {
bool get confirmBeforeReact;
@override
bool get confirmBeforeFollow;
@override
LaunchMode get launchMode;
@override // Theme
ThemeMode get themeMode;
@override
Expand Down
12 changes: 12 additions & 0 deletions lib/model/general_settings.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions lib/provider/general_settings_notifier_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'dart:convert';

import 'package:flutter/material.dart';
import 'package:riverpod_annotation/riverpod_annotation.dart';
import 'package:url_launcher/url_launcher.dart';

import '../i18n/strings.g.dart';
import '../model/general_settings.dart';
Expand Down Expand Up @@ -403,6 +404,11 @@ class GeneralSettingsNotifier extends _$GeneralSettingsNotifier {
await _save();
}

Future<void> setLaunchMode(LaunchMode launchMode) async {
state = state.copyWith(launchMode: launchMode);
await _save();
}

Future<void> setThemeMode(ThemeMode themeMode) async {
state = state.copyWith(themeMode: themeMode);
await _save();
Expand Down
2 changes: 1 addition & 1 deletion lib/provider/general_settings_notifier_provider.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions lib/util/launch_url.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:url_launcher/url_launcher.dart' as launcher;

import '../provider/general_settings_notifier_provider.dart';

Future<bool> launchUrl(WidgetRef ref, Uri url) {
return launcher.launchUrl(
url,
mode: ref.read(generalSettingsNotifierProvider).launchMode,
);
}
8 changes: 4 additions & 4 deletions lib/util/navigate.dart
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import 'package:go_router/go_router.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:url_launcher/url_launcher.dart';

import '../model/account.dart';
import '../provider/emojis_notifier_provider.dart';
import 'launch_url.dart';

Future<void> navigate(WidgetRef ref, Account account, String link) async {
final url = Uri.tryParse(link);
Expand All @@ -25,7 +25,7 @@ Future<void> navigate(WidgetRef ref, Account account, String link) async {
if (!ref.context.mounted) return;
await ref.context.push('/${url.host}${url.path}');
} catch (_) {
await launchUrl(url, mode: LaunchMode.externalApplication);
await launchUrl(ref, url);
}
} else {
await ref.context.push('/$account${url.path}');
Expand All @@ -40,13 +40,13 @@ Future<void> navigate(WidgetRef ref, Account account, String link) async {
if (!ref.context.mounted) return;
await ref.context.push('/${url.host}${url.path}');
} catch (_) {
await launchUrl(url, mode: LaunchMode.externalApplication);
await launchUrl(ref, url);
}
} else {
await ref.context.push('/$account${url.path}');
}
} else {
await launchUrl(url, mode: LaunchMode.externalApplication);
await launchUrl(ref, url);
}
}
}
7 changes: 2 additions & 5 deletions lib/view/dialog/paste_emojis_dialog.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import 'package:flutter_hooks/flutter_hooks.dart';
import 'package:go_router/go_router.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:json5/json5.dart';
import 'package:url_launcher/url_launcher.dart';

import '../../constant/shortcuts.dart';
import '../../extension/string_extension.dart';
Expand All @@ -12,6 +11,7 @@ import '../../i18n/strings.g.dart';
import '../../model/account.dart';
import '../../provider/api/endpoints_provider.dart';
import '../../provider/misskey_colors_provider.dart';
import '../../util/launch_url.dart';
import 'message_dialog.dart';

const _sampleEmojis = """
Expand Down Expand Up @@ -64,10 +64,7 @@ class PasteEmojisDialog extends HookConsumerWidget {
text: registryUrl.toString().breakAll,
style: TextStyle(color: colors.link),
recognizer: recognizer
..onTap = () => launchUrl(
registryUrl,
mode: LaunchMode.externalApplication,
),
..onTap = () => launchUrl(ref, registryUrl),
),
),
),
Expand Down
Loading

0 comments on commit 875cdac

Please sign in to comment.