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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions lib/l10n/app_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -4782,6 +4782,10 @@
}
}
},
"modelsMoveToTop": "Move to Top",
"modelsMoveUp": "Move Up",
"modelsMoveDown": "Move Down",
"modelsDragToReorder": "Drag to reorder",
"modelsFeaturedWhy": "Why am I seeing this?",
"modelsFeaturedNote": "These sites are officially listed by BaoCode",
"modelsFeaturedNoteHow": "Add the one-click import to be listed too, for free",
Expand Down
24 changes: 24 additions & 0 deletions lib/l10n/app_localizations.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10767,6 +10767,30 @@ abstract class AppLocalizations {
/// **'Offer {name} in the model picker'**
String modelsEnableProvider(String name);

/// No description provided for @modelsMoveToTop.
///
/// In en, this message translates to:
/// **'Move to Top'**
String get modelsMoveToTop;

/// No description provided for @modelsMoveUp.
///
/// In en, this message translates to:
/// **'Move Up'**
String get modelsMoveUp;

/// No description provided for @modelsMoveDown.
///
/// In en, this message translates to:
/// **'Move Down'**
String get modelsMoveDown;

/// No description provided for @modelsDragToReorder.
///
/// In en, this message translates to:
/// **'Drag to reorder'**
String get modelsDragToReorder;

/// No description provided for @modelsFeaturedWhy.
///
/// In en, this message translates to:
Expand Down
12 changes: 12 additions & 0 deletions lib/l10n/app_localizations_en.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6672,6 +6672,18 @@ class AppLocalizationsEn extends AppLocalizations {
return 'Offer $name in the model picker';
}

@override
String get modelsMoveToTop => 'Move to Top';

@override
String get modelsMoveUp => 'Move Up';

@override
String get modelsMoveDown => 'Move Down';

@override
String get modelsDragToReorder => 'Drag to reorder';

@override
String get modelsFeaturedWhy => 'Why am I seeing this?';

Expand Down
12 changes: 12 additions & 0 deletions lib/l10n/app_localizations_zh.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6270,6 +6270,18 @@ class AppLocalizationsZh extends AppLocalizations {
return '在模型选择中显示 $name';
}

@override
String get modelsMoveToTop => '置顶';

@override
String get modelsMoveUp => '上移';

@override
String get modelsMoveDown => '下移';

@override
String get modelsDragToReorder => '拖动排序';

@override
String get modelsFeaturedWhy => '为什么我看到这个?';

Expand Down
4 changes: 4 additions & 0 deletions lib/l10n/app_zh.arb
Original file line number Diff line number Diff line change
Expand Up @@ -1777,6 +1777,10 @@
"modelsBuiltinDescription": "使用本机的登录和配置,不做任何改动",
"modelsProviders": "上游",
"modelsEnableProvider": "在模型选择中显示 {name}",
"modelsMoveToTop": "置顶",
"modelsMoveUp": "上移",
"modelsMoveDown": "下移",
"modelsDragToReorder": "拖动排序",
"modelsFeaturedWhy": "为什么我看到这个?",
"modelsFeaturedNote": "这些站点目前已经被官方收录",
"modelsFeaturedNoteHow": "接入一键导入,即可免费参与收录",
Expand Down
43 changes: 42 additions & 1 deletion lib/models/model_providers.dart
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ class ModelProviders extends ChangeNotifier {
static ModelProviders current = ModelProviders.memory();

static const providersKey = 'models.providers';
static const providersOrderedKey = 'models.providers.ordered';
static const builtinHiddenKey = 'models.builtin.hidden';
static const defaultKey = 'models.default';
static const auxiliaryKey = 'models.auxiliary';
Expand All @@ -79,13 +80,14 @@ class ModelProviders extends ChangeNotifier {
SecretStore get secrets => _secrets ?? SecretStore.instance;

List<ModelProvider>? _cache;
bool? _orderedOverride;

void _changed() {
_cache = null;
notifyListeners();
}

/// All of them, in the order they were added.
/// All of them, in the order they were added (or kept by [reorder]).
List<ModelProvider> get providers => _cache ??= [
for (final json in switch (_read(providersKey)) {
final List list => list,
Expand All @@ -94,6 +96,11 @@ class ModelProviders extends ChangeNotifier {
?ModelProvider.fromJson(json),
];

/// Whether the user has ordered [providers] themselves: Settings → Models
/// then keeps this order instead of leading with magpie or a featured site.
bool get providersOrdered =>
_orderedOverride ?? (_read(providersOrderedKey) == true);

/// Those offered in the picker.
List<ModelProvider> get enabled => [
for (final provider in providers)
Expand Down Expand Up @@ -270,6 +277,40 @@ class ModelProviders extends ChangeNotifier {
await _writeProviders(list);
}

/// Puts [providers] in [ids]'s order (any omitted stay after, in theirs),
/// and marks the list as ordered by the user ([providersOrdered]).
Future<void> reorder(List<String> ids) async {
final current = providers;
if (current.length < 2) return;
final byId = {for (final provider in current) provider.id: provider};
final seen = <String>{};
final ordered = [
for (final id in ids)
if (byId[id] case final provider? when seen.add(id)) provider,
for (final provider in current)
if (seen.add(provider.id)) provider,
];
final unchanged =
providersOrdered &&
ordered.length == current.length &&
Iterable<int>.generate(current.length)
.every((i) => ordered[i].id == current[i].id);
if (unchanged) return;
_cache = ordered;
_orderedOverride = true;
notifyListeners();
try {
await _write(providersKey, [
for (final provider in ordered) provider.toJson(),
]);
if (_read(providersOrderedKey) != true) {
await _write(providersOrderedKey, true);
}
} finally {
_orderedOverride = null;
}
}

/// Adds a copy of provider [id] named [name], its key with it; not its
/// accounts, signed in to anew, nor the app it follows: the copy is the
/// user's own. Its id; null without [id].
Expand Down
Loading