Hide the IPFS API key and keep keyboard focus from corrupting it
Obscure the key with a show/hide toggle like the map API key dialog, clear and restore the mask on focus changes instead of onTap, and only save a key the user actually edited. Add ipfs.io as a named public gateway preset now that it is the default.
This commit is contained in:
1 parent
ee302f647b
commit
7f5f71d070
22 files changed
+117
-10
No files matched your search
@@ -457,6 +457,7 @@
|
||||
"appSettings_ipfsImageLinksSubtitle": "Upload for url Images (or Files) via IPFS provider and default gateway to receive",
|
||||
"appSettings_publicIpfsGateway": "Public gateway",
|
||||
"appSettings_ipfsGatewayDeactivated": "Deactivated",
|
||||
"appSettings_ipfsGatewayIpfsIo": "ipfs.io",
|
||||
"appSettings_ipfsGatewayPinata": "Pinata",
|
||||
"appSettings_ipfsGatewayFilebase": "Filebase",
|
||||
"appSettings_ipfsGatewayCustom": "Custom (Kubo)",
|
||||
|
||||
@@ -1978,6 +1978,12 @@ abstract class AppLocalizations {
|
||||
/// **'Deactivated'**
|
||||
String get appSettings_ipfsGatewayDeactivated;
|
||||
|
||||
/// No description provided for @appSettings_ipfsGatewayIpfsIo.
|
||||
///
|
||||
/// In en, this message translates to:
|
||||
/// **'ipfs.io'**
|
||||
String get appSettings_ipfsGatewayIpfsIo;
|
||||
|
||||
/// No description provided for @appSettings_ipfsGatewayPinata.
|
||||
///
|
||||
/// In en, this message translates to:
|
||||
|
||||
@@ -1089,6 +1089,9 @@ class AppLocalizationsBg extends AppLocalizations {
|
||||
@override
|
||||
String get appSettings_ipfsGatewayDeactivated => 'Deactivated';
|
||||
|
||||
@override
|
||||
String get appSettings_ipfsGatewayIpfsIo => 'ipfs.io';
|
||||
|
||||
@override
|
||||
String get appSettings_ipfsGatewayPinata => 'Pinata';
|
||||
|
||||
|
||||
@@ -1084,6 +1084,9 @@ class AppLocalizationsDe extends AppLocalizations {
|
||||
@override
|
||||
String get appSettings_ipfsGatewayDeactivated => 'Deactivated';
|
||||
|
||||
@override
|
||||
String get appSettings_ipfsGatewayIpfsIo => 'ipfs.io';
|
||||
|
||||
@override
|
||||
String get appSettings_ipfsGatewayPinata => 'Pinata';
|
||||
|
||||
|
||||
@@ -1068,6 +1068,9 @@ class AppLocalizationsEn extends AppLocalizations {
|
||||
@override
|
||||
String get appSettings_ipfsGatewayDeactivated => 'Deactivated';
|
||||
|
||||
@override
|
||||
String get appSettings_ipfsGatewayIpfsIo => 'ipfs.io';
|
||||
|
||||
@override
|
||||
String get appSettings_ipfsGatewayPinata => 'Pinata';
|
||||
|
||||
|
||||
@@ -1081,6 +1081,9 @@ class AppLocalizationsEs extends AppLocalizations {
|
||||
@override
|
||||
String get appSettings_ipfsGatewayDeactivated => 'Deactivated';
|
||||
|
||||
@override
|
||||
String get appSettings_ipfsGatewayIpfsIo => 'ipfs.io';
|
||||
|
||||
@override
|
||||
String get appSettings_ipfsGatewayPinata => 'Pinata';
|
||||
|
||||
|
||||
@@ -1087,6 +1087,9 @@ class AppLocalizationsFr extends AppLocalizations {
|
||||
@override
|
||||
String get appSettings_ipfsGatewayDeactivated => 'Deactivated';
|
||||
|
||||
@override
|
||||
String get appSettings_ipfsGatewayIpfsIo => 'ipfs.io';
|
||||
|
||||
@override
|
||||
String get appSettings_ipfsGatewayPinata => 'Pinata';
|
||||
|
||||
|
||||
@@ -1076,6 +1076,9 @@ class AppLocalizationsHu extends AppLocalizations {
|
||||
@override
|
||||
String get appSettings_ipfsGatewayDeactivated => 'Deactivated';
|
||||
|
||||
@override
|
||||
String get appSettings_ipfsGatewayIpfsIo => 'ipfs.io';
|
||||
|
||||
@override
|
||||
String get appSettings_ipfsGatewayPinata => 'Pinata';
|
||||
|
||||
|
||||
@@ -1087,6 +1087,9 @@ class AppLocalizationsIt extends AppLocalizations {
|
||||
@override
|
||||
String get appSettings_ipfsGatewayDeactivated => 'Deactivated';
|
||||
|
||||
@override
|
||||
String get appSettings_ipfsGatewayIpfsIo => 'ipfs.io';
|
||||
|
||||
@override
|
||||
String get appSettings_ipfsGatewayPinata => 'Pinata';
|
||||
|
||||
|
||||
@@ -1024,6 +1024,9 @@ class AppLocalizationsJa extends AppLocalizations {
|
||||
@override
|
||||
String get appSettings_ipfsGatewayDeactivated => 'Deactivated';
|
||||
|
||||
@override
|
||||
String get appSettings_ipfsGatewayIpfsIo => 'ipfs.io';
|
||||
|
||||
@override
|
||||
String get appSettings_ipfsGatewayPinata => 'Pinata';
|
||||
|
||||
|
||||
@@ -1028,6 +1028,9 @@ class AppLocalizationsKo extends AppLocalizations {
|
||||
@override
|
||||
String get appSettings_ipfsGatewayDeactivated => 'Deactivated';
|
||||
|
||||
@override
|
||||
String get appSettings_ipfsGatewayIpfsIo => 'ipfs.io';
|
||||
|
||||
@override
|
||||
String get appSettings_ipfsGatewayPinata => 'Pinata';
|
||||
|
||||
|
||||
@@ -1077,6 +1077,9 @@ class AppLocalizationsNl extends AppLocalizations {
|
||||
@override
|
||||
String get appSettings_ipfsGatewayDeactivated => 'Deactivated';
|
||||
|
||||
@override
|
||||
String get appSettings_ipfsGatewayIpfsIo => 'ipfs.io';
|
||||
|
||||
@override
|
||||
String get appSettings_ipfsGatewayPinata => 'Pinata';
|
||||
|
||||
|
||||
@@ -1093,6 +1093,9 @@ class AppLocalizationsPl extends AppLocalizations {
|
||||
@override
|
||||
String get appSettings_ipfsGatewayDeactivated => 'Deactivated';
|
||||
|
||||
@override
|
||||
String get appSettings_ipfsGatewayIpfsIo => 'ipfs.io';
|
||||
|
||||
@override
|
||||
String get appSettings_ipfsGatewayPinata => 'Pinata';
|
||||
|
||||
|
||||
@@ -1085,6 +1085,9 @@ class AppLocalizationsPt extends AppLocalizations {
|
||||
@override
|
||||
String get appSettings_ipfsGatewayDeactivated => 'Deactivated';
|
||||
|
||||
@override
|
||||
String get appSettings_ipfsGatewayIpfsIo => 'ipfs.io';
|
||||
|
||||
@override
|
||||
String get appSettings_ipfsGatewayPinata => 'Pinata';
|
||||
|
||||
|
||||
@@ -1090,6 +1090,9 @@ class AppLocalizationsRu extends AppLocalizations {
|
||||
@override
|
||||
String get appSettings_ipfsGatewayDeactivated => 'Deactivated';
|
||||
|
||||
@override
|
||||
String get appSettings_ipfsGatewayIpfsIo => 'ipfs.io';
|
||||
|
||||
@override
|
||||
String get appSettings_ipfsGatewayPinata => 'Pinata';
|
||||
|
||||
|
||||
@@ -1076,6 +1076,9 @@ class AppLocalizationsSk extends AppLocalizations {
|
||||
@override
|
||||
String get appSettings_ipfsGatewayDeactivated => 'Deactivated';
|
||||
|
||||
@override
|
||||
String get appSettings_ipfsGatewayIpfsIo => 'ipfs.io';
|
||||
|
||||
@override
|
||||
String get appSettings_ipfsGatewayPinata => 'Pinata';
|
||||
|
||||
|
||||
@@ -1078,6 +1078,9 @@ class AppLocalizationsSl extends AppLocalizations {
|
||||
@override
|
||||
String get appSettings_ipfsGatewayDeactivated => 'Deactivated';
|
||||
|
||||
@override
|
||||
String get appSettings_ipfsGatewayIpfsIo => 'ipfs.io';
|
||||
|
||||
@override
|
||||
String get appSettings_ipfsGatewayPinata => 'Pinata';
|
||||
|
||||
|
||||
@@ -1067,6 +1067,9 @@ class AppLocalizationsSv extends AppLocalizations {
|
||||
@override
|
||||
String get appSettings_ipfsGatewayDeactivated => 'Deactivated';
|
||||
|
||||
@override
|
||||
String get appSettings_ipfsGatewayIpfsIo => 'ipfs.io';
|
||||
|
||||
@override
|
||||
String get appSettings_ipfsGatewayPinata => 'Pinata';
|
||||
|
||||
|
||||
@@ -1080,6 +1080,9 @@ class AppLocalizationsUk extends AppLocalizations {
|
||||
@override
|
||||
String get appSettings_ipfsGatewayDeactivated => 'Deactivated';
|
||||
|
||||
@override
|
||||
String get appSettings_ipfsGatewayIpfsIo => 'ipfs.io';
|
||||
|
||||
@override
|
||||
String get appSettings_ipfsGatewayPinata => 'Pinata';
|
||||
|
||||
|
||||
@@ -1008,6 +1008,9 @@ class AppLocalizationsZh extends AppLocalizations {
|
||||
@override
|
||||
String get appSettings_ipfsGatewayDeactivated => 'Deactivated';
|
||||
|
||||
@override
|
||||
String get appSettings_ipfsGatewayIpfsIo => 'ipfs.io';
|
||||
|
||||
@override
|
||||
String get appSettings_ipfsGatewayPinata => 'Pinata';
|
||||
|
||||
|
||||
@@ -1526,12 +1526,13 @@ class _IpfsImageLinksDialogState extends State<_IpfsImageLinksDialog> {
|
||||
late final TextEditingController _uploadGatewayController;
|
||||
late final TextEditingController _endpointController;
|
||||
late final TextEditingController _apiKeyController;
|
||||
final FocusNode _apiKeyFocus = FocusNode();
|
||||
late final String _currentApiKey;
|
||||
late final String _maskedApiKey;
|
||||
late String _selectedGateway;
|
||||
late String _selectedUploadProvider;
|
||||
bool _apiKeyEditing = false;
|
||||
bool _apiKeyChanged = false;
|
||||
bool _apiKeyObscured = true;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
@@ -1549,6 +1550,7 @@ class _IpfsImageLinksDialogState extends State<_IpfsImageLinksDialog> {
|
||||
_currentApiKey = settings.uploadIpfsApiKey.trim();
|
||||
_maskedApiKey = _currentApiKey.isEmpty ? '' : _maskApiKey(_currentApiKey);
|
||||
_apiKeyController = TextEditingController(text: _maskedApiKey);
|
||||
_apiKeyFocus.addListener(_onApiKeyFocusChanged);
|
||||
_selectedGateway = _gatewayPreset(_publicController.text);
|
||||
_selectedUploadProvider = _uploadProvider(
|
||||
_uploadGatewayController.text,
|
||||
@@ -1563,9 +1565,18 @@ class _IpfsImageLinksDialogState extends State<_IpfsImageLinksDialog> {
|
||||
_uploadGatewayController.dispose();
|
||||
_endpointController.dispose();
|
||||
_apiKeyController.dispose();
|
||||
_apiKeyFocus.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
/// Swaps the masked key out while the field has focus (by tap, Tab or
|
||||
/// keyboard) so typing never appends to the mask, and puts it back if the
|
||||
/// user leaves without editing.
|
||||
void _onApiKeyFocusChanged() {
|
||||
if (_apiKeyChanged) return;
|
||||
_apiKeyController.text = _apiKeyFocus.hasFocus ? '' : _maskedApiKey;
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final l10n = context.l10n;
|
||||
@@ -1588,6 +1599,10 @@ class _IpfsImageLinksDialogState extends State<_IpfsImageLinksDialog> {
|
||||
value: 'deactivated',
|
||||
child: Text(l10n.appSettings_ipfsGatewayDeactivated),
|
||||
),
|
||||
DropdownMenuItem(
|
||||
value: 'ipfsio',
|
||||
child: Text(l10n.appSettings_ipfsGatewayIpfsIo),
|
||||
),
|
||||
DropdownMenuItem(
|
||||
value: 'pinata',
|
||||
child: Text(l10n.appSettings_ipfsGatewayPinata),
|
||||
@@ -1671,18 +1686,25 @@ class _IpfsImageLinksDialogState extends State<_IpfsImageLinksDialog> {
|
||||
const SizedBox(height: 10),
|
||||
TextField(
|
||||
controller: _apiKeyController,
|
||||
focusNode: _apiKeyFocus,
|
||||
decoration: InputDecoration(
|
||||
labelText: l10n.appSettings_uploadIpfsApiKey,
|
||||
suffixIcon: IconButton(
|
||||
tooltip: _apiKeyObscured
|
||||
? l10n.appSettings_showApiKey
|
||||
: l10n.appSettings_hideApiKey,
|
||||
icon: Icon(
|
||||
_apiKeyObscured
|
||||
? Icons.visibility_outlined
|
||||
: Icons.visibility_off_outlined,
|
||||
),
|
||||
onPressed: () =>
|
||||
setState(() => _apiKeyObscured = !_apiKeyObscured),
|
||||
),
|
||||
),
|
||||
autocorrect: false,
|
||||
enableSuggestions: false,
|
||||
onTap: () {
|
||||
if (_apiKeyEditing) return;
|
||||
setState(() {
|
||||
_apiKeyEditing = true;
|
||||
_apiKeyController.clear();
|
||||
});
|
||||
},
|
||||
obscureText: _apiKeyObscured,
|
||||
onChanged: (_) {
|
||||
_apiKeyChanged = true;
|
||||
_markCustomUploadProvider();
|
||||
@@ -1731,14 +1753,15 @@ class _IpfsImageLinksDialogState extends State<_IpfsImageLinksDialog> {
|
||||
|
||||
Future<void> _save() async {
|
||||
final deactivated = _selectedUploadProvider == 'deactivated';
|
||||
final apiKey = _apiKeyController.text.trim();
|
||||
await widget.settingsService.setIpfsImageSettings(
|
||||
publicGateway: _publicController.text,
|
||||
uploadGateway: deactivated ? '' : _uploadGatewayController.text,
|
||||
uploadEndpoint: deactivated ? '' : _endpointController.text,
|
||||
uploadApiKey: deactivated
|
||||
? ''
|
||||
: _apiKeyChanged
|
||||
? _apiKeyController.text
|
||||
: _apiKeyChanged && apiKey != _maskedApiKey
|
||||
? apiKey
|
||||
: _currentApiKey,
|
||||
);
|
||||
if (mounted) Navigator.pop(context);
|
||||
@@ -1746,6 +1769,10 @@ class _IpfsImageLinksDialogState extends State<_IpfsImageLinksDialog> {
|
||||
|
||||
String _gatewayPreset(String value) {
|
||||
if (value.isEmpty) return 'deactivated';
|
||||
if (value == AppSettings.defaultPublicIpfsGateway ||
|
||||
value == 'https://ipfs.io/ipfs') {
|
||||
return 'ipfsio';
|
||||
}
|
||||
if (value == 'https://gateway.pinata.cloud/ipfs/' ||
|
||||
value == 'https://gateway.pinata.cloud/ipfs') {
|
||||
return 'pinata';
|
||||
@@ -1761,6 +1788,8 @@ class _IpfsImageLinksDialogState extends State<_IpfsImageLinksDialog> {
|
||||
switch (preset) {
|
||||
case 'deactivated':
|
||||
return '';
|
||||
case 'ipfsio':
|
||||
return AppSettings.defaultPublicIpfsGateway;
|
||||
case 'pinata':
|
||||
return 'https://gateway.pinata.cloud/ipfs/';
|
||||
case 'filebase':
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
"appSettings_ipfsImageLinksSubtitle",
|
||||
"appSettings_publicIpfsGateway",
|
||||
"appSettings_ipfsGatewayDeactivated",
|
||||
"appSettings_ipfsGatewayIpfsIo",
|
||||
"appSettings_ipfsGatewayPinata",
|
||||
"appSettings_ipfsGatewayFilebase",
|
||||
"appSettings_ipfsGatewayCustom",
|
||||
@@ -55,6 +56,7 @@
|
||||
"appSettings_ipfsImageLinksSubtitle",
|
||||
"appSettings_publicIpfsGateway",
|
||||
"appSettings_ipfsGatewayDeactivated",
|
||||
"appSettings_ipfsGatewayIpfsIo",
|
||||
"appSettings_ipfsGatewayPinata",
|
||||
"appSettings_ipfsGatewayFilebase",
|
||||
"appSettings_ipfsGatewayCustom",
|
||||
@@ -105,6 +107,7 @@
|
||||
"appSettings_ipfsImageLinksSubtitle",
|
||||
"appSettings_publicIpfsGateway",
|
||||
"appSettings_ipfsGatewayDeactivated",
|
||||
"appSettings_ipfsGatewayIpfsIo",
|
||||
"appSettings_ipfsGatewayPinata",
|
||||
"appSettings_ipfsGatewayFilebase",
|
||||
"appSettings_ipfsGatewayCustom",
|
||||
@@ -155,6 +158,7 @@
|
||||
"appSettings_ipfsImageLinksSubtitle",
|
||||
"appSettings_publicIpfsGateway",
|
||||
"appSettings_ipfsGatewayDeactivated",
|
||||
"appSettings_ipfsGatewayIpfsIo",
|
||||
"appSettings_ipfsGatewayPinata",
|
||||
"appSettings_ipfsGatewayFilebase",
|
||||
"appSettings_ipfsGatewayCustom",
|
||||
@@ -205,6 +209,7 @@
|
||||
"appSettings_ipfsImageLinksSubtitle",
|
||||
"appSettings_publicIpfsGateway",
|
||||
"appSettings_ipfsGatewayDeactivated",
|
||||
"appSettings_ipfsGatewayIpfsIo",
|
||||
"appSettings_ipfsGatewayPinata",
|
||||
"appSettings_ipfsGatewayFilebase",
|
||||
"appSettings_ipfsGatewayCustom",
|
||||
@@ -255,6 +260,7 @@
|
||||
"appSettings_ipfsImageLinksSubtitle",
|
||||
"appSettings_publicIpfsGateway",
|
||||
"appSettings_ipfsGatewayDeactivated",
|
||||
"appSettings_ipfsGatewayIpfsIo",
|
||||
"appSettings_ipfsGatewayPinata",
|
||||
"appSettings_ipfsGatewayFilebase",
|
||||
"appSettings_ipfsGatewayCustom",
|
||||
@@ -305,6 +311,7 @@
|
||||
"appSettings_ipfsImageLinksSubtitle",
|
||||
"appSettings_publicIpfsGateway",
|
||||
"appSettings_ipfsGatewayDeactivated",
|
||||
"appSettings_ipfsGatewayIpfsIo",
|
||||
"appSettings_ipfsGatewayPinata",
|
||||
"appSettings_ipfsGatewayFilebase",
|
||||
"appSettings_ipfsGatewayCustom",
|
||||
@@ -355,6 +362,7 @@
|
||||
"appSettings_ipfsImageLinksSubtitle",
|
||||
"appSettings_publicIpfsGateway",
|
||||
"appSettings_ipfsGatewayDeactivated",
|
||||
"appSettings_ipfsGatewayIpfsIo",
|
||||
"appSettings_ipfsGatewayPinata",
|
||||
"appSettings_ipfsGatewayFilebase",
|
||||
"appSettings_ipfsGatewayCustom",
|
||||
@@ -405,6 +413,7 @@
|
||||
"appSettings_ipfsImageLinksSubtitle",
|
||||
"appSettings_publicIpfsGateway",
|
||||
"appSettings_ipfsGatewayDeactivated",
|
||||
"appSettings_ipfsGatewayIpfsIo",
|
||||
"appSettings_ipfsGatewayPinata",
|
||||
"appSettings_ipfsGatewayFilebase",
|
||||
"appSettings_ipfsGatewayCustom",
|
||||
@@ -455,6 +464,7 @@
|
||||
"appSettings_ipfsImageLinksSubtitle",
|
||||
"appSettings_publicIpfsGateway",
|
||||
"appSettings_ipfsGatewayDeactivated",
|
||||
"appSettings_ipfsGatewayIpfsIo",
|
||||
"appSettings_ipfsGatewayPinata",
|
||||
"appSettings_ipfsGatewayFilebase",
|
||||
"appSettings_ipfsGatewayCustom",
|
||||
@@ -505,6 +515,7 @@
|
||||
"appSettings_ipfsImageLinksSubtitle",
|
||||
"appSettings_publicIpfsGateway",
|
||||
"appSettings_ipfsGatewayDeactivated",
|
||||
"appSettings_ipfsGatewayIpfsIo",
|
||||
"appSettings_ipfsGatewayPinata",
|
||||
"appSettings_ipfsGatewayFilebase",
|
||||
"appSettings_ipfsGatewayCustom",
|
||||
@@ -555,6 +566,7 @@
|
||||
"appSettings_ipfsImageLinksSubtitle",
|
||||
"appSettings_publicIpfsGateway",
|
||||
"appSettings_ipfsGatewayDeactivated",
|
||||
"appSettings_ipfsGatewayIpfsIo",
|
||||
"appSettings_ipfsGatewayPinata",
|
||||
"appSettings_ipfsGatewayFilebase",
|
||||
"appSettings_ipfsGatewayCustom",
|
||||
@@ -605,6 +617,7 @@
|
||||
"appSettings_ipfsImageLinksSubtitle",
|
||||
"appSettings_publicIpfsGateway",
|
||||
"appSettings_ipfsGatewayDeactivated",
|
||||
"appSettings_ipfsGatewayIpfsIo",
|
||||
"appSettings_ipfsGatewayPinata",
|
||||
"appSettings_ipfsGatewayFilebase",
|
||||
"appSettings_ipfsGatewayCustom",
|
||||
@@ -655,6 +668,7 @@
|
||||
"appSettings_ipfsImageLinksSubtitle",
|
||||
"appSettings_publicIpfsGateway",
|
||||
"appSettings_ipfsGatewayDeactivated",
|
||||
"appSettings_ipfsGatewayIpfsIo",
|
||||
"appSettings_ipfsGatewayPinata",
|
||||
"appSettings_ipfsGatewayFilebase",
|
||||
"appSettings_ipfsGatewayCustom",
|
||||
@@ -705,6 +719,7 @@
|
||||
"appSettings_ipfsImageLinksSubtitle",
|
||||
"appSettings_publicIpfsGateway",
|
||||
"appSettings_ipfsGatewayDeactivated",
|
||||
"appSettings_ipfsGatewayIpfsIo",
|
||||
"appSettings_ipfsGatewayPinata",
|
||||
"appSettings_ipfsGatewayFilebase",
|
||||
"appSettings_ipfsGatewayCustom",
|
||||
@@ -755,6 +770,7 @@
|
||||
"appSettings_ipfsImageLinksSubtitle",
|
||||
"appSettings_publicIpfsGateway",
|
||||
"appSettings_ipfsGatewayDeactivated",
|
||||
"appSettings_ipfsGatewayIpfsIo",
|
||||
"appSettings_ipfsGatewayPinata",
|
||||
"appSettings_ipfsGatewayFilebase",
|
||||
"appSettings_ipfsGatewayCustom",
|
||||
@@ -805,6 +821,7 @@
|
||||
"appSettings_ipfsImageLinksSubtitle",
|
||||
"appSettings_publicIpfsGateway",
|
||||
"appSettings_ipfsGatewayDeactivated",
|
||||
"appSettings_ipfsGatewayIpfsIo",
|
||||
"appSettings_ipfsGatewayPinata",
|
||||
"appSettings_ipfsGatewayFilebase",
|
||||
"appSettings_ipfsGatewayCustom",
|
||||
|
||||
Reference in new issue
Block a user