Skip to content

Commit

Permalink
opt.: unilinks
Browse files Browse the repository at this point in the history
  • Loading branch information
lollipopkit committed Mar 4, 2024
1 parent 87f9d3a commit 5d6bebb
Show file tree
Hide file tree
Showing 8 changed files with 77 additions and 30 deletions.
7 changes: 0 additions & 7 deletions TODO.md → doc/TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,6 @@
- [x] WebDAV
- [ ] Manually sync media files
- [x] URL Scheme
- [ ] 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=`
- [x] Search: `lk-gptbox://app/search?keyword=`
- [x] Share: `lk-gptbox://app/share?chatId=`
- [ ] Plugin
- [ ] Engine (Webview?)
- [ ] Share Center
Expand Down
38 changes: 38 additions & 0 deletions doc/uni_link.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
- [URL Scheme](#url-scheme)
- [链接](#链接)

## URL Scheme
- [x] On web, replace `lk-gptbox://app` to `https://gpt.lolli.tech`
- [x] Page: `lk-gptbox://app/go?page=`
- Available `page`: `setting`, `backup`, `about`
- [x] Config: `lk-gptbox://app/set?openAiUrl=&openAiKey=&openAiModel=`
- [x] Chat
- [x] New: `lk-gptbox://app/new?msg=&send=`
- If `send` is `true`, send the message, or just open the chat and fill the message
- [x] Open: `lk-gptbox://app/open?chatId=&title=`
- If `chatId` and `title` is empty, open the chat history list
- If `chatId` is not empty, open the chat with id
- If `title` is not empty, open the chat with title
- [x] Search: `lk-gptbox://app/search?keyword=`
- [x] Share: `lk-gptbox://app/share?chatId=&title=`
- If `chatId` and `title` is empty, share the current chat
- If `chatId` is not empty, share the chat with id
- If `title` is not empty, share the chat with title

## 链接
- [x] 在网页上,将 `lk-gptbox://app` 替换为 `https://gpt.lolli.tech`
- [x] 页面: `lk-gptbox://app/go?page=`
- 可用 `page`(页面): `setting`, `backup`, `about`
- [x] 配置: `lk-gptbox://app/set?openAiUrl=&openAiKey=&openAiModel=`
- [x] 聊天
- [x] 新建: `lk-gptbox://app/new?msg=&send=`
- 如果 `send``true`,发送消息,否则只是打开聊天并填充消息
- [x] 打开: `lk-gptbox://app/open?chatId=&title=`
- 如果 `chatId``title` 为空,打开聊天历史列表
- 如果 `chatId` 不为空,打开 id 对应的聊天
- 如果 `title` 不为空,打开标题对应的聊天
- [x] 搜索: `lk-gptbox://app/search?keyword=`
- [x] 分享: `lk-gptbox://app/share?chatId=&title=`
- 如果 `chatId``title` 为空,分享当前聊天
- 如果 `chatId` 不为空,分享 id 对应的聊天
- 如果 `title` 不为空,分享标题对应的聊天
2 changes: 1 addition & 1 deletion lib/view/page/about.dart
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class AboutPage extends StatelessWidget {
child: MarkdownBody(
data: '''
### 👋🏻 ${l10n.myOtherApps}
- [Server Box](https://github.com/lollipopkit/flutter_server_box) - View status & control your server
- [Server Box](https://github.com/lollipopkit/flutter_server_box): View status & control your server
### 🥳 ${l10n.contributor} & ${l10n.participant}
Expand Down
6 changes: 1 addition & 5 deletions lib/view/page/home/bottom.dart
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,7 @@ class _HomeBottom extends StatelessWidget {
},
onTap: () {
if (_curPage.value != HomePageEnum.chat) {
_pageCtrl.animateToPage(
HomePageEnum.chat.index,
duration: Durations.medium1,
curve: Curves.fastEaseInToSlowEaseOut,
);
_switchPage(HomePageEnum.chat);
}
},
contextMenuBuilder: (context, editableTextState) {
Expand Down
8 changes: 8 additions & 0 deletions lib/view/page/home/ctrl.dart
Original file line number Diff line number Diff line change
Expand Up @@ -913,3 +913,11 @@ Future<void> _onLongTapSetting(BuildContext context) async {
// Loggers.app.warning('Update json settings failed', e, trace);
// }
}

void _switchPage(HomePageEnum page) {
_pageCtrl.animateToPage(
page.index,
duration: Durations.medium1,
curve: Curves.fastEaseInToSlowEaseOut,
);
}
6 changes: 1 addition & 5 deletions lib/view/page/home/history.dart
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,7 @@ class _HistoryPageState extends State<_HistoryPage>
() {
_switchChat(chatId);
if (!_isWide.value && _curPage.value != HomePageEnum.chat) {
_pageCtrl.animateToPage(
HomePageEnum.chat.index,
duration: Durations.medium3,
curve: Curves.fastEaseInToSlowEaseOut,
);
_switchPage(HomePageEnum.chat);
}
},
id: 'history_item',
Expand Down
6 changes: 1 addition & 5 deletions lib/view/page/home/search.dart
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,7 @@ class _ChatSearchDelegate extends SearchDelegate<ChatHistory> {
_gotoHistory(chat.id);
_switchChat(chat.id);
if (_curPage.value != HomePageEnum.chat) {
_pageCtrl.animateToPage(
HomePageEnum.chat.index,
duration: Durations.medium1,
curve: Curves.fastEaseInToSlowEaseOut,
);
_switchPage(HomePageEnum.chat);
}
},
).card;
Expand Down
34 changes: 27 additions & 7 deletions lib/view/page/home/uni_link.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,33 @@ abstract final class AppLink {
switch (path) {
case '/new':
final msg = params['msg'];
final send = params['send'];
final chat = _newChat();
_switchChat(chat.id);
if (msg != null) {
_inputCtrl.text = msg;
_onCreateChat(chat.id, context);
if (send == 'true') _onCreateChat(chat.id, context);
}
return true;
case '/open':
final chatId = params['chatId'];
final title = params['title'];
if (chatId != null) {
_switchChat(chatId);
return true;
}
final msg = l10n.invalidLinkFmt('${l10n.empty} chatId');
context.showSnackBar(msg);
Loggers.app.warning(msg);
if (title != null) {
final chat = _allHistories.values.toList().firstWhereOrNull(
(e) => e.name?.contains(title) == true,
);
if (chat != null) {
_switchChat(chat.id);
return true;
}
}
if (_curPage.value != HomePageEnum.history) {
_switchPage(HomePageEnum.history);
}
return true;
case '/search':
final query = params['keyword'];
Expand All @@ -41,6 +52,7 @@ abstract final class AppLink {
return true;
case '/share':
final chatId = params['chatId'];
final title = params['title'];
if (chatId != null) {
final chat = _allHistories[chatId];
if (chat != null) {
Expand All @@ -49,9 +61,17 @@ abstract final class AppLink {
return true;
}
}
final msg = l10n.invalidLinkFmt('${l10n.empty} chatId');
context.showSnackBar(msg);
Loggers.app.warning(msg);
if (title != null) {
final chat = _allHistories.values.toList().firstWhereOrNull(
(e) => e.name?.contains(title) == true,
);
if (chat != null) {
_switchChat(chat.id);
_onShareChat(context);
return true;
}
}
_onShareChat(context);
return true;
case '/go':
final page = params['page'];
Expand Down

0 comments on commit 5d6bebb

Please sign in to comment.