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
2 changes: 1 addition & 1 deletion lib/data/res/openai.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
1 change: 1 addition & 0 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ void _runInZone(void Function() body) {

Future<void> _initApp() async {
WidgetsFlutterBinding.ensureInitialized();
ProxyHttpOverrides.useSystemProxy();

await Paths.init(BuildData.name);
await _initDb();
Expand Down
3 changes: 1 addition & 2 deletions lib/view/page/home/url_scheme.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
181 changes: 89 additions & 92 deletions lib/view/page/settings/profile.dart
Original file line number Diff line number Diff line change
Expand Up @@ -75,113 +75,110 @@ final class _ProfilePageState extends State<ProfilePage>
}

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<ChatConfig>(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);
},
),
],
);
}

Expand Down
2 changes: 1 addition & 1 deletion macos/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
36 changes: 34 additions & 2 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down