Skip to content

Commit

Permalink
new: unilink on web
Browse files Browse the repository at this point in the history
  • Loading branch information
lollipopkit committed Mar 4, 2024
1 parent 7afb5d2 commit 87f9d3a
Show file tree
Hide file tree
Showing 17 changed files with 127 additions and 102 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ Please don't use it in production environment, and don't use it for important da
- Text / Image / Audio chat. (Web only support text)
- Share chat by picture.
- Render code block / latex formula.
- Uni-Link, eg: `lk-gptbox://chat/new?msg=hello` (except Linux / Web)
- Uni-Link, eg: `lk-gptbox://chat/new?msg=hello` (except Linux)
- All platforms support.
- Sync with WebDAV / iCloud.

Expand Down
2 changes: 1 addition & 1 deletion README_zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
-[ChatGPT Next Web](https://github.com/ChatGPTNextWeb/ChatGPT-Next-Web) 恢复
- 文本 / 图片 / 音频聊天(网页版仅支持文本)
- 以图片形式分享聊天
- Uni-Link,例如:`lk-gptbox://chat/new?msg=你好` (Linux / Web 除外)
- Uni-Link,例如:`lk-gptbox://chat/new?msg=你好` (Linux 除外)
- 与 WebDAV / iCloud 同步
- 全平台支持
- 渲染 代码块 / LaTeX 公式
Expand Down
6 changes: 2 additions & 4 deletions TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,8 @@
- [x] WebDAV
- [ ] Manually sync media files
- [x] URL Scheme
- [x] Config: `lk-gptbox://app/set?openAiUrl=&openAiKey=&openAiModel=&chatId=`
- If chatId is not provided, it will config global settings
- If chatId not exists, it will create a new chat
- [ ] On web, it's `https://gpt.lolli.tech/set?openAiUrl=&openAiKey=&openAiModel=&chatId=`
- [ ] On web, replace `lk-gptbox://app` to `https://gpt.lolli.tech`
- [x] Config: `lk-gptbox://app/set?openAiUrl=&openAiKey=&openAiModel=`
- [x] Chat
- [x] New: `lk-gptbox://app/new?msg=`
- [x] Open: `lk-gptbox://app/open?chatId=`
Expand Down
8 changes: 4 additions & 4 deletions ios/Podfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PODS:
- audioplayers_darwin (0.0.1):
- Flutter
- countly_flutter (23.12.1):
- countly_flutter (23.12.0):
- Flutter
- DKImagePickerController/Core (4.3.4):
- DKImagePickerController/ImageDataManager
Expand Down Expand Up @@ -109,21 +109,21 @@ EXTERNAL SOURCES:

SPEC CHECKSUMS:
audioplayers_darwin: 877d9a4d06331c5c374595e46e16453ac7eafa40
countly_flutter: 0b87be283b3ecef341b5f8d45ff97dd33ee966b9
countly_flutter: 72d4b7ed3921f0dfbf1c0ab8b356e3ecb91bdd74
DKImagePickerController: b512c28220a2b8ac7419f21c491fc8534b7601ac
DKPhotoGallery: fdfad5125a9fdda9cc57df834d49df790dbb4179
file_picker: 15fd9539e4eb735dc54bae8c0534a7a9511a03de
Flutter: e0871f40cf51350855a761d2e70bf5af5b9b5de7
flutter_native_splash: 52501b97d1c0a5f898d687f1646226c1f93c56ef
icloud_storage: d9ac7a33ced81df08ba7ea1bf3099cc0ee58f60a
image_picker_ios: 99dfe1854b4fa34d0364e74a78448a0151025425
path_provider_foundation: 3784922295ac71e43754bd15e0653ccfd36a147c
path_provider_foundation: 29f094ae23ebbca9d3d0cec13889cd9060c0e943
r_upgrade: 44d715c61914cce3d01ea225abffe894fd51c114
SDWebImage: 96e0c18ef14010b7485210e92fac888587ebb958
share_plus: c3fef564749587fc939ef86ffb283ceac0baf9f5
SwiftyGif: 93a1cc87bf3a51916001cf8f3d63835fb64c819f
uni_links: d97da20c7701486ba192624d99bffaaffcfc298a
url_launcher_ios: 6116280ddcfe98ab8820085d8d76ae7449447586
url_launcher_ios: bbd758c6e7f9fd7b5b1d4cde34d2b95fcce5e812

PODFILE CHECKSUM: 075ddf6b19cdcced44581bd8fbdfb58404a78f8a

Expand Down
6 changes: 3 additions & 3 deletions ios/Runner.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_ENTITLEMENTS = Runner/Runner.entitlements;
CURRENT_PROJECT_VERSION = 110;
CURRENT_PROJECT_VERSION = 111;
DEVELOPMENT_TEAM = BA88US33G6;
ENABLE_BITCODE = NO;
INFOPLIST_FILE = Runner/Info.plist;
Expand Down Expand Up @@ -494,7 +494,7 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_ENTITLEMENTS = Runner/Runner.entitlements;
CURRENT_PROJECT_VERSION = 110;
CURRENT_PROJECT_VERSION = 111;
DEVELOPMENT_TEAM = BA88US33G6;
ENABLE_BITCODE = NO;
INFOPLIST_FILE = Runner/Info.plist;
Expand All @@ -519,7 +519,7 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_ENTITLEMENTS = Runner/Runner.entitlements;
CURRENT_PROJECT_VERSION = 110;
CURRENT_PROJECT_VERSION = 111;
DEVELOPMENT_TEAM = BA88US33G6;
ENABLE_BITCODE = NO;
INFOPLIST_FILE = Runner/Info.plist;
Expand Down
6 changes: 3 additions & 3 deletions lib/data/res/build.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

class Build {
static const String name = "GPT";
static const int build = 110;
static const int build = 111;
static const String engine = "3.19.2";
static const String buildAt = "2024-03-02 21:21:10";
static const int modifications = 1;
static const String buildAt = "2024-03-04 11:05:52";
static const int modifications = 16;
}
25 changes: 25 additions & 0 deletions lib/data/res/github_id.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
abstract final class GithubId {
static const participants = {
'SeaHI-Robot',
'Http-200',
'bxoooooo',
};

static const contributors = {
'ParperCube',
};

static String get markdownStr {
final sb = StringBuffer();
sb.write('- Participants: ');
for (final p in participants) {
sb.write('[$p](https://github.com/$p) ');
}
sb.writeln();
sb.write('- Contributors: ');
for (final c in contributors) {
sb.write('[$c](https://github.com/$c) ');
}
return sb.toString();
}
}
2 changes: 1 addition & 1 deletion lib/l10n/app_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
"hoursAgo": "{hours} hours ago",
"ignoreTip": "Ignore tips",
"image": "Image",
"initChatHelp": "### 📖 Tip\n- Overscroll on the chat page to switch chat history.\n- Long press code block to copy\n- The left drawer settings are global settings, the settings above the input box below are settings for the current conversation\n- Swipe right to enter the left side of the history page, you can modify the title of the chat, delete the chat\n\n### 🔍 Help\n- If you have found a bug, please use [Github Issue](https://github.com/lollipopkit/flutter_gpt_box/issues)",
"initChatHelp": "### 📖 Tip\n- Overscroll on the chat page to switch chat history.\n- Long press code block to copy\n\n### 🔗 URL Scheme\n- [ ] On web, replace `lk-gptbox://app` to `https://gpt.lolli.tech`\n- [x] Config: `lk-gptbox://app/set?openAiUrl=&openAiKey=&openAiModel=`\n- [x] Chat\n - [x] New: `lk-gptbox://app/new?msg=`\n - [x] Open: `lk-gptbox://app/open?chatId=`\n - [x] Search: `lk-gptbox://app/search?keyword=`\n - [x] Share: `lk-gptbox://app/share?chatId=`\n\n### 🔍 Help\n- If you have found a bug, please use [Github Issue](https://github.com/lollipopkit/flutter_gpt_box/issues)",
"invalidLinkFmt": "Invalid link: {uri}",
"justNow": "Just now",
"lang": "Language",
Expand Down
2 changes: 1 addition & 1 deletion lib/l10n/app_zh.arb
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
"hoursAgo": "{hours} 小时前",
"ignoreTip": "忽略提示",
"image": "图片",
"initChatHelp": "### 📖 提示\n- 在聊天界面过度滑动(overscroll)可以快捷切换聊天历史记录\n- 长按代码块来复制\n- 左侧抽屉设置为全局设置,下方的输入框上方的设置为当前对话的设置\n- 向右滑动可以进入左侧的历史聊天记录页面,可以修改聊天标题、删除聊天\n\n### 🔍 帮助\n- 如果 GPT Box 有 bug,请使用 [Github Issue](https://github.com/lollipopkit/flutter_gpt_box/issues)\n- QQ群 762870488",
"initChatHelp": "### 📖 提示\n- 在聊天界面过度滑动(overscroll)可以快捷切换聊天历史记录\n- 长按代码块来复制\n\n### 🔗 链接\n- [ ] 在Web, 替换 `lk-gptbox://app` 为 `https://gpt.lolli.tech`\n- [x] 配置: `lk-gptbox://app/set?openAiUrl=&openAiKey=&openAiModel=`\n- [x] 聊天\n - [x] 新建: `lk-gptbox://app/new?msg=`\n - [x] 打开: `lk-gptbox://app/open?chatId=`\n - [x] 搜索: `lk-gptbox://app/search?keyword=`\n - [x] 分享: `lk-gptbox://app/share?chatId=`\n\n### 🔍 帮助\n- 如果 GPT Box 有 bug,请使用 [Github Issue](https://github.com/lollipopkit/flutter_gpt_box/issues)\n- QQ群 762870488",
"invalidLinkFmt": "未知链接:{uri}",
"justNow": "刚刚",
"lang": "语言",
Expand Down
5 changes: 3 additions & 2 deletions lib/view/page/about.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'package:flutter/material.dart';
import 'package:flutter_chatgpt/data/res/github_id.dart';
import 'package:flutter_chatgpt/data/res/l10n.dart';
import 'package:flutter_chatgpt/data/res/ui.dart';
import 'package:flutter_chatgpt/view/widget/appbar.dart';
Expand All @@ -18,8 +19,8 @@ class AboutPage extends StatelessWidget {
child: ListView(
padding: const EdgeInsets.symmetric(horizontal: 17),
children: [
_buildInfo(),
_buildLicense(context),
_buildInfo(),
],
),
),
Expand All @@ -37,7 +38,7 @@ class AboutPage extends StatelessWidget {
### 🥳 ${l10n.contributor} & ${l10n.participant}
${GithubId.markdownStr}
### 🗂️ ${l10n.privacy}
Expand Down
102 changes: 49 additions & 53 deletions lib/view/page/home/bottom.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,63 +10,59 @@ class _HomeBottom extends StatelessWidget {
return ListenableBuilder(
listenable: _homeBottomRN,
builder: (_, __) {
return _buildView(context);
},
);
}

Widget _buildView(BuildContext context) {
final isDark = RNode.dark.value;
return Container(
padding: isDesktop
? const EdgeInsets.only(left: 11, right: 11, top: 7, bottom: 17)
: const EdgeInsets.symmetric(horizontal: 11, vertical: 5),
decoration: BoxDecoration(
borderRadius: const BorderRadius.vertical(top: Radius.circular(17)),
color: UIs.bgColor.fromBool(isDark),
boxShadow: isDark ? _boxShadowDark : _boxShadow,
),
child: AnimatedPadding(
padding: EdgeInsets.only(bottom: _media?.viewInsets.bottom ?? 0),
curve: Curves.fastEaseInToSlowEaseOut,
duration: Durations.short1,
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Row(
final isDark = RNode.dark.value;
return Container(
padding: isDesktop
? const EdgeInsets.only(left: 11, right: 11, top: 7, bottom: 17)
: const EdgeInsets.symmetric(horizontal: 11, vertical: 5),
decoration: BoxDecoration(
borderRadius: const BorderRadius.vertical(top: Radius.circular(17)),
color: UIs.bgColor.fromBool(isDark),
boxShadow: isDark ? _boxShadowDark : _boxShadow,
),
child: AnimatedPadding(
padding: EdgeInsets.only(bottom: _media?.viewInsets.bottom ?? 0),
curve: Curves.fastEaseInToSlowEaseOut,
duration: Durations.short1,
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
// IconButton(
// onPressed: () => _onTapSetting(context),
// icon: const Icon(Icons.settings, size: 19),
// tooltip: l10n.settings,
// ),
IconButton(
onPressed: () {
_switchChat(_newChat().id);
_historyRN.build();
},
icon: const Icon(Icons.add),
tooltip: l10n.newChat,
),
IconButton(
onPressed: () => _onTapRenameChat(_curChatId, context),
icon: const Icon(Icons.abc, size: 19),
tooltip: l10n.rename,
),
IconButton(
onPressed: () => _onTapDeleteChat(_curChatId, context),
icon: const Icon(Icons.delete, size: 19),
tooltip: l10n.delete,
Row(
children: [
// IconButton(
// onPressed: () => _onTapSetting(context),
// icon: const Icon(Icons.settings, size: 19),
// tooltip: l10n.settings,
// ),
IconButton(
onPressed: () {
_switchChat(_newChat().id);
_historyRN.build();
},
icon: const Icon(Icons.add),
tooltip: l10n.newChat,
),
IconButton(
onPressed: () => _onTapRenameChat(_curChatId, context),
icon: const Icon(Icons.abc, size: 19),
tooltip: l10n.rename,
),
IconButton(
onPressed: () => _onTapDeleteChat(_curChatId, context),
icon: const Icon(Icons.delete, size: 19),
tooltip: l10n.delete,
),
const Spacer(),
_buildSwitchChatType(),
],
),
const Spacer(),
_buildSwitchChatType(),
_buildTextField(context),
SizedBox(height: _media?.padding.bottom),
],
),
_buildTextField(context),
SizedBox(height: _media?.padding.bottom),
],
),
),
),
);
},
);
}

Expand Down
20 changes: 14 additions & 6 deletions lib/view/page/home/ctrl.dart
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,8 @@ void _onStopStreamSub(String chatId) {
_sendBtnRN.build();
}

final _punctionsRm = RegExp('[。"\'“”]');

Future<void> _genChatTitle(
BuildContext context,
String chatId,
Expand Down Expand Up @@ -252,7 +254,13 @@ if it is English, French, German, Latin and other Western languages, the number
The title should be the same as the language entered by the user.''',
role: ChatRole.system,
).toOpenAI,
entity.items.first.toOpenAI,
ChatHistoryItem.single(
role: ChatRole.user,
raw: entity.items.first.content
.firstWhereOrNull((p0) => p0.type == ChatContentType.text)
?.raw ??
'',
).toOpenAI,
],
);
final title = resp.choices.firstOrNull?.message.content?.firstOrNull?.text;
Expand All @@ -264,8 +272,7 @@ The title should be the same as the language entered by the user.''',
}

/// These punctions which not affect the meaning of the title will be removed
const punctions2Rm = ['。', '"', "'", "“", '”'];
entity.name = title.replaceAll(RegExp('[${punctions2Rm.join()}]'), '');
entity.name = title.replaceAll(_punctionsRm, '');
_historyRNMap[chatId]?.build();
if (chatId == _curChatId) _appbarTitleRN.build();
}
Expand Down Expand Up @@ -299,11 +306,12 @@ void _onShareChat(BuildContext context) async {
}

Future<void> _onTapImgPick(BuildContext context) async {
if (_filePicked.value != null) {
final val = _filePicked.value;
if (val != null) {
final delete = await context.showRoundDialog(
title: l10n.file,
child: Image.memory(
await _filePicked.value!.readAsBytes(),
await val.readAsBytes(),
fit: BoxFit.cover,
cacheHeight: 100,
cacheWidth: 100,
Expand All @@ -312,7 +320,7 @@ Future<void> _onTapImgPick(BuildContext context) async {
TextButton(
onPressed: () => context.pop(true),
child: Text(
l10n.delete,
l10n.clear,
style: UIs.textRed,
),
),
Expand Down
19 changes: 7 additions & 12 deletions lib/view/page/home/home.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import 'package:flutter_chatgpt/core/ext/context/base.dart';
import 'package:flutter_chatgpt/core/ext/context/dialog.dart';
import 'package:flutter_chatgpt/core/ext/context/snackbar.dart';
import 'package:flutter_chatgpt/core/ext/datetime.dart';
import 'package:flutter_chatgpt/core/ext/list.dart';
import 'package:flutter_chatgpt/core/ext/media_query.dart';
import 'package:flutter_chatgpt/core/ext/num.dart';
import 'package:flutter_chatgpt/core/ext/widget.dart';
Expand Down Expand Up @@ -142,13 +143,8 @@ class _HomePageState extends State<HomePage>
if (_isWide.value) {
return const Row(
children: [
SizedBox(
width: 300,
child: history,
),
Expanded(
child: chat,
),
SizedBox(width: 300, child: history),
Expanded(child: chat),
],
);
}
Expand Down Expand Up @@ -228,12 +224,11 @@ class _HomePageState extends State<HomePage>
}
}

void _initUniLinks() async {
Future<void> _initUniLinks() async {
if (isWeb) {
// getInitialUri().then((uri) {
// if (uri == null) return;
// AppLink.handle(context, uri);
// });
final uri = await getInitialUri();
if (uri == null) return;
AppLink.handle(context, uri);
} else {
uriLinkStream.listen((Uri? uri) {
if (uri == null) return;
Expand Down
1 change: 1 addition & 0 deletions lib/view/page/home/uni_link.dart
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ abstract final class AppLink {
);
return true;
default:
if (isWeb && path == '/') return true;
final msg = l10n.invalidLinkFmt(path);
context.showSnackBar(msg);
Loggers.app.warning(msg);
Expand Down
Loading

0 comments on commit 87f9d3a

Please sign in to comment.