diff --git a/lib/data/res/openai.dart b/lib/data/res/openai.dart index e996d9d..2970b80 100644 --- a/lib/data/res/openai.dart +++ b/lib/data/res/openai.dart @@ -157,7 +157,7 @@ abstract final class Cfg { Cfg.setTo(cfg: Cfg.current.copyWith(model: model)); } - static void switchToDefault(BuildContext context) { + static void switchToDefault() { final cfg = _store.fetch(ChatConfig.defaultId); if (cfg != null) return setTo(cfg: cfg); diff --git a/lib/main.dart b/lib/main.dart index 557be3f..ccdc60c 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -39,6 +39,7 @@ void _runInZone(void Function() body) { Future _initApp() async { WidgetsFlutterBinding.ensureInitialized(); + ProxyHttpOverrides.useSystemProxy(); await Paths.init(BuildData.name); await _initDb(); diff --git a/lib/view/page/home/url_scheme.dart b/lib/view/page/home/url_scheme.dart index 810c123..c60c4f2 100644 --- a/lib/view/page/home/url_scheme.dart +++ b/lib/view/page/home/url_scheme.dart @@ -118,8 +118,7 @@ extension _AppLink on AppLink { if (paramsStr == null) return false; final cfg = ChatConfig.fromUrlParams(paramsStr); - cfg.save(); - Cfg.setTo(id: cfg.id); + Cfg.setTo(cfg: cfg); return true; default: diff --git a/lib/view/page/settings/profile.dart b/lib/view/page/settings/profile.dart index b9748de..b58dc9a 100644 --- a/lib/view/page/settings/profile.dart +++ b/lib/view/page/settings/profile.dart @@ -75,113 +75,110 @@ final class _ProfilePageState extends State } Widget _buildSwitchCfg(ChatConfig cfg) { - return ListTile( + final profiles = Stores.config.fetchAll().values.toList(); + return ExpandTile( leading: const Icon(Icons.switch_account), title: Text(l10n.profile), subtitle: Text(cfg.displayName, style: UIs.textGrey), - trailing: Row( - mainAxisSize: MainAxisSize.min, - children: [ - // Delete - if (cfg.id != ChatConfig.defaultId) - Btn.icon( - icon: const Icon(Icons.delete, size: 19), - onTap: () { - if (cfg.id == ChatConfig.defaultId) return; - context.showRoundDialog( - title: l10n.attention, - child: Text(l10n.delFmt(cfg.name, l10n.profile)), - actions: Btn.ok( - onTap: () { - Stores.config.delete(cfg.id); - context.pop(); - if (cfg.id == cfg.id) { - Cfg.switchToDefault(context); - } - }, - red: true, - ).toList, - ); - }, - ), - // Rename + initiallyExpanded: true, + trailing: _buildSwitchCfgActions(cfg), + children: [ + ChoiceWidget( + items: profiles, + selected: [cfg], + display: (p0) => p0.displayName, + onChanged: (vals) { + final select = vals.firstOrNull; + if (select == null) return; + Cfg.setTo(cfg: select); + }, + ).paddingOnly(bottom: 7, left: 7, right: 7), + ], + ); + } + + Widget _buildSwitchCfgActions(ChatConfig cfg) { + return Row( + mainAxisSize: MainAxisSize.min, + children: [ + // Delete + if (cfg.id != ChatConfig.defaultId) Btn.icon( - icon: const Icon(Icons.edit, size: 19), + icon: const Icon(Icons.delete, size: 19), onTap: () { - final ctrl = TextEditingController(text: cfg.name); + if (cfg.id == ChatConfig.defaultId) return; context.showRoundDialog( - title: libL10n.edit, - child: Input( - controller: ctrl, - label: libL10n.name, - autoFocus: true, - ), + title: l10n.attention, + child: Text(l10n.delFmt(cfg.name, l10n.profile)), actions: Btn.ok( onTap: () { - final name = ctrl.text; - if (name.isEmpty) return; - final newCfg = cfg.copyWith(name: name); - newCfg.save(); - Cfg.setTo(cfg: newCfg); + Stores.config.delete(cfg.id); context.pop(); + if (cfg.id == Cfg.current.id) { + Cfg.switchToDefault(); + } }, + red: true, ).toList, ); }, ), - // Switch - Btn.icon( - icon: const Icon(OctIcons.arrow_switch, size: 19), - onTap: () async { - final map = await Stores.config - .getAllMapTyped(includeInternalKeys: false); - final vals = map.values.toList(); - final newCfg = await context.showPickSingleDialog( - items: vals, - initial: cfg, - title: l10n.profile, - display: (p0) => p0.displayName, - ); - - if (newCfg == null) return; - Cfg.setTo(cfg: newCfg); - }, - ), - Btn.icon( - icon: const Icon(Icons.add, size: 19), - onTap: () async { - final ctrl = TextEditingController(); - final ok = await context.showRoundDialog( - title: libL10n.add, - child: Input( - controller: ctrl, - label: libL10n.name, - autoFocus: true, - ), - actions: Btnx.oks, - ); - if (ok != true) return; - final clipboardData = await Pfs.paste(); - var (key, url) = ('', ChatConfig.defaultUrl); - if (clipboardData != null) { - if (clipboardData.startsWith('https://')) { - url = clipboardData; - } else if (clipboardData.startsWith('sk-')) { - key = clipboardData; - } + // Rename + Btn.icon( + icon: const Icon(Icons.edit, size: 19), + onTap: () { + final ctrl = TextEditingController(text: cfg.name); + context.showRoundDialog( + title: libL10n.edit, + child: Input( + controller: ctrl, + label: libL10n.name, + autoFocus: true, + ), + actions: Btn.ok( + onTap: () { + final name = ctrl.text; + if (name.isEmpty) return; + Cfg.setTo(cfg: cfg.copyWith(name: name)); + context.pop(); + }, + ).toList, + ); + }, + ), + Btn.icon( + icon: const Icon(Icons.add, size: 19), + onTap: () async { + final ctrl = TextEditingController(); + final ok = await context.showRoundDialog( + title: libL10n.add, + child: Input( + controller: ctrl, + label: libL10n.name, + autoFocus: true, + ), + actions: Btnx.oks, + ); + if (ok != true) return; + final clipboardData = await Pfs.paste(); + var (key, url) = ('', ChatConfig.defaultUrl); + if (clipboardData != null) { + if (clipboardData.startsWith('https://')) { + url = clipboardData; + } else if (clipboardData.startsWith('sk-')) { + key = clipboardData; } - final newCfg = Cfg.current.copyWith( - id: shortid.generate(), - name: ctrl.text, - key: key, - url: url, - ); - newCfg.save(); - Cfg.setTo(cfg: newCfg); - }, - ), - ], - ), + } + final newCfg = Cfg.current.copyWith( + id: shortid.generate(), + name: ctrl.text, + key: key, + url: url, + ); + Cfg.setTo(cfg: newCfg); + }, + ), + ], ); } diff --git a/macos/Podfile.lock b/macos/Podfile.lock index 69fd635..66edcf8 100644 --- a/macos/Podfile.lock +++ b/macos/Podfile.lock @@ -78,7 +78,7 @@ EXTERNAL SOURCES: :path: Flutter/ephemeral/.symlinks/plugins/window_manager/macos SPEC CHECKSUMS: - app_links: 9028728e32c83a0831d9db8cf91c526d16cc5468 + app_links: afe860c55c7ef176cea7fb630a2b7d7736de591d file_picker: 7584aae6fa07a041af2b36a2655122d42f578c1a file_selector_macos: 6280b52b459ae6c590af5d78fc35c7267a3c4b31 flutter_inappwebview_macos: c2d68649f9f8f1831bfcd98d73fd6256366d9d1d diff --git a/pubspec.lock b/pubspec.lock index 174c86b..cfb05c4 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -492,8 +492,8 @@ packages: dependency: "direct main" description: path: "." - ref: "v1.0.244" - resolved-ref: "5104bf4a32003ef76877555f58a2986c0646ead3" + ref: "v1.0.251" + resolved-ref: "5774f9e56e6255293a40dc750692dc600056a288" url: "https://github.com/lppcg/fl_lib" source: git version: "0.0.1" @@ -660,6 +660,14 @@ packages: url: "https://pub.dev" source: hosted version: "2.0.27" + flutter_riverpod: + dependency: transitive + description: + name: flutter_riverpod + sha256: "9532ee6db4a943a1ed8383072a2e3eeda041db5657cdf6d2acecf3c21ecbe7e1" + url: "https://pub.dev" + source: hosted + version: "2.6.1" flutter_svg: dependency: transitive description: @@ -1326,6 +1334,22 @@ packages: url: "https://pub.dev" source: hosted version: "4.1.0" + riverpod: + dependency: transitive + description: + name: riverpod + sha256: "59062512288d3056b2321804332a13ffdd1bf16df70dcc8e506e411280a72959" + url: "https://pub.dev" + source: hosted + version: "2.6.1" + riverpod_annotation: + dependency: transitive + description: + name: riverpod_annotation + sha256: e14b0bf45b71326654e2705d462f21b958f987087be850afd60578fcd502d1b8 + url: "https://pub.dev" + source: hosted + version: "2.6.1" screen_retriever: dependency: transitive description: @@ -1523,6 +1547,14 @@ packages: url: "https://pub.dev" source: hosted version: "1.12.1" + state_notifier: + dependency: transitive + description: + name: state_notifier + sha256: b8677376aa54f2d7c58280d5a007f9e8774f1968d1fb1c096adcb4792fba29bb + url: "https://pub.dev" + source: hosted + version: "1.0.0" stream_channel: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index 40f808b..2989bde 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -42,7 +42,7 @@ dependencies: fl_lib: git: url: https://github.com/lppcg/fl_lib - ref: v1.0.244 + ref: v1.0.251 # dependency_overrides: # fl_lib: