feat: initial Cutdex application
Add the Flutter video editing application with project management, media import, timeline editing, preview, AI assistance, diagnostics and settings. Include shared UI and native host packages, platform runners, application tests and release tooling. Provide usage and contribution guides, the MIT license and third-party notices. Exclude local credentials, build outputs and validation data.
This commit is contained in:
commit
27e77fff39
718 files changed
+183958
No files matched your search
@@ -0,0 +1,760 @@
|
||||
import 'package:freezed_annotation/freezed_annotation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
|
||||
import '../../integrations/agent/agent_settings.dart';
|
||||
import '../../integrations/agent/agent_models.dart';
|
||||
import '../../l10n/l10n.dart';
|
||||
|
||||
import 'package:cutdex_ui/theme.dart';
|
||||
import 'package:cutdex_ui/widgets.dart';
|
||||
|
||||
import 'settings_layout.dart';
|
||||
import '../../settings/settings_operation.dart';
|
||||
|
||||
part 'agent_settings_panel.freezed.dart';
|
||||
|
||||
class AgentSettingsPanel extends ConsumerStatefulWidget {
|
||||
const AgentSettingsPanel({super.key, this.contentPadding = EdgeInsets.zero});
|
||||
|
||||
final EdgeInsets contentPadding;
|
||||
|
||||
@override
|
||||
ConsumerState<AgentSettingsPanel> createState() => _AgentSettingsPanelState();
|
||||
}
|
||||
|
||||
class _AgentSettingsPanelState extends ConsumerState<AgentSettingsPanel>
|
||||
with SingleTickerProviderStateMixin {
|
||||
late final AnimationController _pageFade = AnimationController(
|
||||
vsync: this,
|
||||
duration: const Duration(milliseconds: 140),
|
||||
value: 1,
|
||||
);
|
||||
bool _showingProviderEditor = false;
|
||||
AgentProviderSettings? _editingProvider;
|
||||
bool _transitioning = false;
|
||||
bool get _saving =>
|
||||
ref.read(settingsOperationProvider('agent-save')).isLoading;
|
||||
final _scroll = ScrollController();
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_pageFade.dispose();
|
||||
_scroll.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
Future<void> _showProviderForm(
|
||||
bool adding, {
|
||||
AgentProviderSettings? provider,
|
||||
}) async {
|
||||
if (_transitioning || _saving || _showingProviderEditor == adding) return;
|
||||
setState(() => _transitioning = true);
|
||||
await _pageFade.reverse();
|
||||
if (!mounted) return;
|
||||
if (_scroll.hasClients) _scroll.jumpTo(0);
|
||||
setState(() {
|
||||
_showingProviderEditor = adding;
|
||||
_editingProvider = adding ? provider : null;
|
||||
});
|
||||
await _pageFade.forward();
|
||||
if (mounted) setState(() => _transitioning = false);
|
||||
}
|
||||
|
||||
Future<void> _saveProvider(_ProviderFormValue result) async {
|
||||
if (_saving) return;
|
||||
final saved = await ref
|
||||
.read(settingsOperationProvider('agent-save').notifier)
|
||||
.run(
|
||||
() => ref
|
||||
.read(agentSettingsProvider.notifier)
|
||||
.upsertProvider(
|
||||
id: _editingProvider?.id,
|
||||
name: result.name,
|
||||
apiType: result.apiType,
|
||||
baseUrl: result.baseUrl,
|
||||
models: result.models,
|
||||
apiKey: result.apiKey,
|
||||
clearApiKey: result.clearApiKey,
|
||||
),
|
||||
);
|
||||
if (!mounted) return;
|
||||
if (saved) {
|
||||
await _showProviderForm(false);
|
||||
} else {
|
||||
_showSaveError();
|
||||
}
|
||||
}
|
||||
|
||||
void _showSaveError() => ScaffoldMessenger.of(
|
||||
context,
|
||||
).showSnackBar(SnackBar(content: Text(context.l10n.agentSaveSettingsFailed)));
|
||||
|
||||
Future<void> _setProviderEnabled(
|
||||
AgentProviderSettings provider,
|
||||
bool enabled,
|
||||
) async {
|
||||
if (_transitioning) return;
|
||||
final operation = settingsOperationProvider('agent-enable-${provider.id}');
|
||||
if (ref.read(operation).isLoading) return;
|
||||
final saved = await ref
|
||||
.read(operation.notifier)
|
||||
.run(
|
||||
() => ref
|
||||
.read(agentSettingsProvider.notifier)
|
||||
.setProviderEnabled(provider.id, enabled),
|
||||
);
|
||||
if (!saved && mounted) _showSaveError();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) => Theme(
|
||||
data: AppTheme.settingsContentTheme(Theme.of(context)),
|
||||
child: Builder(builder: _buildContent),
|
||||
);
|
||||
|
||||
Widget _buildContent(BuildContext context) {
|
||||
ref.watch(settingsOperationProvider('agent-save'));
|
||||
final settings = ref.watch(agentSettingsProvider);
|
||||
return ScrollConfiguration(
|
||||
behavior: ScrollConfiguration.of(context).copyWith(scrollbars: false),
|
||||
child: Scrollbar(
|
||||
controller: _scroll,
|
||||
thumbVisibility: true,
|
||||
child: SingleChildScrollView(
|
||||
key: const Key('agent-settings-scroll'),
|
||||
controller: _scroll,
|
||||
primary: false,
|
||||
padding: widget.contentPadding,
|
||||
physics: const ClampingScrollPhysics(),
|
||||
child: FadeTransition(
|
||||
key: const Key('agent-provider-page-transition'),
|
||||
opacity: _pageFade,
|
||||
child: IgnorePointer(
|
||||
ignoring: _transitioning,
|
||||
child: _showingProviderEditor
|
||||
? _ProviderEditor(
|
||||
key: const Key('agent-provider-editor'),
|
||||
saving: _saving,
|
||||
provider: _editingProvider,
|
||||
onBack: () => _showProviderForm(false),
|
||||
onSave: _saveProvider,
|
||||
)
|
||||
: SettingsPageSection(
|
||||
key: const Key('agent-provider-list'),
|
||||
title: context.l10n.agentSettings,
|
||||
icon: Icons.auto_awesome_outlined,
|
||||
action: OutlinedButton.icon(
|
||||
onPressed: settings.asData == null
|
||||
? null
|
||||
: () => _showProviderForm(true),
|
||||
icon: const Icon(Icons.add),
|
||||
label: Text(context.l10n.agentAddProvider),
|
||||
),
|
||||
children: [
|
||||
for (final provider
|
||||
in settings.asData?.value.providers ??
|
||||
const <AgentProviderSettings>[])
|
||||
_ProviderCard(
|
||||
key: ValueKey('agent-provider-${provider.id}'),
|
||||
provider: provider,
|
||||
onEdit: () =>
|
||||
_showProviderForm(true, provider: provider),
|
||||
onEnabledChanged: (value) =>
|
||||
_setProviderEnabled(provider, value),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _ProviderCard extends StatelessWidget {
|
||||
const _ProviderCard({
|
||||
super.key,
|
||||
required this.provider,
|
||||
required this.onEdit,
|
||||
required this.onEnabledChanged,
|
||||
});
|
||||
|
||||
final AgentProviderSettings provider;
|
||||
final VoidCallback onEdit;
|
||||
final ValueChanged<bool> onEnabledChanged;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final theme = Theme.of(context);
|
||||
final colors = theme.colorScheme;
|
||||
final icon = switch (provider.apiType) {
|
||||
'anthropicMessages' => Icons.auto_awesome_outlined,
|
||||
'openAiResponses' => Icons.bolt_outlined,
|
||||
_ => Icons.forum_outlined,
|
||||
};
|
||||
return Container(
|
||||
padding: EdgeInsets.zero,
|
||||
child: Row(
|
||||
children: [
|
||||
Icon(icon, size: AppIconSize.header, color: colors.onSurfaceVariant),
|
||||
const SizedBox(width: 16),
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Text(
|
||||
provider.name,
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: theme.textTheme.bodyMedium?.copyWith(
|
||||
fontWeight: FontWeight.w400,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 2),
|
||||
Text(
|
||||
provider.models.map((model) => model.id).join(' · '),
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: theme.textTheme.bodySmall?.copyWith(
|
||||
color: colors.onSurfaceVariant,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
IconButton(
|
||||
key: ValueKey('agent-provider-edit-${provider.id}'),
|
||||
tooltip: context.l10n.agentEditProvider,
|
||||
onPressed: onEdit,
|
||||
icon: const Icon(Icons.edit_outlined, size: AppIconSize.header),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
AppSwitch(
|
||||
key: ValueKey('agent-provider-enabled-${provider.id}'),
|
||||
value: provider.enabled,
|
||||
semanticLabel: context.l10n.agentEnableProvider,
|
||||
onChanged: onEnabledChanged,
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
TextStyle _providerInputStyle(BuildContext context) =>
|
||||
Theme.of(context).textTheme.bodyMedium!;
|
||||
|
||||
InputDecoration _providerInputDecoration(
|
||||
BuildContext context, {
|
||||
String? hintText,
|
||||
}) => InputDecoration(
|
||||
hintText: hintText,
|
||||
hintStyle: _providerInputStyle(context)
|
||||
.copyWith(color: Theme.of(context).colorScheme.onSurfaceVariant),
|
||||
);
|
||||
|
||||
class _ProviderEditor extends StatefulWidget {
|
||||
const _ProviderEditor({
|
||||
super.key,
|
||||
required this.onBack,
|
||||
required this.onSave,
|
||||
required this.saving,
|
||||
this.provider,
|
||||
});
|
||||
|
||||
final VoidCallback onBack;
|
||||
final ValueChanged<_ProviderFormValue> onSave;
|
||||
final bool saving;
|
||||
final AgentProviderSettings? provider;
|
||||
|
||||
@override
|
||||
State<_ProviderEditor> createState() => _ProviderEditorState();
|
||||
}
|
||||
|
||||
class _ProviderEditorState extends State<_ProviderEditor> {
|
||||
final _formKey = GlobalKey<FormState>();
|
||||
late final TextEditingController _name;
|
||||
late final TextEditingController _baseUrl;
|
||||
late final TextEditingController _apiKey;
|
||||
late List<_ModelControllers> _models;
|
||||
AgentApiType _apiType = AgentApiType.openAiChatCompletions;
|
||||
String? _formError;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
final provider = widget.provider;
|
||||
_name = TextEditingController(text: provider?.name);
|
||||
_baseUrl = TextEditingController(text: provider?.baseUrl);
|
||||
_apiKey = TextEditingController();
|
||||
_apiType =
|
||||
AgentApiType.values
|
||||
.where((type) => type.name == provider?.apiType)
|
||||
.firstOrNull ??
|
||||
AgentApiType.openAiChatCompletions;
|
||||
_models = provider == null || provider.models.isEmpty
|
||||
? [_ModelControllers()]
|
||||
: [for (final model in provider.models) _ModelControllers(model)];
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_name.dispose();
|
||||
_baseUrl.dispose();
|
||||
_apiKey.dispose();
|
||||
for (final model in _models) {
|
||||
model.dispose();
|
||||
}
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
void _submit() {
|
||||
if (!_formKey.currentState!.validate()) return;
|
||||
final modelIds = _models.map((model) => model.id.text.trim()).toList();
|
||||
if (modelIds.toSet().length != modelIds.length) {
|
||||
setState(() => _formError = context.l10n.agentModelIdsUnique);
|
||||
return;
|
||||
}
|
||||
widget.onSave(
|
||||
_ProviderFormValue(
|
||||
name: _name.text.trim(),
|
||||
apiType: _apiType,
|
||||
baseUrl: _baseUrl.text.trim(),
|
||||
apiKey: _apiKey.text.isEmpty ? null : _apiKey.text,
|
||||
clearApiKey: false,
|
||||
models: [for (final model in _models) model.toData()],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) => Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
TextButton.icon(
|
||||
key: const Key('agent-provider-back'),
|
||||
onPressed: widget.saving ? null : widget.onBack,
|
||||
icon: const Icon(Icons.arrow_back, size: 16),
|
||||
label: Text(context.l10n.agentBackToProviders),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: AppSpacing.large),
|
||||
Form(
|
||||
key: _formKey,
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
_ConfigurationCard(
|
||||
title: context.l10n.agentProviderConfiguration,
|
||||
child: AppFieldGroup(
|
||||
children: [
|
||||
_ProviderIdentityRow(
|
||||
children: [
|
||||
AppField(
|
||||
label: context.l10n.name,
|
||||
child: TextFormField(
|
||||
style: _providerInputStyle(context),
|
||||
textAlignVertical: TextAlignVertical.center,
|
||||
cursorHeight: 18,
|
||||
cursorWidth: 1.5,
|
||||
strutStyle: StrutStyle.fromTextStyle(
|
||||
_providerInputStyle(context),
|
||||
),
|
||||
key: const Key('agent-provider-name'),
|
||||
controller: _name,
|
||||
decoration: _providerInputDecoration(
|
||||
context,
|
||||
hintText: context.l10n.agentProviderNameHint,
|
||||
),
|
||||
validator: (value) => _required(context, value),
|
||||
),
|
||||
),
|
||||
AppField(
|
||||
label: context.l10n.agentApiType,
|
||||
child: AppSelect<AgentApiType>(
|
||||
emptyLabel: context.l10n.noMatchingOptions,
|
||||
controlHeight: AppSettingsMetrics.inputHeight,
|
||||
textStyle: _providerInputStyle(context),
|
||||
value: _apiType,
|
||||
label: context.l10n.agentApiType,
|
||||
options: [
|
||||
for (final value in AgentApiType.values)
|
||||
AppSelectOption(
|
||||
value,
|
||||
_apiTypeLabel(context, value),
|
||||
),
|
||||
],
|
||||
onChanged: (value) =>
|
||||
setState(() => _apiType = value),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
AppField(
|
||||
label: context.l10n.agentBaseUrl,
|
||||
child: TextFormField(
|
||||
style: _providerInputStyle(context),
|
||||
textAlignVertical: TextAlignVertical.center,
|
||||
cursorHeight: 18,
|
||||
cursorWidth: 1.5,
|
||||
strutStyle: StrutStyle.fromTextStyle(
|
||||
_providerInputStyle(context),
|
||||
),
|
||||
key: const Key('agent-provider-base-url'),
|
||||
controller: _baseUrl,
|
||||
keyboardType: TextInputType.url,
|
||||
decoration: _providerInputDecoration(
|
||||
context,
|
||||
hintText: _apiType == AgentApiType.anthropicMessages
|
||||
? 'https://api.anthropic.com/v1'
|
||||
: 'https://api.openai.com/v1',
|
||||
),
|
||||
validator: (value) => _validateUrl(context, value),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(height: AppSpacing.large),
|
||||
_ConfigurationCard(
|
||||
title: context.l10n.agentAuthenticationAndModels,
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
AppField(
|
||||
label: context.l10n.agentApiKey,
|
||||
child: TextFormField(
|
||||
style: _providerInputStyle(context),
|
||||
textAlignVertical: TextAlignVertical.center,
|
||||
cursorHeight: 18,
|
||||
cursorWidth: 1.5,
|
||||
strutStyle: StrutStyle.fromTextStyle(
|
||||
_providerInputStyle(context),
|
||||
),
|
||||
key: const Key('agent-provider-api-key'),
|
||||
controller: _apiKey,
|
||||
obscureText: true,
|
||||
decoration: _providerInputDecoration(
|
||||
context,
|
||||
hintText: context.l10n.agentOptional,
|
||||
),
|
||||
validator: (value) =>
|
||||
value != null &&
|
||||
(value.contains('\n') || value.contains('\r'))
|
||||
? context.l10n.agentApiKeyOneLine
|
||||
: null,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: AppSpacing.small),
|
||||
Text(
|
||||
widget.provider?.credentialId != null
|
||||
? context.l10n.agentApiKeyKeep
|
||||
: context.l10n.agentApiKeyOptional,
|
||||
style: Theme.of(context).textTheme.bodySmall?.copyWith(
|
||||
color: Theme.of(context).colorScheme.onSurfaceVariant,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: AppSpacing.extraLarge),
|
||||
if (_formError != null) ...[
|
||||
const SizedBox(height: AppSpacing.small),
|
||||
Text(
|
||||
_formError!,
|
||||
style: TextStyle(
|
||||
color: Theme.of(context).colorScheme.error,
|
||||
),
|
||||
),
|
||||
],
|
||||
const SizedBox(height: AppSpacing.small),
|
||||
for (var index = 0; index < _models.length; index++)
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(bottom: AppSpacing.medium),
|
||||
child: _ModelFields(
|
||||
index: index,
|
||||
controllers: _models[index],
|
||||
canDelete: _models.length > 1,
|
||||
onDelete: () {
|
||||
final removed = _models[index];
|
||||
setState(
|
||||
() => _models = [..._models]..removeAt(index),
|
||||
);
|
||||
removed.dispose();
|
||||
},
|
||||
),
|
||||
),
|
||||
Align(
|
||||
alignment: AlignmentDirectional.centerEnd,
|
||||
child: OutlinedButton.icon(
|
||||
onPressed: () => setState(
|
||||
() => _models = [..._models, _ModelControllers()],
|
||||
),
|
||||
icon: const Icon(Icons.add, size: AppIconSize.header),
|
||||
label: Text(context.l10n.agentAddModel),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: AppSpacing.large),
|
||||
Align(
|
||||
alignment: AlignmentDirectional.centerEnd,
|
||||
child: FilledButton(
|
||||
onPressed: widget.saving ? null : _submit,
|
||||
child: Text(context.l10n.agentSaveProvider),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
|
||||
static String? _required(BuildContext context, String? value) =>
|
||||
value == null || value.trim().isEmpty
|
||||
? context.l10n.agentRequiredField
|
||||
: null;
|
||||
|
||||
static String? _validateUrl(BuildContext context, String? value) {
|
||||
final uri = Uri.tryParse(value?.trim() ?? '');
|
||||
return uri == null ||
|
||||
!uri.hasAuthority ||
|
||||
!['http', 'https'].contains(uri.scheme) ||
|
||||
uri.userInfo.isNotEmpty ||
|
||||
uri.hasQuery ||
|
||||
uri.hasFragment
|
||||
? context.l10n.agentInvalidBaseUrl
|
||||
: null;
|
||||
}
|
||||
|
||||
static String _apiTypeLabel(BuildContext context, AgentApiType value) =>
|
||||
switch (value) {
|
||||
AgentApiType.openAiChatCompletions =>
|
||||
context.l10n.agentOpenAiChatCompletions,
|
||||
AgentApiType.openAiResponses => 'OpenAI Responses',
|
||||
AgentApiType.anthropicMessages => 'Anthropic Messages',
|
||||
};
|
||||
}
|
||||
|
||||
class _ConfigurationCard extends StatelessWidget {
|
||||
const _ConfigurationCard({required this.title, required this.child});
|
||||
|
||||
final String title;
|
||||
final Widget child;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final theme = Theme.of(context);
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
Text(title, style: theme.textTheme.labelLarge),
|
||||
const SizedBox(height: AppSpacing.medium),
|
||||
Container(
|
||||
padding: const EdgeInsets.all(AppSpacing.medium),
|
||||
decoration: BoxDecoration(
|
||||
color: theme.colorScheme.surfaceContainer,
|
||||
borderRadius: BorderRadius.circular(AppSettingsMetrics.cardRadius),
|
||||
border: Border.all(color: theme.colorScheme.outlineVariant),
|
||||
),
|
||||
child: child,
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _ProviderIdentityRow extends StatelessWidget {
|
||||
const _ProviderIdentityRow({required this.children});
|
||||
final List<Widget> children;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) => LayoutBuilder(
|
||||
builder: (context, constraints) => constraints.maxWidth < 520
|
||||
? AppFieldGroup(children: children)
|
||||
: Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Expanded(child: children[0]),
|
||||
const SizedBox(width: 16),
|
||||
Expanded(child: children[1]),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
class _ModelFields extends StatelessWidget {
|
||||
const _ModelFields({
|
||||
required this.index,
|
||||
required this.controllers,
|
||||
required this.canDelete,
|
||||
required this.onDelete,
|
||||
});
|
||||
|
||||
final int index;
|
||||
final _ModelControllers controllers;
|
||||
final bool canDelete;
|
||||
final VoidCallback onDelete;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final fields = <Widget>[
|
||||
AppField(
|
||||
label: context.l10n.agentModelId,
|
||||
child: TextFormField(
|
||||
style: _providerInputStyle(context),
|
||||
textAlignVertical: TextAlignVertical.center,
|
||||
cursorHeight: 18,
|
||||
cursorWidth: 1.5,
|
||||
strutStyle: StrutStyle.fromTextStyle(_providerInputStyle(context)),
|
||||
key: Key('agent-model-id-$index'),
|
||||
controller: controllers.id,
|
||||
decoration: _providerInputDecoration(
|
||||
context,
|
||||
hintText: 'my-model-id',
|
||||
),
|
||||
validator: (value) => _ProviderEditorState._required(context, value),
|
||||
),
|
||||
),
|
||||
AppField(
|
||||
label: context.l10n.agentContextWindow,
|
||||
child: TextFormField(
|
||||
style: _providerInputStyle(context),
|
||||
textAlignVertical: TextAlignVertical.center,
|
||||
cursorHeight: 18,
|
||||
cursorWidth: 1.5,
|
||||
strutStyle: StrutStyle.fromTextStyle(_providerInputStyle(context)),
|
||||
key: Key('agent-model-context-$index'),
|
||||
controller: controllers.contextWindow,
|
||||
keyboardType: TextInputType.number,
|
||||
decoration: _providerInputDecoration(context, hintText: '512000'),
|
||||
validator: (value) => _optionalPositiveInteger(context, value),
|
||||
),
|
||||
),
|
||||
AppField(
|
||||
label: context.l10n.agentMaxOutputTokens,
|
||||
child: TextFormField(
|
||||
style: _providerInputStyle(context),
|
||||
textAlignVertical: TextAlignVertical.center,
|
||||
cursorHeight: 18,
|
||||
cursorWidth: 1.5,
|
||||
strutStyle: StrutStyle.fromTextStyle(_providerInputStyle(context)),
|
||||
key: Key('agent-model-output-$index'),
|
||||
controller: controllers.maxOutputTokens,
|
||||
keyboardType: TextInputType.number,
|
||||
decoration: _providerInputDecoration(context, hintText: '4096'),
|
||||
validator: (value) {
|
||||
final basic = _optionalPositiveInteger(context, value);
|
||||
if (basic != null) return basic;
|
||||
final contextWindow = int.tryParse(controllers.contextWindow.text);
|
||||
final model = AgentModelSettings(
|
||||
id: controllers.id.text,
|
||||
contextWindow: contextWindow,
|
||||
maxOutputTokens: int.tryParse(value ?? ''),
|
||||
);
|
||||
if (!model.hasValidTokenBudget) {
|
||||
return context.l10n.agentMaxOutputBelowContext;
|
||||
}
|
||||
return model.hasInstructionBudget
|
||||
? null
|
||||
: context.l10n.agentContextBudgetTooSmall;
|
||||
},
|
||||
),
|
||||
),
|
||||
];
|
||||
final removeButton = SizedBox.square(
|
||||
dimension: AppSettingsMetrics.inputHeight,
|
||||
child: IconButton(
|
||||
style: IconButton.styleFrom(
|
||||
padding: EdgeInsets.zero,
|
||||
minimumSize: const Size.square(AppSettingsMetrics.inputHeight),
|
||||
tapTargetSize: MaterialTapTargetSize.shrinkWrap,
|
||||
),
|
||||
tooltip: context.l10n.agentDeleteModel,
|
||||
onPressed: canDelete ? onDelete : null,
|
||||
icon: const Icon(Icons.delete_outline, size: AppIconSize.header),
|
||||
),
|
||||
);
|
||||
return LayoutBuilder(
|
||||
builder: (context, constraints) {
|
||||
if (constraints.maxWidth < 520) {
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
spacing: AppSpacing.compact,
|
||||
children: [
|
||||
...fields,
|
||||
Align(
|
||||
alignment: AlignmentDirectional.centerEnd,
|
||||
child: removeButton,
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
return Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
spacing: AppSpacing.small,
|
||||
children: [
|
||||
for (var i = 0; i < fields.length; i++)
|
||||
Expanded(flex: i == 0 ? 2 : 1, child: fields[i]),
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(top: 26),
|
||||
child: removeButton,
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
static String? _optionalPositiveInteger(BuildContext context, String? value) {
|
||||
if (value == null || value.trim().isEmpty) return null;
|
||||
final parsed = int.tryParse(value);
|
||||
return parsed == null || parsed <= 0
|
||||
? context.l10n.agentPositiveInteger
|
||||
: null;
|
||||
}
|
||||
}
|
||||
|
||||
class _ModelControllers {
|
||||
_ModelControllers([AgentModelSettings? model])
|
||||
: id = TextEditingController(text: model?.id),
|
||||
contextWindow = TextEditingController(
|
||||
text: model?.contextWindow?.toString(),
|
||||
),
|
||||
maxOutputTokens = TextEditingController(
|
||||
text: model?.maxOutputTokens?.toString(),
|
||||
);
|
||||
|
||||
final TextEditingController id;
|
||||
final TextEditingController contextWindow;
|
||||
final TextEditingController maxOutputTokens;
|
||||
|
||||
AgentModelSettings toData() => AgentModelSettings(
|
||||
id: id.text.trim(),
|
||||
contextWindow: int.tryParse(contextWindow.text),
|
||||
maxOutputTokens: int.tryParse(maxOutputTokens.text),
|
||||
);
|
||||
|
||||
void dispose() {
|
||||
id.dispose();
|
||||
contextWindow.dispose();
|
||||
maxOutputTokens.dispose();
|
||||
}
|
||||
}
|
||||
|
||||
@freezed
|
||||
abstract class _ProviderFormValue with _$ProviderFormValue {
|
||||
const factory _ProviderFormValue({
|
||||
required String name,
|
||||
required AgentApiType apiType,
|
||||
required String baseUrl,
|
||||
required List<AgentModelSettings> models,
|
||||
required String? apiKey,
|
||||
required bool clearApiKey,
|
||||
}) = _ProviderFormData;
|
||||
}
|
||||
@@ -0,0 +1,483 @@
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
// coverage:ignore-file
|
||||
// ignore_for_file: type=lint, type=warning, deprecated_member_use, deprecated_member_use_from_same_package
|
||||
// ignore_for_file: unused_element, deprecated_member_use, deprecated_member_use_from_same_package, use_function_type_syntax_for_parameters, unnecessary_const, avoid_init_to_null, invalid_override_different_default_values_named, prefer_expression_function_bodies, annotate_overrides, invalid_annotation_target, unnecessary_question_mark
|
||||
|
||||
part of 'agent_settings_panel.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// FreezedGenerator
|
||||
// **************************************************************************
|
||||
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
T _$identity<T>(T value) => value;
|
||||
|
||||
/// @nodoc
|
||||
mixin _$ProviderFormValue {
|
||||
String get name;
|
||||
AgentApiType get apiType;
|
||||
String get baseUrl;
|
||||
List<AgentModelSettings> get models;
|
||||
String? get apiKey;
|
||||
bool get clearApiKey;
|
||||
|
||||
/// Create a copy of _ProviderFormValue
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@JsonKey(includeFromJson: false, includeToJson: false)
|
||||
@pragma('vm:prefer-inline')
|
||||
_$ProviderFormValueCopyWith<_ProviderFormValue> get copyWith =>
|
||||
__$ProviderFormValueCopyWithImpl<_ProviderFormValue>(
|
||||
this as _ProviderFormValue,
|
||||
_$identity,
|
||||
);
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) {
|
||||
final _this = this as _ProviderFormValue;
|
||||
return identical(this, other) ||
|
||||
(other.runtimeType == runtimeType &&
|
||||
other is _ProviderFormValue &&
|
||||
(identical(other.name, _this.name) || other.name == _this.name) &&
|
||||
(identical(other.apiType, _this.apiType) ||
|
||||
other.apiType == _this.apiType) &&
|
||||
(identical(other.baseUrl, _this.baseUrl) ||
|
||||
other.baseUrl == _this.baseUrl) &&
|
||||
const DeepCollectionEquality().equals(other.models, _this.models) &&
|
||||
(identical(other.apiKey, _this.apiKey) ||
|
||||
other.apiKey == _this.apiKey) &&
|
||||
(identical(other.clearApiKey, _this.clearApiKey) ||
|
||||
other.clearApiKey == _this.clearApiKey));
|
||||
}
|
||||
|
||||
@override
|
||||
int get hashCode {
|
||||
final _this = this as _ProviderFormValue;
|
||||
return Object.hash(
|
||||
runtimeType,
|
||||
_this.name,
|
||||
_this.apiType,
|
||||
_this.baseUrl,
|
||||
const DeepCollectionEquality().hash(_this.models),
|
||||
_this.apiKey,
|
||||
_this.clearApiKey,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
final _this = this as _ProviderFormValue;
|
||||
return '_ProviderFormValue(name: ${_this.name}, apiType: ${_this.apiType}, baseUrl: ${_this.baseUrl}, models: ${_this.models}, apiKey: ${_this.apiKey}, clearApiKey: ${_this.clearApiKey})';
|
||||
}
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
abstract mixin class _$ProviderFormValueCopyWith<$Res> {
|
||||
factory _$ProviderFormValueCopyWith(
|
||||
_ProviderFormValue value,
|
||||
$Res Function(_ProviderFormValue) _then,
|
||||
) = __$ProviderFormValueCopyWithImpl;
|
||||
@useResult
|
||||
$Res call({
|
||||
String name,
|
||||
AgentApiType apiType,
|
||||
String baseUrl,
|
||||
List<AgentModelSettings> models,
|
||||
String? apiKey,
|
||||
bool clearApiKey,
|
||||
});
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
class __$ProviderFormValueCopyWithImpl<$Res>
|
||||
implements _$ProviderFormValueCopyWith<$Res> {
|
||||
__$ProviderFormValueCopyWithImpl(this._self, this._then);
|
||||
|
||||
final _ProviderFormValue _self;
|
||||
final $Res Function(_ProviderFormValue) _then;
|
||||
|
||||
/// Create a copy of _ProviderFormValue
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@pragma('vm:prefer-inline')
|
||||
@override
|
||||
$Res call({
|
||||
Object? name = null,
|
||||
Object? apiType = null,
|
||||
Object? baseUrl = null,
|
||||
Object? models = null,
|
||||
Object? apiKey = freezed,
|
||||
Object? clearApiKey = null,
|
||||
}) {
|
||||
return _then(
|
||||
_ProviderFormValue(
|
||||
name: null == name
|
||||
? _self.name
|
||||
: name // ignore: cast_nullable_to_non_nullable
|
||||
as String,
|
||||
apiType: null == apiType
|
||||
? _self.apiType
|
||||
: apiType // ignore: cast_nullable_to_non_nullable
|
||||
as AgentApiType,
|
||||
baseUrl: null == baseUrl
|
||||
? _self.baseUrl
|
||||
: baseUrl // ignore: cast_nullable_to_non_nullable
|
||||
as String,
|
||||
models: null == models
|
||||
? _self.models
|
||||
: models // ignore: cast_nullable_to_non_nullable
|
||||
as List<AgentModelSettings>,
|
||||
apiKey: freezed == apiKey
|
||||
? _self.apiKey
|
||||
: apiKey // ignore: cast_nullable_to_non_nullable
|
||||
as String?,
|
||||
clearApiKey: null == clearApiKey
|
||||
? _self.clearApiKey
|
||||
: clearApiKey // ignore: cast_nullable_to_non_nullable
|
||||
as bool,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// Adds pattern-matching-related methods to [_ProviderFormValue].
|
||||
extension _ProviderFormValuePatterns on _ProviderFormValue {
|
||||
/// A variant of `map` that fallback to returning `orElse`.
|
||||
///
|
||||
/// It is equivalent to doing:
|
||||
/// ```dart
|
||||
/// switch (sealedClass) {
|
||||
/// case final Subclass value:
|
||||
/// return ...;
|
||||
/// case _:
|
||||
/// return orElse();
|
||||
/// }
|
||||
/// ```
|
||||
|
||||
@optionalTypeArgs
|
||||
TResult maybeMap<TResult extends Object?>(
|
||||
TResult Function(_ProviderFormData value)? $default, {
|
||||
required TResult orElse(),
|
||||
}) {
|
||||
final _that = this;
|
||||
switch (_that) {
|
||||
case _ProviderFormData() when $default != null:
|
||||
return $default(_that);
|
||||
case _:
|
||||
return orElse();
|
||||
}
|
||||
}
|
||||
|
||||
/// A `switch`-like method, using callbacks.
|
||||
///
|
||||
/// Callbacks receives the raw object, upcasted.
|
||||
/// It is equivalent to doing:
|
||||
/// ```dart
|
||||
/// switch (sealedClass) {
|
||||
/// case final Subclass value:
|
||||
/// return ...;
|
||||
/// case final Subclass2 value:
|
||||
/// return ...;
|
||||
/// }
|
||||
/// ```
|
||||
|
||||
@optionalTypeArgs
|
||||
TResult map<TResult extends Object?>(
|
||||
TResult Function(_ProviderFormData value) $default,
|
||||
) {
|
||||
final _that = this;
|
||||
switch (_that) {
|
||||
case _ProviderFormData():
|
||||
return $default(_that);
|
||||
case _:
|
||||
throw StateError('Unexpected subclass');
|
||||
}
|
||||
}
|
||||
|
||||
/// A variant of `map` that fallback to returning `null`.
|
||||
///
|
||||
/// It is equivalent to doing:
|
||||
/// ```dart
|
||||
/// switch (sealedClass) {
|
||||
/// case final Subclass value:
|
||||
/// return ...;
|
||||
/// case _:
|
||||
/// return null;
|
||||
/// }
|
||||
/// ```
|
||||
|
||||
@optionalTypeArgs
|
||||
TResult? mapOrNull<TResult extends Object?>(
|
||||
TResult? Function(_ProviderFormData value)? $default,
|
||||
) {
|
||||
final _that = this;
|
||||
switch (_that) {
|
||||
case _ProviderFormData() when $default != null:
|
||||
return $default(_that);
|
||||
case _:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/// A variant of `when` that fallback to an `orElse` callback.
|
||||
///
|
||||
/// It is equivalent to doing:
|
||||
/// ```dart
|
||||
/// switch (sealedClass) {
|
||||
/// case Subclass(:final field):
|
||||
/// return ...;
|
||||
/// case _:
|
||||
/// return orElse();
|
||||
/// }
|
||||
/// ```
|
||||
|
||||
@optionalTypeArgs
|
||||
TResult maybeWhen<TResult extends Object?>(
|
||||
TResult Function(
|
||||
String name,
|
||||
AgentApiType apiType,
|
||||
String baseUrl,
|
||||
List<AgentModelSettings> models,
|
||||
String? apiKey,
|
||||
bool clearApiKey,
|
||||
)?
|
||||
$default, {
|
||||
required TResult orElse(),
|
||||
}) {
|
||||
final _that = this;
|
||||
switch (_that) {
|
||||
case _ProviderFormData() when $default != null:
|
||||
return $default(
|
||||
_that.name,
|
||||
_that.apiType,
|
||||
_that.baseUrl,
|
||||
_that.models,
|
||||
_that.apiKey,
|
||||
_that.clearApiKey,
|
||||
);
|
||||
case _:
|
||||
return orElse();
|
||||
}
|
||||
}
|
||||
|
||||
/// A `switch`-like method, using callbacks.
|
||||
///
|
||||
/// As opposed to `map`, this offers destructuring.
|
||||
/// It is equivalent to doing:
|
||||
/// ```dart
|
||||
/// switch (sealedClass) {
|
||||
/// case Subclass(:final field):
|
||||
/// return ...;
|
||||
/// case Subclass2(:final field2):
|
||||
/// return ...;
|
||||
/// }
|
||||
/// ```
|
||||
|
||||
@optionalTypeArgs
|
||||
TResult when<TResult extends Object?>(
|
||||
TResult Function(
|
||||
String name,
|
||||
AgentApiType apiType,
|
||||
String baseUrl,
|
||||
List<AgentModelSettings> models,
|
||||
String? apiKey,
|
||||
bool clearApiKey,
|
||||
)
|
||||
$default,
|
||||
) {
|
||||
final _that = this;
|
||||
switch (_that) {
|
||||
case _ProviderFormData():
|
||||
return $default(
|
||||
_that.name,
|
||||
_that.apiType,
|
||||
_that.baseUrl,
|
||||
_that.models,
|
||||
_that.apiKey,
|
||||
_that.clearApiKey,
|
||||
);
|
||||
case _:
|
||||
throw StateError('Unexpected subclass');
|
||||
}
|
||||
}
|
||||
|
||||
/// A variant of `when` that fallback to returning `null`
|
||||
///
|
||||
/// It is equivalent to doing:
|
||||
/// ```dart
|
||||
/// switch (sealedClass) {
|
||||
/// case Subclass(:final field):
|
||||
/// return ...;
|
||||
/// case _:
|
||||
/// return null;
|
||||
/// }
|
||||
/// ```
|
||||
|
||||
@optionalTypeArgs
|
||||
TResult? whenOrNull<TResult extends Object?>(
|
||||
TResult? Function(
|
||||
String name,
|
||||
AgentApiType apiType,
|
||||
String baseUrl,
|
||||
List<AgentModelSettings> models,
|
||||
String? apiKey,
|
||||
bool clearApiKey,
|
||||
)?
|
||||
$default,
|
||||
) {
|
||||
final _that = this;
|
||||
switch (_that) {
|
||||
case _ProviderFormData() when $default != null:
|
||||
return $default(
|
||||
_that.name,
|
||||
_that.apiType,
|
||||
_that.baseUrl,
|
||||
_that.models,
|
||||
_that.apiKey,
|
||||
_that.clearApiKey,
|
||||
);
|
||||
case _:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
|
||||
class _ProviderFormData implements _ProviderFormValue {
|
||||
const _ProviderFormData({
|
||||
required this.name,
|
||||
required this.apiType,
|
||||
required this.baseUrl,
|
||||
required List<AgentModelSettings> models,
|
||||
required this.apiKey,
|
||||
required this.clearApiKey,
|
||||
}) : _models = models;
|
||||
|
||||
@override
|
||||
final String name;
|
||||
@override
|
||||
final AgentApiType apiType;
|
||||
@override
|
||||
final String baseUrl;
|
||||
final List<AgentModelSettings> _models;
|
||||
@override
|
||||
List<AgentModelSettings> get models {
|
||||
if (_models is EqualUnmodifiableListView) return _models;
|
||||
// ignore: implicit_dynamic_type
|
||||
return EqualUnmodifiableListView(_models);
|
||||
}
|
||||
|
||||
@override
|
||||
final String? apiKey;
|
||||
@override
|
||||
final bool clearApiKey;
|
||||
|
||||
/// Create a copy of _ProviderFormValue
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@override
|
||||
@JsonKey(includeFromJson: false, includeToJson: false)
|
||||
@pragma('vm:prefer-inline')
|
||||
_$ProviderFormDataCopyWith<_ProviderFormData> get copyWith =>
|
||||
__$ProviderFormDataCopyWithImpl<_ProviderFormData>(this, _$identity);
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) {
|
||||
return identical(this, other) ||
|
||||
(other.runtimeType == runtimeType &&
|
||||
other is _ProviderFormData &&
|
||||
(identical(other.name, name) || other.name == name) &&
|
||||
(identical(other.apiType, apiType) || other.apiType == apiType) &&
|
||||
(identical(other.baseUrl, baseUrl) || other.baseUrl == baseUrl) &&
|
||||
const DeepCollectionEquality().equals(other.models, _models) &&
|
||||
(identical(other.apiKey, apiKey) || other.apiKey == apiKey) &&
|
||||
(identical(other.clearApiKey, clearApiKey) ||
|
||||
other.clearApiKey == clearApiKey));
|
||||
}
|
||||
|
||||
@override
|
||||
int get hashCode {
|
||||
return Object.hash(
|
||||
runtimeType,
|
||||
name,
|
||||
apiType,
|
||||
baseUrl,
|
||||
const DeepCollectionEquality().hash(_models),
|
||||
apiKey,
|
||||
clearApiKey,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return '_ProviderFormValue(name: $name, apiType: $apiType, baseUrl: $baseUrl, models: $models, apiKey: $apiKey, clearApiKey: $clearApiKey)';
|
||||
}
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
abstract mixin class _$ProviderFormDataCopyWith<$Res>
|
||||
implements _$ProviderFormValueCopyWith<$Res> {
|
||||
factory _$ProviderFormDataCopyWith(
|
||||
_ProviderFormData value,
|
||||
$Res Function(_ProviderFormData) _then,
|
||||
) = __$ProviderFormDataCopyWithImpl;
|
||||
@override
|
||||
@useResult
|
||||
$Res call({
|
||||
String name,
|
||||
AgentApiType apiType,
|
||||
String baseUrl,
|
||||
List<AgentModelSettings> models,
|
||||
String? apiKey,
|
||||
bool clearApiKey,
|
||||
});
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
class __$ProviderFormDataCopyWithImpl<$Res>
|
||||
implements _$ProviderFormDataCopyWith<$Res> {
|
||||
__$ProviderFormDataCopyWithImpl(this._self, this._then);
|
||||
|
||||
final _ProviderFormData _self;
|
||||
final $Res Function(_ProviderFormData) _then;
|
||||
|
||||
/// Create a copy of _ProviderFormValue
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@override
|
||||
@pragma('vm:prefer-inline')
|
||||
$Res call({
|
||||
Object? name = null,
|
||||
Object? apiType = null,
|
||||
Object? baseUrl = null,
|
||||
Object? models = null,
|
||||
Object? apiKey = freezed,
|
||||
Object? clearApiKey = null,
|
||||
}) {
|
||||
return _then(
|
||||
_ProviderFormData(
|
||||
name: null == name
|
||||
? _self.name
|
||||
: name // ignore: cast_nullable_to_non_nullable
|
||||
as String,
|
||||
apiType: null == apiType
|
||||
? _self.apiType
|
||||
: apiType // ignore: cast_nullable_to_non_nullable
|
||||
as AgentApiType,
|
||||
baseUrl: null == baseUrl
|
||||
? _self.baseUrl
|
||||
: baseUrl // ignore: cast_nullable_to_non_nullable
|
||||
as String,
|
||||
models: null == models
|
||||
? _self._models
|
||||
: models // ignore: cast_nullable_to_non_nullable
|
||||
as List<AgentModelSettings>,
|
||||
apiKey: freezed == apiKey
|
||||
? _self.apiKey
|
||||
: apiKey // ignore: cast_nullable_to_non_nullable
|
||||
as String?,
|
||||
clearApiKey: null == clearApiKey
|
||||
? _self.clearApiKey
|
||||
: clearApiKey // ignore: cast_nullable_to_non_nullable
|
||||
as bool,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:riverpod_annotation/riverpod_annotation.dart';
|
||||
|
||||
import '../../persistence/settings/appearance_settings_repository.dart';
|
||||
import '../../settings/appearance.dart';
|
||||
import '../../settings/settings_write_queue.dart';
|
||||
|
||||
export '../../settings/appearance.dart';
|
||||
|
||||
part 'appearance_settings.g.dart';
|
||||
|
||||
extension AppAppearanceTheme on AppAppearance {
|
||||
ThemeMode get themeMode => switch (this) {
|
||||
AppAppearance.system => ThemeMode.system,
|
||||
AppAppearance.penLight => ThemeMode.light,
|
||||
AppAppearance.penDark => ThemeMode.dark,
|
||||
};
|
||||
}
|
||||
|
||||
@Riverpod(keepAlive: true)
|
||||
class AppearanceSettings extends _$AppearanceSettings {
|
||||
final _writes = SettingsWriteQueue();
|
||||
|
||||
@override
|
||||
Future<AppAppearance> build() =>
|
||||
ref.watch(appearanceSettingsRepositoryProvider).load();
|
||||
|
||||
Future<void> setMode(AppAppearance appearance) => _writes.run(() async {
|
||||
if (!ref.mounted) return;
|
||||
await future;
|
||||
if (!ref.mounted) return;
|
||||
await ref.read(appearanceSettingsRepositoryProvider).save(appearance);
|
||||
if (ref.mounted) state = AsyncData(appearance);
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
part of 'appearance_settings.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// RiverpodGenerator
|
||||
// **************************************************************************
|
||||
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
// ignore_for_file: type=lint, type=warning
|
||||
|
||||
@ProviderFor(AppearanceSettings)
|
||||
final appearanceSettingsProvider = AppearanceSettingsProvider._();
|
||||
|
||||
final class AppearanceSettingsProvider
|
||||
extends $AsyncNotifierProvider<AppearanceSettings, AppAppearance> {
|
||||
AppearanceSettingsProvider._()
|
||||
: super(
|
||||
from: null,
|
||||
argument: null,
|
||||
retry: null,
|
||||
name: r'appearanceSettingsProvider',
|
||||
isAutoDispose: false,
|
||||
dependencies: null,
|
||||
$allTransitiveDependencies: null,
|
||||
);
|
||||
|
||||
@override
|
||||
String debugGetCreateSourceHash() => _$appearanceSettingsHash();
|
||||
|
||||
@$internal
|
||||
@override
|
||||
AppearanceSettings create() => AppearanceSettings();
|
||||
}
|
||||
|
||||
String _$appearanceSettingsHash() =>
|
||||
r'df889bcd3ec16a726ebc1bccd98b9e7033989a69';
|
||||
|
||||
abstract class _$AppearanceSettings extends $AsyncNotifier<AppAppearance> {
|
||||
FutureOr<AppAppearance> build();
|
||||
@$mustCallSuper
|
||||
@override
|
||||
WhenComplete runBuild() {
|
||||
final ref = this.ref as $Ref<AsyncValue<AppAppearance>, AppAppearance>;
|
||||
final element =
|
||||
ref.element
|
||||
as $ClassProviderElement<
|
||||
AnyNotifier<AsyncValue<AppAppearance>, AppAppearance>,
|
||||
AsyncValue<AppAppearance>,
|
||||
Object?,
|
||||
Object?
|
||||
>;
|
||||
return element.handleCreate(ref, build);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:cutdex_ui/widgets.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
|
||||
import '../../diagnostics/app_diagnostics.dart';
|
||||
import '../../integrations/platform/file_picker.dart';
|
||||
import '../../l10n/l10n.dart';
|
||||
import '../../settings/settings_operation.dart';
|
||||
|
||||
class DiagnosticSettings extends ConsumerStatefulWidget {
|
||||
const DiagnosticSettings({super.key});
|
||||
|
||||
@override
|
||||
ConsumerState<DiagnosticSettings> createState() => _DiagnosticSettingsState();
|
||||
}
|
||||
|
||||
class _DiagnosticSettingsState extends ConsumerState<DiagnosticSettings> {
|
||||
bool _exported = false;
|
||||
|
||||
Future<void> _export() async {
|
||||
setState(() => _exported = false);
|
||||
final picker = ref.read(filePickerProvider);
|
||||
await ref.read(settingsOperationProvider('diagnosticsExport').notifier).run(
|
||||
() async {
|
||||
final selected = await picker.pickDirectory();
|
||||
if (selected == null) return;
|
||||
final diagnostics =
|
||||
AppDiagnostics.instance ?? await AppDiagnostics.initialize();
|
||||
await diagnostics.export(Directory(selected));
|
||||
if (mounted) setState(() => _exported = true);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final operation = ref.watch(settingsOperationProvider('diagnosticsExport'));
|
||||
return AppField(
|
||||
label: context.l10n.diagnostics,
|
||||
orientation: AppFieldOrientation.horizontal,
|
||||
error: operation.hasError ? context.l10n.exportDiagnosticsFailed : null,
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.end,
|
||||
children: [
|
||||
OutlinedButton(
|
||||
key: const Key('export-diagnostics'),
|
||||
onPressed: operation.isLoading ? null : _export,
|
||||
child: Text(context.l10n.exportDiagnostics),
|
||||
),
|
||||
if (_exported) Text(context.l10n.exportDiagnosticsSucceeded),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,97 @@
|
||||
import 'package:flutter/widgets.dart';
|
||||
import 'package:riverpod_annotation/riverpod_annotation.dart';
|
||||
|
||||
import '../../persistence/settings/language_settings_repository.dart';
|
||||
import '../../settings/language.dart';
|
||||
import '../../settings/settings_write_queue.dart';
|
||||
|
||||
export '../../settings/language.dart';
|
||||
|
||||
part 'language_settings.g.dart';
|
||||
|
||||
extension AppLanguagePresentation on AppLanguage {
|
||||
Locale? get locale => switch (this) {
|
||||
AppLanguage.system => null,
|
||||
AppLanguage.english => const Locale('en'),
|
||||
AppLanguage.simplifiedChinese => const Locale.fromSubtags(
|
||||
languageCode: 'zh',
|
||||
scriptCode: 'Hans',
|
||||
),
|
||||
AppLanguage.traditionalChinese => const Locale.fromSubtags(
|
||||
languageCode: 'zh',
|
||||
scriptCode: 'Hant',
|
||||
),
|
||||
AppLanguage.japanese => const Locale('ja'),
|
||||
AppLanguage.korean => const Locale('ko'),
|
||||
AppLanguage.french => const Locale('fr'),
|
||||
AppLanguage.german => const Locale('de'),
|
||||
AppLanguage.spanish => const Locale('es'),
|
||||
AppLanguage.portuguese => const Locale('pt'),
|
||||
AppLanguage.italian => const Locale('it'),
|
||||
AppLanguage.russian => const Locale('ru'),
|
||||
};
|
||||
|
||||
String get nativeName => switch (this) {
|
||||
AppLanguage.system => '',
|
||||
AppLanguage.english => 'English',
|
||||
AppLanguage.simplifiedChinese => '简体中文',
|
||||
AppLanguage.traditionalChinese => '繁體中文',
|
||||
AppLanguage.japanese => '日本語',
|
||||
AppLanguage.korean => '한국어',
|
||||
AppLanguage.french => 'Français',
|
||||
AppLanguage.german => 'Deutsch',
|
||||
AppLanguage.spanish => 'Español',
|
||||
AppLanguage.portuguese => 'Português',
|
||||
AppLanguage.italian => 'Italiano',
|
||||
AppLanguage.russian => 'Русский',
|
||||
};
|
||||
}
|
||||
|
||||
/// Select a supported language in device preference order, resolving Chinese
|
||||
/// scripts explicitly when the operating system supplies only a region.
|
||||
Locale resolveAppLocale(
|
||||
List<Locale>? preferredLocales,
|
||||
Iterable<Locale> supportedLocales,
|
||||
) {
|
||||
for (final preferred in preferredLocales ?? const <Locale>[]) {
|
||||
if (preferred.languageCode == 'zh') {
|
||||
final script =
|
||||
preferred.scriptCode ??
|
||||
(const {'TW', 'HK', 'MO'}.contains(preferred.countryCode)
|
||||
? 'Hant'
|
||||
: 'Hans');
|
||||
final match = supportedLocales
|
||||
.where(
|
||||
(locale) =>
|
||||
locale.languageCode == 'zh' && locale.scriptCode == script,
|
||||
)
|
||||
.firstOrNull;
|
||||
if (match != null) return match;
|
||||
}
|
||||
final match = supportedLocales
|
||||
.where((locale) => locale.languageCode == preferred.languageCode)
|
||||
.firstOrNull;
|
||||
if (match != null) return match;
|
||||
}
|
||||
return supportedLocales
|
||||
.where((locale) => locale.languageCode == 'en')
|
||||
.firstOrNull ??
|
||||
supportedLocales.first;
|
||||
}
|
||||
|
||||
@Riverpod(keepAlive: true)
|
||||
class LanguageSettings extends _$LanguageSettings {
|
||||
final _writes = SettingsWriteQueue();
|
||||
|
||||
@override
|
||||
Future<AppLanguage> build() =>
|
||||
ref.watch(languageSettingsRepositoryProvider).load();
|
||||
|
||||
Future<void> setLanguage(AppLanguage language) => _writes.run(() async {
|
||||
if (!ref.mounted) return;
|
||||
await future;
|
||||
if (!ref.mounted) return;
|
||||
await ref.read(languageSettingsRepositoryProvider).save(language);
|
||||
if (ref.mounted) state = AsyncData(language);
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
part of 'language_settings.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// RiverpodGenerator
|
||||
// **************************************************************************
|
||||
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
// ignore_for_file: type=lint, type=warning
|
||||
|
||||
@ProviderFor(LanguageSettings)
|
||||
final languageSettingsProvider = LanguageSettingsProvider._();
|
||||
|
||||
final class LanguageSettingsProvider
|
||||
extends $AsyncNotifierProvider<LanguageSettings, AppLanguage> {
|
||||
LanguageSettingsProvider._()
|
||||
: super(
|
||||
from: null,
|
||||
argument: null,
|
||||
retry: null,
|
||||
name: r'languageSettingsProvider',
|
||||
isAutoDispose: false,
|
||||
dependencies: null,
|
||||
$allTransitiveDependencies: null,
|
||||
);
|
||||
|
||||
@override
|
||||
String debugGetCreateSourceHash() => _$languageSettingsHash();
|
||||
|
||||
@$internal
|
||||
@override
|
||||
LanguageSettings create() => LanguageSettings();
|
||||
}
|
||||
|
||||
String _$languageSettingsHash() => r'fcd5bb7f010ea5bb09f9743d9023cd1668214f43';
|
||||
|
||||
abstract class _$LanguageSettings extends $AsyncNotifier<AppLanguage> {
|
||||
FutureOr<AppLanguage> build();
|
||||
@$mustCallSuper
|
||||
@override
|
||||
WhenComplete runBuild() {
|
||||
final ref = this.ref as $Ref<AsyncValue<AppLanguage>, AppLanguage>;
|
||||
final element =
|
||||
ref.element
|
||||
as $ClassProviderElement<
|
||||
AnyNotifier<AsyncValue<AppLanguage>, AppLanguage>,
|
||||
AsyncValue<AppLanguage>,
|
||||
Object?,
|
||||
Object?
|
||||
>;
|
||||
return element.handleCreate(ref, build);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,139 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:freezed_annotation/freezed_annotation.dart';
|
||||
import 'package:riverpod_annotation/riverpod_annotation.dart';
|
||||
|
||||
import '../../integrations/runtime/processing_resource_repository.dart';
|
||||
import '../../persistence/settings/location_settings_repositories.dart';
|
||||
import '../../settings/settings_write_queue.dart';
|
||||
import '../../workspace/persistence/project_location_directory.dart';
|
||||
|
||||
part 'location_settings.g.dart';
|
||||
part 'location_settings.freezed.dart';
|
||||
|
||||
enum LocationSettingsError { load, save }
|
||||
|
||||
@freezed
|
||||
abstract class LocationSettingsState with _$LocationSettingsState {
|
||||
const factory LocationSettingsState({
|
||||
String? directory,
|
||||
ProjectLocationStatus? status,
|
||||
@Default(true) bool loading,
|
||||
@Default(false) bool saving,
|
||||
LocationSettingsError? error,
|
||||
}) = _LocationSettingsState;
|
||||
}
|
||||
|
||||
@riverpod
|
||||
ProjectLocationDirectory projectLocationDirectory(Ref ref) =>
|
||||
const ProjectLocationDirectory();
|
||||
|
||||
@riverpod
|
||||
class ProjectLocationSettings extends _$ProjectLocationSettings {
|
||||
final _writes = SettingsWriteQueue();
|
||||
|
||||
@override
|
||||
LocationSettingsState build() {
|
||||
final repository = ref.watch(projectLocationSettingsRepositoryProvider);
|
||||
final directory = ref.watch(projectLocationDirectoryProvider);
|
||||
unawaited(_writes.run(() => _load(repository, directory)));
|
||||
return const LocationSettingsState();
|
||||
}
|
||||
|
||||
Future<void> reload() => _writes.run(() async {
|
||||
if (!ref.mounted) return;
|
||||
await _load(
|
||||
ref.read(projectLocationSettingsRepositoryProvider),
|
||||
ref.read(projectLocationDirectoryProvider),
|
||||
);
|
||||
});
|
||||
|
||||
Future<void> _load(
|
||||
ProjectLocationSettingsRepository repository,
|
||||
ProjectLocationDirectory inspector,
|
||||
) async {
|
||||
if (!ref.mounted) return;
|
||||
state = state.copyWith(loading: true, error: null, status: null);
|
||||
try {
|
||||
final directory = await repository.load();
|
||||
if (!ref.mounted) return;
|
||||
state = state.copyWith(directory: directory);
|
||||
final status = directory == null
|
||||
? null
|
||||
: await inspector.inspect(directory);
|
||||
if (ref.mounted) state = state.copyWith(status: status);
|
||||
} catch (_) {
|
||||
if (ref.mounted) {
|
||||
state = state.copyWith(error: LocationSettingsError.load);
|
||||
}
|
||||
} finally {
|
||||
if (ref.mounted) state = state.copyWith(loading: false);
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> save(String directory) => _writes.run(() async {
|
||||
if (!ref.mounted) return;
|
||||
final keepAlive = ref.keepAlive();
|
||||
state = state.copyWith(saving: true, error: null);
|
||||
final repository = ref.read(projectLocationSettingsRepositoryProvider);
|
||||
final inspector = ref.read(projectLocationDirectoryProvider);
|
||||
try {
|
||||
await repository.save(directory);
|
||||
if (ref.mounted) await _load(repository, inspector);
|
||||
} catch (_) {
|
||||
if (ref.mounted) {
|
||||
state = state.copyWith(error: LocationSettingsError.save);
|
||||
}
|
||||
} finally {
|
||||
if (ref.mounted) state = state.copyWith(saving: false);
|
||||
keepAlive.close();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@riverpod
|
||||
class ResourceLocationSettings extends _$ResourceLocationSettings {
|
||||
final _writes = SettingsWriteQueue();
|
||||
|
||||
@override
|
||||
LocationSettingsState build() {
|
||||
final repository = ref.watch(resourceLocationSettingsRepositoryProvider);
|
||||
unawaited(_writes.run(() => _load(repository)));
|
||||
return const LocationSettingsState();
|
||||
}
|
||||
|
||||
Future<void> _load(ResourceLocationSettingsRepository repository) async {
|
||||
if (!ref.mounted) return;
|
||||
try {
|
||||
final directory = await repository.load();
|
||||
if (ref.mounted) state = state.copyWith(directory: directory);
|
||||
} catch (_) {
|
||||
if (ref.mounted) {
|
||||
state = state.copyWith(error: LocationSettingsError.load);
|
||||
}
|
||||
} finally {
|
||||
if (ref.mounted) state = state.copyWith(loading: false);
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> save(String directory) => _writes.run(() async {
|
||||
if (!ref.mounted) return;
|
||||
final keepAlive = ref.keepAlive();
|
||||
state = state.copyWith(saving: true, error: null);
|
||||
try {
|
||||
await ref
|
||||
.read(resourceLocationSettingsRepositoryProvider)
|
||||
.save(directory);
|
||||
if (!ref.mounted) return;
|
||||
ref.invalidate(processingResourceRepositoryProvider);
|
||||
state = state.copyWith(directory: directory);
|
||||
} catch (_) {
|
||||
if (ref.mounted) {
|
||||
state = state.copyWith(error: LocationSettingsError.save);
|
||||
}
|
||||
} finally {
|
||||
if (ref.mounted) state = state.copyWith(saving: false);
|
||||
keepAlive.close();
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,450 @@
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
// coverage:ignore-file
|
||||
// ignore_for_file: type=lint, type=warning, deprecated_member_use, deprecated_member_use_from_same_package
|
||||
// ignore_for_file: unused_element, deprecated_member_use, deprecated_member_use_from_same_package, use_function_type_syntax_for_parameters, unnecessary_const, avoid_init_to_null, invalid_override_different_default_values_named, prefer_expression_function_bodies, annotate_overrides, invalid_annotation_target, unnecessary_question_mark
|
||||
|
||||
part of 'location_settings.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// FreezedGenerator
|
||||
// **************************************************************************
|
||||
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
T _$identity<T>(T value) => value;
|
||||
|
||||
/// @nodoc
|
||||
mixin _$LocationSettingsState {
|
||||
String? get directory;
|
||||
ProjectLocationStatus? get status;
|
||||
bool get loading;
|
||||
bool get saving;
|
||||
LocationSettingsError? get error;
|
||||
|
||||
/// Create a copy of LocationSettingsState
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@JsonKey(includeFromJson: false, includeToJson: false)
|
||||
@pragma('vm:prefer-inline')
|
||||
$LocationSettingsStateCopyWith<LocationSettingsState> get copyWith =>
|
||||
_$LocationSettingsStateCopyWithImpl<LocationSettingsState>(
|
||||
this as LocationSettingsState,
|
||||
_$identity,
|
||||
);
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) {
|
||||
final _this = this as LocationSettingsState;
|
||||
return identical(this, other) ||
|
||||
(other.runtimeType == runtimeType &&
|
||||
other is LocationSettingsState &&
|
||||
(identical(other.directory, _this.directory) ||
|
||||
other.directory == _this.directory) &&
|
||||
(identical(other.status, _this.status) ||
|
||||
other.status == _this.status) &&
|
||||
(identical(other.loading, _this.loading) ||
|
||||
other.loading == _this.loading) &&
|
||||
(identical(other.saving, _this.saving) ||
|
||||
other.saving == _this.saving) &&
|
||||
(identical(other.error, _this.error) ||
|
||||
other.error == _this.error));
|
||||
}
|
||||
|
||||
@override
|
||||
int get hashCode {
|
||||
final _this = this as LocationSettingsState;
|
||||
return Object.hash(
|
||||
runtimeType,
|
||||
_this.directory,
|
||||
_this.status,
|
||||
_this.loading,
|
||||
_this.saving,
|
||||
_this.error,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
final _this = this as LocationSettingsState;
|
||||
return 'LocationSettingsState(directory: ${_this.directory}, status: ${_this.status}, loading: ${_this.loading}, saving: ${_this.saving}, error: ${_this.error})';
|
||||
}
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
abstract mixin class $LocationSettingsStateCopyWith<$Res> {
|
||||
factory $LocationSettingsStateCopyWith(
|
||||
LocationSettingsState value,
|
||||
$Res Function(LocationSettingsState) _then,
|
||||
) = _$LocationSettingsStateCopyWithImpl;
|
||||
@useResult
|
||||
$Res call({
|
||||
String? directory,
|
||||
ProjectLocationStatus? status,
|
||||
bool loading,
|
||||
bool saving,
|
||||
LocationSettingsError? error,
|
||||
});
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
class _$LocationSettingsStateCopyWithImpl<$Res>
|
||||
implements $LocationSettingsStateCopyWith<$Res> {
|
||||
_$LocationSettingsStateCopyWithImpl(this._self, this._then);
|
||||
|
||||
final LocationSettingsState _self;
|
||||
final $Res Function(LocationSettingsState) _then;
|
||||
|
||||
/// Create a copy of LocationSettingsState
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@pragma('vm:prefer-inline')
|
||||
@override
|
||||
$Res call({
|
||||
Object? directory = freezed,
|
||||
Object? status = freezed,
|
||||
Object? loading = null,
|
||||
Object? saving = null,
|
||||
Object? error = freezed,
|
||||
}) {
|
||||
return _then(
|
||||
LocationSettingsState(
|
||||
directory: freezed == directory
|
||||
? _self.directory
|
||||
: directory // ignore: cast_nullable_to_non_nullable
|
||||
as String?,
|
||||
status: freezed == status
|
||||
? _self.status
|
||||
: status // ignore: cast_nullable_to_non_nullable
|
||||
as ProjectLocationStatus?,
|
||||
loading: null == loading
|
||||
? _self.loading
|
||||
: loading // ignore: cast_nullable_to_non_nullable
|
||||
as bool,
|
||||
saving: null == saving
|
||||
? _self.saving
|
||||
: saving // ignore: cast_nullable_to_non_nullable
|
||||
as bool,
|
||||
error: freezed == error
|
||||
? _self.error
|
||||
: error // ignore: cast_nullable_to_non_nullable
|
||||
as LocationSettingsError?,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// Adds pattern-matching-related methods to [LocationSettingsState].
|
||||
extension LocationSettingsStatePatterns on LocationSettingsState {
|
||||
/// A variant of `map` that fallback to returning `orElse`.
|
||||
///
|
||||
/// It is equivalent to doing:
|
||||
/// ```dart
|
||||
/// switch (sealedClass) {
|
||||
/// case final Subclass value:
|
||||
/// return ...;
|
||||
/// case _:
|
||||
/// return orElse();
|
||||
/// }
|
||||
/// ```
|
||||
|
||||
@optionalTypeArgs
|
||||
TResult maybeMap<TResult extends Object?>(
|
||||
TResult Function(_LocationSettingsState value)? $default, {
|
||||
required TResult orElse(),
|
||||
}) {
|
||||
final _that = this;
|
||||
switch (_that) {
|
||||
case _LocationSettingsState() when $default != null:
|
||||
return $default(_that);
|
||||
case _:
|
||||
return orElse();
|
||||
}
|
||||
}
|
||||
|
||||
/// A `switch`-like method, using callbacks.
|
||||
///
|
||||
/// Callbacks receives the raw object, upcasted.
|
||||
/// It is equivalent to doing:
|
||||
/// ```dart
|
||||
/// switch (sealedClass) {
|
||||
/// case final Subclass value:
|
||||
/// return ...;
|
||||
/// case final Subclass2 value:
|
||||
/// return ...;
|
||||
/// }
|
||||
/// ```
|
||||
|
||||
@optionalTypeArgs
|
||||
TResult map<TResult extends Object?>(
|
||||
TResult Function(_LocationSettingsState value) $default,
|
||||
) {
|
||||
final _that = this;
|
||||
switch (_that) {
|
||||
case _LocationSettingsState():
|
||||
return $default(_that);
|
||||
case _:
|
||||
throw StateError('Unexpected subclass');
|
||||
}
|
||||
}
|
||||
|
||||
/// A variant of `map` that fallback to returning `null`.
|
||||
///
|
||||
/// It is equivalent to doing:
|
||||
/// ```dart
|
||||
/// switch (sealedClass) {
|
||||
/// case final Subclass value:
|
||||
/// return ...;
|
||||
/// case _:
|
||||
/// return null;
|
||||
/// }
|
||||
/// ```
|
||||
|
||||
@optionalTypeArgs
|
||||
TResult? mapOrNull<TResult extends Object?>(
|
||||
TResult? Function(_LocationSettingsState value)? $default,
|
||||
) {
|
||||
final _that = this;
|
||||
switch (_that) {
|
||||
case _LocationSettingsState() when $default != null:
|
||||
return $default(_that);
|
||||
case _:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/// A variant of `when` that fallback to an `orElse` callback.
|
||||
///
|
||||
/// It is equivalent to doing:
|
||||
/// ```dart
|
||||
/// switch (sealedClass) {
|
||||
/// case Subclass(:final field):
|
||||
/// return ...;
|
||||
/// case _:
|
||||
/// return orElse();
|
||||
/// }
|
||||
/// ```
|
||||
|
||||
@optionalTypeArgs
|
||||
TResult maybeWhen<TResult extends Object?>(
|
||||
TResult Function(
|
||||
String? directory,
|
||||
ProjectLocationStatus? status,
|
||||
bool loading,
|
||||
bool saving,
|
||||
LocationSettingsError? error,
|
||||
)?
|
||||
$default, {
|
||||
required TResult orElse(),
|
||||
}) {
|
||||
final _that = this;
|
||||
switch (_that) {
|
||||
case _LocationSettingsState() when $default != null:
|
||||
return $default(
|
||||
_that.directory,
|
||||
_that.status,
|
||||
_that.loading,
|
||||
_that.saving,
|
||||
_that.error,
|
||||
);
|
||||
case _:
|
||||
return orElse();
|
||||
}
|
||||
}
|
||||
|
||||
/// A `switch`-like method, using callbacks.
|
||||
///
|
||||
/// As opposed to `map`, this offers destructuring.
|
||||
/// It is equivalent to doing:
|
||||
/// ```dart
|
||||
/// switch (sealedClass) {
|
||||
/// case Subclass(:final field):
|
||||
/// return ...;
|
||||
/// case Subclass2(:final field2):
|
||||
/// return ...;
|
||||
/// }
|
||||
/// ```
|
||||
|
||||
@optionalTypeArgs
|
||||
TResult when<TResult extends Object?>(
|
||||
TResult Function(
|
||||
String? directory,
|
||||
ProjectLocationStatus? status,
|
||||
bool loading,
|
||||
bool saving,
|
||||
LocationSettingsError? error,
|
||||
)
|
||||
$default,
|
||||
) {
|
||||
final _that = this;
|
||||
switch (_that) {
|
||||
case _LocationSettingsState():
|
||||
return $default(
|
||||
_that.directory,
|
||||
_that.status,
|
||||
_that.loading,
|
||||
_that.saving,
|
||||
_that.error,
|
||||
);
|
||||
case _:
|
||||
throw StateError('Unexpected subclass');
|
||||
}
|
||||
}
|
||||
|
||||
/// A variant of `when` that fallback to returning `null`
|
||||
///
|
||||
/// It is equivalent to doing:
|
||||
/// ```dart
|
||||
/// switch (sealedClass) {
|
||||
/// case Subclass(:final field):
|
||||
/// return ...;
|
||||
/// case _:
|
||||
/// return null;
|
||||
/// }
|
||||
/// ```
|
||||
|
||||
@optionalTypeArgs
|
||||
TResult? whenOrNull<TResult extends Object?>(
|
||||
TResult? Function(
|
||||
String? directory,
|
||||
ProjectLocationStatus? status,
|
||||
bool loading,
|
||||
bool saving,
|
||||
LocationSettingsError? error,
|
||||
)?
|
||||
$default,
|
||||
) {
|
||||
final _that = this;
|
||||
switch (_that) {
|
||||
case _LocationSettingsState() when $default != null:
|
||||
return $default(
|
||||
_that.directory,
|
||||
_that.status,
|
||||
_that.loading,
|
||||
_that.saving,
|
||||
_that.error,
|
||||
);
|
||||
case _:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
|
||||
class _LocationSettingsState implements LocationSettingsState {
|
||||
const _LocationSettingsState({
|
||||
this.directory,
|
||||
this.status,
|
||||
this.loading = true,
|
||||
this.saving = false,
|
||||
this.error,
|
||||
});
|
||||
|
||||
@override
|
||||
final String? directory;
|
||||
@override
|
||||
final ProjectLocationStatus? status;
|
||||
@override
|
||||
@JsonKey()
|
||||
final bool loading;
|
||||
@override
|
||||
@JsonKey()
|
||||
final bool saving;
|
||||
@override
|
||||
final LocationSettingsError? error;
|
||||
|
||||
/// Create a copy of LocationSettingsState
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@override
|
||||
@JsonKey(includeFromJson: false, includeToJson: false)
|
||||
@pragma('vm:prefer-inline')
|
||||
_$LocationSettingsStateCopyWith<_LocationSettingsState> get copyWith =>
|
||||
__$LocationSettingsStateCopyWithImpl<_LocationSettingsState>(
|
||||
this,
|
||||
_$identity,
|
||||
);
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) {
|
||||
return identical(this, other) ||
|
||||
(other.runtimeType == runtimeType &&
|
||||
other is _LocationSettingsState &&
|
||||
(identical(other.directory, directory) ||
|
||||
other.directory == directory) &&
|
||||
(identical(other.status, status) || other.status == status) &&
|
||||
(identical(other.loading, loading) || other.loading == loading) &&
|
||||
(identical(other.saving, saving) || other.saving == saving) &&
|
||||
(identical(other.error, error) || other.error == error));
|
||||
}
|
||||
|
||||
@override
|
||||
int get hashCode {
|
||||
return Object.hash(runtimeType, directory, status, loading, saving, error);
|
||||
}
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return 'LocationSettingsState(directory: $directory, status: $status, loading: $loading, saving: $saving, error: $error)';
|
||||
}
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
abstract mixin class _$LocationSettingsStateCopyWith<$Res>
|
||||
implements $LocationSettingsStateCopyWith<$Res> {
|
||||
factory _$LocationSettingsStateCopyWith(
|
||||
_LocationSettingsState value,
|
||||
$Res Function(_LocationSettingsState) _then,
|
||||
) = __$LocationSettingsStateCopyWithImpl;
|
||||
@override
|
||||
@useResult
|
||||
$Res call({
|
||||
String? directory,
|
||||
ProjectLocationStatus? status,
|
||||
bool loading,
|
||||
bool saving,
|
||||
LocationSettingsError? error,
|
||||
});
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
class __$LocationSettingsStateCopyWithImpl<$Res>
|
||||
implements _$LocationSettingsStateCopyWith<$Res> {
|
||||
__$LocationSettingsStateCopyWithImpl(this._self, this._then);
|
||||
|
||||
final _LocationSettingsState _self;
|
||||
final $Res Function(_LocationSettingsState) _then;
|
||||
|
||||
/// Create a copy of LocationSettingsState
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@override
|
||||
@pragma('vm:prefer-inline')
|
||||
$Res call({
|
||||
Object? directory = freezed,
|
||||
Object? status = freezed,
|
||||
Object? loading = null,
|
||||
Object? saving = null,
|
||||
Object? error = freezed,
|
||||
}) {
|
||||
return _then(
|
||||
_LocationSettingsState(
|
||||
directory: freezed == directory
|
||||
? _self.directory
|
||||
: directory // ignore: cast_nullable_to_non_nullable
|
||||
as String?,
|
||||
status: freezed == status
|
||||
? _self.status
|
||||
: status // ignore: cast_nullable_to_non_nullable
|
||||
as ProjectLocationStatus?,
|
||||
loading: null == loading
|
||||
? _self.loading
|
||||
: loading // ignore: cast_nullable_to_non_nullable
|
||||
as bool,
|
||||
saving: null == saving
|
||||
? _self.saving
|
||||
: saving // ignore: cast_nullable_to_non_nullable
|
||||
as bool,
|
||||
error: freezed == error
|
||||
? _self.error
|
||||
: error // ignore: cast_nullable_to_non_nullable
|
||||
as LocationSettingsError?,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,166 @@
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
part of 'location_settings.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// RiverpodGenerator
|
||||
// **************************************************************************
|
||||
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
// ignore_for_file: type=lint, type=warning
|
||||
|
||||
@ProviderFor(projectLocationDirectory)
|
||||
final projectLocationDirectoryProvider = ProjectLocationDirectoryProvider._();
|
||||
|
||||
final class ProjectLocationDirectoryProvider
|
||||
extends
|
||||
$FunctionalProvider<
|
||||
ProjectLocationDirectory,
|
||||
ProjectLocationDirectory,
|
||||
ProjectLocationDirectory
|
||||
>
|
||||
with $Provider<ProjectLocationDirectory> {
|
||||
ProjectLocationDirectoryProvider._()
|
||||
: super(
|
||||
from: null,
|
||||
argument: null,
|
||||
retry: null,
|
||||
name: r'projectLocationDirectoryProvider',
|
||||
isAutoDispose: true,
|
||||
dependencies: null,
|
||||
$allTransitiveDependencies: null,
|
||||
);
|
||||
|
||||
@override
|
||||
String debugGetCreateSourceHash() => _$projectLocationDirectoryHash();
|
||||
|
||||
@$internal
|
||||
@override
|
||||
$ProviderElement<ProjectLocationDirectory> $createElement(
|
||||
$ProviderPointer pointer,
|
||||
) => $ProviderElement(pointer);
|
||||
|
||||
@override
|
||||
ProjectLocationDirectory create(Ref ref) {
|
||||
return projectLocationDirectory(ref);
|
||||
}
|
||||
|
||||
/// {@macro riverpod.override_with_value}
|
||||
Override overrideWithValue(ProjectLocationDirectory value) {
|
||||
return $ProviderOverride(
|
||||
origin: this,
|
||||
providerOverride: $SyncValueProvider<ProjectLocationDirectory>(value),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
String _$projectLocationDirectoryHash() =>
|
||||
r'a09b928fd3a8ba8db867b5226eb61ed34eb634f1';
|
||||
|
||||
@ProviderFor(ProjectLocationSettings)
|
||||
final projectLocationSettingsProvider = ProjectLocationSettingsProvider._();
|
||||
|
||||
final class ProjectLocationSettingsProvider
|
||||
extends $NotifierProvider<ProjectLocationSettings, LocationSettingsState> {
|
||||
ProjectLocationSettingsProvider._()
|
||||
: super(
|
||||
from: null,
|
||||
argument: null,
|
||||
retry: null,
|
||||
name: r'projectLocationSettingsProvider',
|
||||
isAutoDispose: true,
|
||||
dependencies: null,
|
||||
$allTransitiveDependencies: null,
|
||||
);
|
||||
|
||||
@override
|
||||
String debugGetCreateSourceHash() => _$projectLocationSettingsHash();
|
||||
|
||||
@$internal
|
||||
@override
|
||||
ProjectLocationSettings create() => ProjectLocationSettings();
|
||||
|
||||
/// {@macro riverpod.override_with_value}
|
||||
Override overrideWithValue(LocationSettingsState value) {
|
||||
return $ProviderOverride(
|
||||
origin: this,
|
||||
providerOverride: $SyncValueProvider<LocationSettingsState>(value),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
String _$projectLocationSettingsHash() =>
|
||||
r'0142e55d46997be3387944612ab0287f6fd7acf0';
|
||||
|
||||
abstract class _$ProjectLocationSettings
|
||||
extends $Notifier<LocationSettingsState> {
|
||||
LocationSettingsState build();
|
||||
@$mustCallSuper
|
||||
@override
|
||||
WhenComplete runBuild() {
|
||||
final ref = this.ref as $Ref<LocationSettingsState, LocationSettingsState>;
|
||||
final element =
|
||||
ref.element
|
||||
as $ClassProviderElement<
|
||||
AnyNotifier<LocationSettingsState, LocationSettingsState>,
|
||||
LocationSettingsState,
|
||||
Object?,
|
||||
Object?
|
||||
>;
|
||||
return element.handleCreate(ref, build);
|
||||
}
|
||||
}
|
||||
|
||||
@ProviderFor(ResourceLocationSettings)
|
||||
final resourceLocationSettingsProvider = ResourceLocationSettingsProvider._();
|
||||
|
||||
final class ResourceLocationSettingsProvider
|
||||
extends $NotifierProvider<ResourceLocationSettings, LocationSettingsState> {
|
||||
ResourceLocationSettingsProvider._()
|
||||
: super(
|
||||
from: null,
|
||||
argument: null,
|
||||
retry: null,
|
||||
name: r'resourceLocationSettingsProvider',
|
||||
isAutoDispose: true,
|
||||
dependencies: null,
|
||||
$allTransitiveDependencies: null,
|
||||
);
|
||||
|
||||
@override
|
||||
String debugGetCreateSourceHash() => _$resourceLocationSettingsHash();
|
||||
|
||||
@$internal
|
||||
@override
|
||||
ResourceLocationSettings create() => ResourceLocationSettings();
|
||||
|
||||
/// {@macro riverpod.override_with_value}
|
||||
Override overrideWithValue(LocationSettingsState value) {
|
||||
return $ProviderOverride(
|
||||
origin: this,
|
||||
providerOverride: $SyncValueProvider<LocationSettingsState>(value),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
String _$resourceLocationSettingsHash() =>
|
||||
r'8d9482cd3580029c65fc541c4c8f2d296bce5ad3';
|
||||
|
||||
abstract class _$ResourceLocationSettings
|
||||
extends $Notifier<LocationSettingsState> {
|
||||
LocationSettingsState build();
|
||||
@$mustCallSuper
|
||||
@override
|
||||
WhenComplete runBuild() {
|
||||
final ref = this.ref as $Ref<LocationSettingsState, LocationSettingsState>;
|
||||
final element =
|
||||
ref.element
|
||||
as $ClassProviderElement<
|
||||
AnyNotifier<LocationSettingsState, LocationSettingsState>,
|
||||
LocationSettingsState,
|
||||
Object?,
|
||||
Object?
|
||||
>;
|
||||
return element.handleCreate(ref, build);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,155 @@
|
||||
import 'package:cutdex/l10n/l10n.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
|
||||
import '../../integrations/editor_tools.dart';
|
||||
|
||||
import 'package:cutdex_ui/widgets.dart';
|
||||
import 'package:cutdex_ui/theme.dart';
|
||||
|
||||
import '../../integrations/mcp/mcp_settings.dart';
|
||||
import 'settings_layout.dart';
|
||||
import '../../settings/settings_operation.dart';
|
||||
|
||||
class McpSettingsPanel extends ConsumerStatefulWidget {
|
||||
const McpSettingsPanel({super.key, this.workspace});
|
||||
final (String, String)? workspace;
|
||||
|
||||
@override
|
||||
ConsumerState<McpSettingsPanel> createState() => _McpSettingsPanelState();
|
||||
}
|
||||
|
||||
class _McpSettingsPanelState extends ConsumerState<McpSettingsPanel> {
|
||||
String? _port;
|
||||
String? _error;
|
||||
|
||||
Future<void> _toggle(bool enabled, McpSettingsValue settings) async {
|
||||
final port = int.tryParse(_port ?? '${settings.port}');
|
||||
if (enabled && (port == null || port < 1 || port > 65535)) {
|
||||
setState(() => _error = context.l10n.invalidPort);
|
||||
return;
|
||||
}
|
||||
setState(() => _error = null);
|
||||
await ref
|
||||
.read(settingsOperationProvider('mcp').notifier)
|
||||
.run(
|
||||
() => ref
|
||||
.read(mcpSettingsProvider.notifier)
|
||||
.saveSettings(enabled: enabled, port: enabled ? port : null),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) => Theme(
|
||||
data: AppTheme.settingsContentTheme(Theme.of(context)),
|
||||
child: Builder(builder: _buildContent),
|
||||
);
|
||||
|
||||
Widget _buildContent(BuildContext context) {
|
||||
final operation = ref.watch(settingsOperationProvider('mcp'));
|
||||
final error =
|
||||
_error ?? (operation.hasError ? context.l10n.saveMcpFailed : null);
|
||||
final settings = ref.watch(mcpSettingsProvider);
|
||||
final value = settings.asData?.value;
|
||||
final ids = widget.workspace;
|
||||
final connection = ids == null
|
||||
? null
|
||||
: ref.watch(editorMcpConnectionProvider(ids.$1, ids.$2));
|
||||
final status = value?.enabled != true
|
||||
? context.l10n.disabled
|
||||
: ids == null
|
||||
? context.l10n.waitingForProject
|
||||
: connection!.hasError
|
||||
? context.l10n.startFailed
|
||||
: connection.isLoading
|
||||
? context.l10n.starting
|
||||
: context.l10n.running;
|
||||
return SettingsPageSection(
|
||||
title: 'MCP',
|
||||
icon: Icons.terminal_outlined,
|
||||
children: [
|
||||
AppField(
|
||||
label: context.l10n.mcpService,
|
||||
description: settings.isLoading
|
||||
? context.l10n.loadingSettings
|
||||
: status,
|
||||
orientation: AppFieldOrientation.horizontal,
|
||||
child: Align(
|
||||
alignment: AlignmentDirectional.centerEnd,
|
||||
child: AppSwitch(
|
||||
semanticLabel: context.l10n.mcpService,
|
||||
value: value?.enabled ?? false,
|
||||
onChanged: value == null || operation.isLoading
|
||||
? null
|
||||
: (enabled) => _toggle(enabled, value),
|
||||
),
|
||||
),
|
||||
),
|
||||
if (value != null) ...[
|
||||
AppField(
|
||||
orientation: AppFieldOrientation.horizontal,
|
||||
label: context.l10n.listenPort,
|
||||
child: SizedBox(
|
||||
width: AppSettingsMetrics.controlWidth,
|
||||
child: TextFormField(
|
||||
style: AppTheme.inputTextStyle(context),
|
||||
cursorHeight: AppTheme.inputCursorHeight(context),
|
||||
initialValue: '${value.port}',
|
||||
enabled: !value.enabled && !operation.isLoading,
|
||||
keyboardType: TextInputType.number,
|
||||
decoration: const InputDecoration(
|
||||
isDense: true,
|
||||
prefixText: '127.0.0.1 : ',
|
||||
),
|
||||
onChanged: (text) => _port = text,
|
||||
),
|
||||
),
|
||||
),
|
||||
AppField(
|
||||
orientation: AppFieldOrientation.horizontal,
|
||||
label: context.l10n.accessToken,
|
||||
child: IconButton(
|
||||
tooltip: context.l10n.copyAccessToken,
|
||||
icon: const Icon(Icons.copy_outlined),
|
||||
onPressed: () async {
|
||||
await Clipboard.setData(ClipboardData(text: value.token));
|
||||
if (context.mounted) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(content: Text(context.l10n.accessTokenCopied)),
|
||||
);
|
||||
}
|
||||
},
|
||||
),
|
||||
),
|
||||
],
|
||||
if (settings.hasError)
|
||||
TextButton(
|
||||
onPressed: () => ref.invalidate(mcpSettingsProvider),
|
||||
child: Text(context.l10n.loadMcpFailed),
|
||||
),
|
||||
if (value?.enabled == true && connection?.hasError == true) ...[
|
||||
Text(
|
||||
context.l10n.mcpStartError(
|
||||
context.l10n.errorMessage(connection!.error!),
|
||||
),
|
||||
style: TextStyle(color: Theme.of(context).colorScheme.error),
|
||||
),
|
||||
TextButton(
|
||||
onPressed: operation.isLoading
|
||||
? null
|
||||
: () => ref.invalidate(
|
||||
editorMcpConnectionProvider(ids!.$1, ids.$2),
|
||||
),
|
||||
child: Text(context.l10n.retryStart),
|
||||
),
|
||||
],
|
||||
if (error != null)
|
||||
Text(
|
||||
error,
|
||||
style: TextStyle(color: Theme.of(context).colorScheme.error),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,519 @@
|
||||
import 'package:cutdex/l10n/l10n.dart';
|
||||
|
||||
import 'dart:math' as math;
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
|
||||
import '../../integrations/platform/file_picker.dart';
|
||||
|
||||
import '../../workspace/persistence/project_location_directory.dart';
|
||||
|
||||
import 'package:cutdex_ui/theme.dart';
|
||||
import 'package:cutdex_ui/widgets.dart';
|
||||
|
||||
import 'appearance_settings.dart';
|
||||
import 'language_settings.dart';
|
||||
import 'location_settings.dart';
|
||||
import 'mcp_settings_panel.dart';
|
||||
import 'settings_layout.dart';
|
||||
import '../../settings/settings_operation.dart';
|
||||
import 'update_settings.dart';
|
||||
import 'diagnostic_settings.dart';
|
||||
import 'agent_settings_panel.dart';
|
||||
|
||||
const _settingsContentPadding = EdgeInsets.fromLTRB(20, 48, 20, 20);
|
||||
|
||||
Future<void> showSettingsDialog(
|
||||
BuildContext context, {
|
||||
(String, String)? workspace,
|
||||
int initialTab = 0,
|
||||
}) => showAppDialog<void>(
|
||||
context: Navigator.of(context, rootNavigator: true).context,
|
||||
builder: (_) => SettingsDialog(workspace: workspace, initialTab: initialTab),
|
||||
);
|
||||
|
||||
class SettingsDialog extends ConsumerStatefulWidget {
|
||||
const SettingsDialog({super.key, this.workspace, this.initialTab = 0})
|
||||
: assert(initialTab >= 0 && initialTab <= 2);
|
||||
|
||||
final int initialTab;
|
||||
|
||||
final (String, String)? workspace;
|
||||
|
||||
@override
|
||||
ConsumerState<SettingsDialog> createState() => _SettingsDialogState();
|
||||
}
|
||||
|
||||
class _SettingsDialogState extends ConsumerState<SettingsDialog> {
|
||||
late int _tab = widget.initialTab;
|
||||
|
||||
Future<void> _setMode(AppAppearance appearance) async {
|
||||
await ref
|
||||
.read(settingsOperationProvider('appearance').notifier)
|
||||
.run(
|
||||
() =>
|
||||
ref.read(appearanceSettingsProvider.notifier).setMode(appearance),
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> _setLanguage(AppLanguage language) async {
|
||||
await ref
|
||||
.read(settingsOperationProvider('language').notifier)
|
||||
.run(
|
||||
() =>
|
||||
ref.read(languageSettingsProvider.notifier).setLanguage(language),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) => Theme(
|
||||
data: AppTheme.settingsContentTheme(Theme.of(context)),
|
||||
child: Builder(builder: _buildDialog),
|
||||
);
|
||||
|
||||
Widget _buildDialog(BuildContext context) {
|
||||
final appearanceSave = ref.watch(settingsOperationProvider('appearance'));
|
||||
final languageSave = ref.watch(settingsOperationProvider('language'));
|
||||
final appearance = ref.watch(appearanceSettingsProvider);
|
||||
final language = ref.watch(languageSettingsProvider);
|
||||
final viewport = MediaQuery.sizeOf(context);
|
||||
return AppDialog(
|
||||
title: context.l10n.settings,
|
||||
closeLabel: context.l10n.closeSettings,
|
||||
width: math.min(1120, math.max(560, viewport.width * .9)),
|
||||
height: math.min(704, math.max(520, viewport.height * .88)),
|
||||
contentOnly: true,
|
||||
scrollContent: false,
|
||||
child: LayoutBuilder(
|
||||
builder: (context, constraints) => Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
SizedBox(
|
||||
width: constraints.maxWidth < 600 ? 96 : 220,
|
||||
child: _SettingsNavigation(
|
||||
value: _tab,
|
||||
compact: constraints.maxWidth < 600,
|
||||
onChanged: (value) => setState(() => _tab = value),
|
||||
),
|
||||
),
|
||||
VerticalDivider(
|
||||
key: const Key('settings-sidebar-divider'),
|
||||
width: 1,
|
||||
thickness: 1,
|
||||
color: Theme.of(context).colorScheme.outlineVariant,
|
||||
),
|
||||
Expanded(
|
||||
child: ColoredBox(
|
||||
color: Theme.of(context).colorScheme.surface,
|
||||
child: IndexedStack(
|
||||
index: _tab,
|
||||
children: [
|
||||
ExcludeFocus(
|
||||
excluding: _tab != 0,
|
||||
child: TickerMode(
|
||||
enabled: _tab == 0,
|
||||
child: SingleChildScrollView(
|
||||
primary: false,
|
||||
padding: _settingsContentPadding,
|
||||
child: SettingsPageSection(
|
||||
title: context.l10n.general,
|
||||
icon: Icons.settings_outlined,
|
||||
children: [
|
||||
AppField(
|
||||
label: context.l10n.appearance,
|
||||
orientation: AppFieldOrientation.horizontal,
|
||||
error:
|
||||
(appearanceSave.hasError
|
||||
? context.l10n.saveAppearanceFailed
|
||||
: null) ??
|
||||
(appearance.hasError
|
||||
? context.l10n.loadAppearanceFailed
|
||||
: null),
|
||||
child: SizedBox(
|
||||
width: AppSettingsMetrics.controlWidth,
|
||||
child: AppSelect<AppAppearance>(
|
||||
emptyLabel: context.l10n.noMatchingOptions,
|
||||
controlHeight:
|
||||
AppSettingsMetrics.controlHeight,
|
||||
value:
|
||||
appearance.asData?.value ??
|
||||
AppAppearance.system,
|
||||
label: context.l10n.theme,
|
||||
options: [
|
||||
AppSelectOption(
|
||||
AppAppearance.system,
|
||||
context.l10n.system,
|
||||
),
|
||||
AppSelectOption(
|
||||
AppAppearance.penLight,
|
||||
'Pen · ${context.l10n.light}',
|
||||
),
|
||||
AppSelectOption(
|
||||
AppAppearance.penDark,
|
||||
'Pen · ${context.l10n.dark}',
|
||||
),
|
||||
],
|
||||
onChanged:
|
||||
appearanceSave.isLoading ||
|
||||
appearance.isLoading
|
||||
? null
|
||||
: _setMode,
|
||||
),
|
||||
),
|
||||
),
|
||||
AppField(
|
||||
label: context.l10n.language,
|
||||
orientation: AppFieldOrientation.horizontal,
|
||||
error:
|
||||
(languageSave.hasError
|
||||
? context.l10n.saveLanguageFailed
|
||||
: null) ??
|
||||
(language.hasError
|
||||
? context.l10n.loadLanguageFailed
|
||||
: null),
|
||||
child: SizedBox(
|
||||
width: AppSettingsMetrics.controlWidth,
|
||||
child: AppSelect<AppLanguage>(
|
||||
emptyLabel: context.l10n.noMatchingOptions,
|
||||
controlHeight:
|
||||
AppSettingsMetrics.controlHeight,
|
||||
value:
|
||||
language.asData?.value ??
|
||||
AppLanguage.system,
|
||||
label: context.l10n.language,
|
||||
options: [
|
||||
for (final option in AppLanguage.values)
|
||||
AppSelectOption(
|
||||
option,
|
||||
option == AppLanguage.system
|
||||
? context.l10n.system
|
||||
: option.nativeName,
|
||||
),
|
||||
],
|
||||
onChanged:
|
||||
languageSave.isLoading ||
|
||||
language.isLoading
|
||||
? null
|
||||
: _setLanguage,
|
||||
),
|
||||
),
|
||||
),
|
||||
const _ProjectLocationField(),
|
||||
const _ResourceLocationField(),
|
||||
const UpdateSettings(),
|
||||
const DiagnosticSettings(),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
ExcludeFocus(
|
||||
excluding: _tab != 1,
|
||||
child: TickerMode(
|
||||
enabled: _tab == 1,
|
||||
child: const AgentSettingsPanel(
|
||||
contentPadding: _settingsContentPadding,
|
||||
),
|
||||
),
|
||||
),
|
||||
ExcludeFocus(
|
||||
excluding: _tab != 2,
|
||||
child: TickerMode(
|
||||
enabled: _tab == 2,
|
||||
child: SingleChildScrollView(
|
||||
primary: false,
|
||||
padding: _settingsContentPadding,
|
||||
child: McpSettingsPanel(workspace: widget.workspace),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _SettingsNavigation extends StatelessWidget {
|
||||
const _SettingsNavigation({
|
||||
required this.value,
|
||||
required this.compact,
|
||||
required this.onChanged,
|
||||
});
|
||||
|
||||
final int value;
|
||||
final bool compact;
|
||||
final ValueChanged<int> onChanged;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final theme = Theme.of(context);
|
||||
final entries = [
|
||||
(context.l10n.general, Icons.settings_outlined),
|
||||
(context.l10n.agentSettings, Icons.auto_awesome_outlined),
|
||||
('MCP', Icons.terminal_outlined),
|
||||
];
|
||||
return ColoredBox(
|
||||
key: const Key('settings-sidebar'),
|
||||
color: AppTheme.settingsSidebarBackground(context),
|
||||
child: ListView(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 16),
|
||||
children: [
|
||||
Padding(
|
||||
padding: const EdgeInsets.fromLTRB(8, 0, 8, 20),
|
||||
child: Text(
|
||||
context.l10n.settings,
|
||||
style: theme.textTheme.titleSmall?.copyWith(fontSize: 16),
|
||||
),
|
||||
),
|
||||
for (var index = 0; index < entries.length; index++)
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(bottom: 1),
|
||||
child: Semantics(
|
||||
selected: value == index,
|
||||
child: Tooltip(
|
||||
message: entries[index].$1,
|
||||
child: TextButton(
|
||||
key: ValueKey('settings-navigation-$index'),
|
||||
onPressed: () => onChanged(index),
|
||||
style: TextButton.styleFrom(
|
||||
minimumSize: const Size(0, 30),
|
||||
padding: const EdgeInsets.symmetric(horizontal: 8),
|
||||
foregroundColor: theme.colorScheme.onSurface,
|
||||
backgroundColor: value == index
|
||||
? theme.colorScheme.onSurface.withValues(alpha: .078)
|
||||
: Colors.transparent,
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
),
|
||||
alignment: AlignmentDirectional.centerStart,
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
if (!compact) ...[
|
||||
Icon(entries[index].$2, size: 16),
|
||||
const SizedBox(width: 8),
|
||||
],
|
||||
Expanded(
|
||||
child: Text(
|
||||
entries[index].$1,
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _ResourceLocationField extends ConsumerWidget {
|
||||
const _ResourceLocationField();
|
||||
|
||||
Future<void> _choose(
|
||||
BuildContext context,
|
||||
WidgetRef ref,
|
||||
String? initialDirectory,
|
||||
) async {
|
||||
final directory = await ref
|
||||
.read(filePickerProvider)
|
||||
.pickDirectory(
|
||||
initialDirectory: initialDirectory,
|
||||
confirmButtonText: context.l10n.select,
|
||||
);
|
||||
if (directory == null || !context.mounted) return;
|
||||
await ref.read(resourceLocationSettingsProvider.notifier).save(directory);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
final settings = ref.watch(resourceLocationSettingsProvider);
|
||||
final error = switch (settings.error) {
|
||||
LocationSettingsError.load => context.l10n.loadResourceLocationFailed,
|
||||
LocationSettingsError.save => context.l10n.saveResourceLocationFailed,
|
||||
null => null,
|
||||
};
|
||||
return AppField(
|
||||
label: context.l10n.resourceLocation,
|
||||
orientation: AppFieldOrientation.horizontal,
|
||||
error: error,
|
||||
child: SizedBox(
|
||||
width: 420,
|
||||
child: Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: Tooltip(
|
||||
message:
|
||||
settings.directory ?? context.l10n.resourceLocationNotSet,
|
||||
child: _MiddleEllipsisText(
|
||||
settings.directory ?? context.l10n.resourceLocationNotSet,
|
||||
key: const Key('resource-location-value'),
|
||||
textAlign: TextAlign.right,
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: AppSpacing.compact),
|
||||
OutlinedButton(
|
||||
key: const Key('choose-resource-location'),
|
||||
onPressed: settings.loading || settings.saving
|
||||
? null
|
||||
: () => _choose(context, ref, settings.directory),
|
||||
child: Text(context.l10n.modify),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _ProjectLocationField extends ConsumerWidget {
|
||||
const _ProjectLocationField();
|
||||
|
||||
Future<void> _choose(
|
||||
BuildContext context,
|
||||
WidgetRef ref,
|
||||
String? initialDirectory,
|
||||
) async {
|
||||
final directory = await ref
|
||||
.read(filePickerProvider)
|
||||
.pickDirectory(
|
||||
initialDirectory: initialDirectory,
|
||||
confirmButtonText: context.l10n.select,
|
||||
);
|
||||
if (directory == null || !context.mounted) return;
|
||||
await ref.read(projectLocationSettingsProvider.notifier).save(directory);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
final settings = ref.watch(projectLocationSettingsProvider);
|
||||
final error = switch (settings.error) {
|
||||
LocationSettingsError.load => context.l10n.loadProjectLocationFailed,
|
||||
LocationSettingsError.save => context.l10n.saveProjectLocationFailed,
|
||||
null => null,
|
||||
};
|
||||
return AppField(
|
||||
label: context.l10n.projectLocation,
|
||||
orientation: AppFieldOrientation.horizontal,
|
||||
description: settings.status == ProjectLocationStatus.missing
|
||||
? context.l10n.projectLocationMissing
|
||||
: null,
|
||||
error:
|
||||
error ??
|
||||
switch (settings.status) {
|
||||
ProjectLocationStatus.unavailable =>
|
||||
context.l10n.projectLocationUnavailable,
|
||||
ProjectLocationStatus.notWritable =>
|
||||
context.l10n.projectLocationNotWritable,
|
||||
_ => null,
|
||||
},
|
||||
child: SizedBox(
|
||||
width: 420,
|
||||
child: Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: Tooltip(
|
||||
message:
|
||||
settings.directory ?? context.l10n.projectLocationNotSet,
|
||||
child: _MiddleEllipsisText(
|
||||
settings.directory ?? context.l10n.projectLocationNotSet,
|
||||
key: const Key('project-location-value'),
|
||||
textAlign: TextAlign.right,
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: AppSpacing.compact),
|
||||
if (error != null ||
|
||||
settings.status == ProjectLocationStatus.unavailable ||
|
||||
settings.status == ProjectLocationStatus.notWritable)
|
||||
TextButton(
|
||||
key: const Key('retry-project-location'),
|
||||
onPressed: settings.loading || settings.saving
|
||||
? null
|
||||
: ref.read(projectLocationSettingsProvider.notifier).reload,
|
||||
child: Text(context.l10n.retry),
|
||||
),
|
||||
OutlinedButton(
|
||||
key: const Key('choose-project-location'),
|
||||
onPressed: settings.loading || settings.saving
|
||||
? null
|
||||
: () => _choose(context, ref, settings.directory),
|
||||
child: Text(context.l10n.modify),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _MiddleEllipsisText extends StatelessWidget {
|
||||
const _MiddleEllipsisText(
|
||||
this.text, {
|
||||
super.key,
|
||||
this.textAlign = TextAlign.start,
|
||||
});
|
||||
|
||||
final String text;
|
||||
final TextAlign textAlign;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final style = DefaultTextStyle.of(context).style;
|
||||
final direction = Directionality.of(context);
|
||||
return LayoutBuilder(
|
||||
builder: (context, constraints) => Text(
|
||||
_ellipsize(text, constraints.maxWidth, style, direction),
|
||||
maxLines: 1,
|
||||
textAlign: textAlign,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
static String _ellipsize(
|
||||
String value,
|
||||
double maxWidth,
|
||||
TextStyle style,
|
||||
TextDirection direction,
|
||||
) {
|
||||
bool fits(String candidate) {
|
||||
final painter = TextPainter(
|
||||
text: TextSpan(text: candidate, style: style),
|
||||
maxLines: 1,
|
||||
textDirection: direction,
|
||||
)..layout(maxWidth: maxWidth);
|
||||
return !painter.didExceedMaxLines && painter.width <= maxWidth;
|
||||
}
|
||||
|
||||
if (!maxWidth.isFinite || fits(value)) return value;
|
||||
var low = 0;
|
||||
var high = value.length;
|
||||
while (low < high) {
|
||||
final keep = (low + high + 1) ~/ 2;
|
||||
final leading = (keep + 1) ~/ 2;
|
||||
final candidate =
|
||||
'${value.substring(0, leading)}…'
|
||||
'${value.substring(value.length - (keep - leading))}';
|
||||
if (fits(candidate)) {
|
||||
low = keep;
|
||||
} else {
|
||||
high = keep - 1;
|
||||
}
|
||||
}
|
||||
final leading = (low + 1) ~/ 2;
|
||||
return '${value.substring(0, leading)}…'
|
||||
'${value.substring(value.length - (low - leading))}';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'package:cutdex_ui/theme.dart';
|
||||
|
||||
class SettingsPageSection extends StatelessWidget {
|
||||
const SettingsPageSection({
|
||||
super.key,
|
||||
required this.title,
|
||||
required this.icon,
|
||||
required this.children,
|
||||
this.action,
|
||||
});
|
||||
|
||||
final String title;
|
||||
final IconData icon;
|
||||
final List<Widget> children;
|
||||
final Widget? action;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final theme = Theme.of(context);
|
||||
return Align(
|
||||
alignment: Alignment.topCenter,
|
||||
child: ConstrainedBox(
|
||||
constraints: const BoxConstraints(
|
||||
maxWidth: AppSettingsMetrics.contentWidth,
|
||||
),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
Text(title, style: theme.textTheme.titleLarge),
|
||||
const SizedBox(height: 40),
|
||||
Row(
|
||||
children: [
|
||||
Expanded(child: Text(title, style: theme.textTheme.labelLarge)),
|
||||
?action,
|
||||
],
|
||||
),
|
||||
const SizedBox(height: AppSpacing.medium),
|
||||
DecoratedBox(
|
||||
decoration: BoxDecoration(
|
||||
color: theme.colorScheme.surfaceContainer,
|
||||
borderRadius: BorderRadius.circular(
|
||||
AppSettingsMetrics.cardRadius,
|
||||
),
|
||||
border: Border.all(color: theme.colorScheme.outlineVariant),
|
||||
),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: AppSpacing.medium,
|
||||
),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
for (var index = 0; index < children.length; index++) ...[
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
vertical: AppSettingsMetrics.rowVerticalPadding,
|
||||
),
|
||||
child: children[index],
|
||||
),
|
||||
if (index < children.length - 1) const Divider(height: 1),
|
||||
],
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
import 'package:riverpod_annotation/riverpod_annotation.dart';
|
||||
|
||||
import '../../integrations/app_updates.dart';
|
||||
import '../../integrations/app_update_coordinator.dart';
|
||||
import '../../settings/settings_operation.dart';
|
||||
|
||||
part 'update_controller.g.dart';
|
||||
|
||||
@riverpod
|
||||
class UpdateController extends _$UpdateController {
|
||||
int _eventRevision = 0;
|
||||
UpdateStatus? _latestEvent;
|
||||
|
||||
@override
|
||||
Future<UpdateStatus> build() {
|
||||
ref.watch(appUpdateLifecycleProvider);
|
||||
final subscription = ref.watch(appUpdateBridgeProvider).events.listen((
|
||||
status,
|
||||
) {
|
||||
_eventRevision++;
|
||||
_latestEvent = status;
|
||||
if (ref.mounted) state = AsyncData(_latestEvent!);
|
||||
});
|
||||
ref.onDispose(subscription.cancel);
|
||||
return _load();
|
||||
}
|
||||
|
||||
Future<UpdateStatus> _load() async {
|
||||
final revision = _eventRevision;
|
||||
try {
|
||||
final status = await ref.read(appUpdateBridgeProvider).status();
|
||||
return revision != _eventRevision && _latestEvent != null
|
||||
? _latestEvent!
|
||||
: status;
|
||||
} catch (_) {
|
||||
return const UpdateStatus();
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> check() => _invoke((bridge) => bridge.check());
|
||||
Future<void> download() => _invoke((bridge) => bridge.download());
|
||||
Future<void> install() async {
|
||||
final link = ref.keepAlive();
|
||||
try {
|
||||
await ref.read(settingsOperationProvider('updates').notifier).run(
|
||||
() async {
|
||||
await installWindowsUpdate(ref);
|
||||
},
|
||||
);
|
||||
} finally {
|
||||
link.close();
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> setAutomaticChecks(bool value) =>
|
||||
_invoke((bridge) => bridge.setAutomaticChecks(value));
|
||||
|
||||
Future<void> _invoke(Future<void> Function(AppUpdateBridge) action) async {
|
||||
await ref.read(settingsOperationProvider('updates').notifier).run(() async {
|
||||
await action(ref.read(appUpdateBridgeProvider));
|
||||
final next = await _load();
|
||||
if (ref.mounted) state = AsyncData(next);
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
part of 'update_controller.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// RiverpodGenerator
|
||||
// **************************************************************************
|
||||
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
// ignore_for_file: type=lint, type=warning
|
||||
|
||||
@ProviderFor(UpdateController)
|
||||
final updateControllerProvider = UpdateControllerProvider._();
|
||||
|
||||
final class UpdateControllerProvider
|
||||
extends $AsyncNotifierProvider<UpdateController, UpdateStatus> {
|
||||
UpdateControllerProvider._()
|
||||
: super(
|
||||
from: null,
|
||||
argument: null,
|
||||
retry: null,
|
||||
name: r'updateControllerProvider',
|
||||
isAutoDispose: true,
|
||||
dependencies: null,
|
||||
$allTransitiveDependencies: null,
|
||||
);
|
||||
|
||||
@override
|
||||
String debugGetCreateSourceHash() => _$updateControllerHash();
|
||||
|
||||
@$internal
|
||||
@override
|
||||
UpdateController create() => UpdateController();
|
||||
}
|
||||
|
||||
String _$updateControllerHash() => r'896a08b90b032eee312d0c759e3323352ca441db';
|
||||
|
||||
abstract class _$UpdateController extends $AsyncNotifier<UpdateStatus> {
|
||||
FutureOr<UpdateStatus> build();
|
||||
@$mustCallSuper
|
||||
@override
|
||||
WhenComplete runBuild() {
|
||||
final ref = this.ref as $Ref<AsyncValue<UpdateStatus>, UpdateStatus>;
|
||||
final element =
|
||||
ref.element
|
||||
as $ClassProviderElement<
|
||||
AnyNotifier<AsyncValue<UpdateStatus>, UpdateStatus>,
|
||||
AsyncValue<UpdateStatus>,
|
||||
Object?,
|
||||
Object?
|
||||
>;
|
||||
return element.handleCreate(ref, build);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,108 @@
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
|
||||
import '../../settings/settings_operation.dart';
|
||||
import '../../integrations/app_updates.dart';
|
||||
import 'update_controller.dart';
|
||||
import '../../l10n/l10n.dart';
|
||||
|
||||
import 'package:cutdex_ui/widgets.dart';
|
||||
|
||||
class UpdateSettings extends ConsumerWidget {
|
||||
const UpdateSettings({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
if (!supportsAppUpdates) {
|
||||
return const SizedBox.shrink();
|
||||
}
|
||||
final status = ref.watch(updateControllerProvider).value;
|
||||
final operation = ref.watch(settingsOperationProvider('updates'));
|
||||
final controller = ref.read(updateControllerProvider.notifier);
|
||||
final configured = status?.configured == true;
|
||||
final version = status?.version ?? '';
|
||||
final build = status?.build ?? '';
|
||||
final windows = defaultTargetPlatform == TargetPlatform.windows;
|
||||
final busy =
|
||||
operation.isLoading ||
|
||||
const [
|
||||
UpdatePhase.checking,
|
||||
UpdatePhase.downloading,
|
||||
UpdatePhase.installing,
|
||||
].contains(status?.phase);
|
||||
return AppField(
|
||||
label: context.l10n.softwareUpdates,
|
||||
orientation: AppFieldOrientation.horizontal,
|
||||
error: operation.hasError || status?.error.isNotEmpty == true
|
||||
? (windows
|
||||
? context.l10n.updateOperationFailed
|
||||
: context.l10n.updateCheckFailed)
|
||||
: null,
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.end,
|
||||
children: [
|
||||
Wrap(
|
||||
alignment: WrapAlignment.end,
|
||||
crossAxisAlignment: WrapCrossAlignment.center,
|
||||
spacing: 12,
|
||||
children: [
|
||||
if (version.isNotEmpty) Text('$version ($build)'),
|
||||
OutlinedButton(
|
||||
key: const Key('check-for-updates'),
|
||||
onPressed:
|
||||
configured &&
|
||||
!busy &&
|
||||
(!windows || status?.canCheck == true)
|
||||
? controller.check
|
||||
: null,
|
||||
child: Text(context.l10n.checkForUpdates),
|
||||
),
|
||||
],
|
||||
),
|
||||
if (windows && status?.phase == UpdatePhase.checking)
|
||||
Text(context.l10n.checkingForUpdates),
|
||||
if (windows && status?.phase == UpdatePhase.current)
|
||||
Text(context.l10n.appIsUpToDate),
|
||||
if (windows && status?.phase == UpdatePhase.downloading) ...[
|
||||
Text(context.l10n.downloadingUpdate(status!.progress)),
|
||||
SizedBox(
|
||||
width: 200,
|
||||
child: LinearProgressIndicator(value: status.progress / 100),
|
||||
),
|
||||
],
|
||||
if (windows && status?.availableVersion.isNotEmpty == true) ...[
|
||||
Text(context.l10n.updateAvailable(status!.availableVersion)),
|
||||
if (status.phase == UpdatePhase.available)
|
||||
OutlinedButton(
|
||||
key: const Key('download-update'),
|
||||
onPressed: busy ? null : controller.download,
|
||||
child: Text(context.l10n.downloadUpdate),
|
||||
),
|
||||
if (status.phase == UpdatePhase.ready)
|
||||
OutlinedButton(
|
||||
key: const Key('install-update'),
|
||||
onPressed: busy ? null : controller.install,
|
||||
child: Text(context.l10n.restartToUpdate),
|
||||
),
|
||||
],
|
||||
if (configured)
|
||||
Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Flexible(child: Text(context.l10n.automaticallyCheckUpdates)),
|
||||
AppSwitch(
|
||||
semanticLabel: context.l10n.automaticallyCheckUpdates,
|
||||
value: status!.automaticChecks,
|
||||
onChanged: busy ? null : controller.setAutomaticChecks,
|
||||
),
|
||||
],
|
||||
)
|
||||
else if (status != null)
|
||||
Text(context.l10n.updatesUnavailable),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user