mirror of
https://github.com/HChaZZY/PiliPlus.git
synced 2025-12-06 09:13:48 +08:00
feat: open in browser
Closes #140 Signed-off-by: bggRGjQaUbCoE <githubaccount56556@proton.me>
This commit is contained in:
@@ -134,14 +134,7 @@ class VideoCardV extends StatelessWidget {
|
||||
break;
|
||||
default:
|
||||
SmartDialog.showToast(videoItem.goto);
|
||||
Get.toNamed(
|
||||
'/webview',
|
||||
parameters: {
|
||||
'url': videoItem.uri,
|
||||
'type': 'url',
|
||||
'pageTitle': videoItem.title,
|
||||
},
|
||||
);
|
||||
Utils.handleWebview(videoItem.uri);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -123,14 +123,7 @@ class VideoCardVMemberHome extends StatelessWidget {
|
||||
// break;
|
||||
default:
|
||||
SmartDialog.showToast(goto);
|
||||
Get.toNamed(
|
||||
'/webview',
|
||||
parameters: {
|
||||
'url': videoItem.uri ?? '',
|
||||
'type': 'url',
|
||||
'pageTitle': videoItem.title ?? '',
|
||||
},
|
||||
);
|
||||
Utils.handleWebview(videoItem.uri ?? '');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -138,14 +138,7 @@ class DynamicsController extends GetxController
|
||||
'dynamicType': url.split('//').last.split('/')[1]
|
||||
});
|
||||
} else {
|
||||
Utils.toDupNamed(
|
||||
'/webview',
|
||||
parameters: {
|
||||
'url': 'https:$url',
|
||||
'type': 'note',
|
||||
'pageTitle': title
|
||||
},
|
||||
);
|
||||
Utils.handleWebview('https:$url');
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
@@ -286,11 +286,7 @@ Widget forWard(item, context, ctr, source, callback, {floor = 1}) {
|
||||
final Map music = item.modules.moduleDynamic.major.music;
|
||||
return InkWell(
|
||||
onTap: () {
|
||||
Get.toNamed('/webview', parameters: {
|
||||
'url': "https:${music['jump_url']}",
|
||||
'type': 'url',
|
||||
'pageTitle': music['title']
|
||||
});
|
||||
Utils.handleWebview("https:${music['jump_url']}");
|
||||
},
|
||||
child: Container(
|
||||
width: double.infinity,
|
||||
|
||||
@@ -108,16 +108,9 @@ InlineSpan? richNode(item, context) {
|
||||
PiliScheme.routePush(Uri.parse(url));
|
||||
return;
|
||||
}
|
||||
Get.toNamed(
|
||||
'/webview',
|
||||
parameters: {
|
||||
'url': url.startsWith('//')
|
||||
? "https://${url.split('//').last}"
|
||||
: url,
|
||||
'type': 'url',
|
||||
'pageTitle': ''
|
||||
},
|
||||
);
|
||||
Utils.handleWebview(url.startsWith('//')
|
||||
? "https://${url.split('//').last}"
|
||||
: url);
|
||||
},
|
||||
child: Text(
|
||||
i.text ?? '',
|
||||
|
||||
@@ -224,11 +224,7 @@ class _HtmlRenderPageState extends State<HtmlRenderPage>
|
||||
IconButton(
|
||||
tooltip: '用内置浏览器打开',
|
||||
onPressed: () {
|
||||
Get.toNamed('/webview', parameters: {
|
||||
'url': url.startsWith('http') ? url : 'https:$url',
|
||||
'type': 'url',
|
||||
'pageTitle': title,
|
||||
});
|
||||
Utils.handleWebview(url.startsWith('http') ? url : 'https:$url');
|
||||
},
|
||||
icon: const Icon(Icons.open_in_browser_outlined, size: 19),
|
||||
),
|
||||
@@ -250,18 +246,15 @@ class _HtmlRenderPageState extends State<HtmlRenderPage>
|
||||
),
|
||||
PopupMenuItem(
|
||||
onTap: () => {
|
||||
Get.toNamed('/webview', parameters: {
|
||||
'url': url.startsWith('http') ? url : 'https:$url',
|
||||
'type': 'url',
|
||||
'pageTitle': title,
|
||||
}),
|
||||
Utils.handleWebview(
|
||||
url.startsWith('http') ? url : 'https:$url')
|
||||
},
|
||||
child: const Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Icon(Icons.open_in_new, size: 19),
|
||||
SizedBox(width: 10),
|
||||
Text('内置浏览器打开'),
|
||||
Text('浏览器打开'),
|
||||
],
|
||||
),
|
||||
),
|
||||
|
||||
@@ -292,21 +292,11 @@ class _LiveRoomPageState extends State<LiveRoomPage>
|
||||
),
|
||||
//内置浏览器打开
|
||||
IconButton(
|
||||
tooltip: '内置浏览器打开',
|
||||
tooltip: '浏览器打开',
|
||||
onPressed: () {
|
||||
Get.offNamed(
|
||||
'/webview',
|
||||
parameters: {
|
||||
'url':
|
||||
'https://live.bilibili.com/h5/${_liveRoomController.roomId}',
|
||||
'type': 'liveRoom',
|
||||
'pageTitle': _liveRoomController
|
||||
.roomInfoH5
|
||||
.value
|
||||
.anchorInfo!
|
||||
.baseInfo!
|
||||
.uname!,
|
||||
},
|
||||
Utils.handleWebview(
|
||||
'https://live.bilibili.com/h5/${_liveRoomController.roomId}',
|
||||
off: true,
|
||||
);
|
||||
},
|
||||
icon: const Icon(Icons.open_in_browser)),
|
||||
|
||||
@@ -1645,6 +1645,13 @@ List<SettingsModel> get extraSettings => [
|
||||
key: SettingBoxKey.banWordForReply,
|
||||
getBanWord: () => GStorage.banWordForReply,
|
||||
),
|
||||
SettingsModel(
|
||||
settingsType: SettingsType.sw1tch,
|
||||
title: '使用外部浏览器打开链接',
|
||||
leading: Icon(Icons.open_in_browser),
|
||||
setKey: SettingBoxKey.openInBrowser,
|
||||
defaultVal: false,
|
||||
),
|
||||
SettingsModel(
|
||||
settingsType: SettingsType.sw1tch,
|
||||
enableFeedback: true,
|
||||
|
||||
@@ -1035,10 +1035,7 @@ class _VideoInfoState extends State<VideoInfo> with TickerProviderStateMixin {
|
||||
recognizer: TapGestureRecognizer()
|
||||
..onTap = () {
|
||||
try {
|
||||
Get.toNamed(
|
||||
'/webview',
|
||||
parameters: {'url': matchStr},
|
||||
);
|
||||
Utils.handleWebview(matchStr);
|
||||
} catch (err) {
|
||||
SmartDialog.showToast(err.toString());
|
||||
}
|
||||
|
||||
@@ -167,14 +167,7 @@ class IntroDetail extends StatelessWidget {
|
||||
..onTap = () {
|
||||
// 处理点击事件
|
||||
try {
|
||||
Get.toNamed(
|
||||
'/webview',
|
||||
parameters: {
|
||||
'url': match.group(0)!,
|
||||
'type': 'url',
|
||||
'pageTitle': match.group(0)!,
|
||||
},
|
||||
);
|
||||
Utils.handleWebview(match.group(0)!);
|
||||
} catch (err) {
|
||||
SmartDialog.showToast(err.toString());
|
||||
}
|
||||
|
||||
@@ -838,24 +838,10 @@ class ReplyItem extends StatelessWidget {
|
||||
redirectUrl,
|
||||
);
|
||||
} else {
|
||||
Get.toNamed(
|
||||
'/webview',
|
||||
parameters: {
|
||||
'url': redirectUrl,
|
||||
'type': 'url',
|
||||
'pageTitle': title
|
||||
},
|
||||
);
|
||||
Utils.handleWebview(redirectUrl);
|
||||
}
|
||||
} else {
|
||||
Get.toNamed(
|
||||
'/webview',
|
||||
parameters: {
|
||||
'url': matchStr,
|
||||
'type': 'url',
|
||||
'pageTitle': title
|
||||
},
|
||||
);
|
||||
Utils.handleWebview(matchStr);
|
||||
}
|
||||
}
|
||||
},
|
||||
@@ -890,10 +876,7 @@ class ReplyItem extends StatelessWidget {
|
||||
color: Theme.of(context).colorScheme.primary,
|
||||
),
|
||||
recognizer: TapGestureRecognizer()
|
||||
..onTap = () => Get.toNamed(
|
||||
'/webview',
|
||||
parameters: {'url': matchStr},
|
||||
),
|
||||
..onTap = () => Utils.handleWebview(matchStr),
|
||||
),
|
||||
);
|
||||
} else {
|
||||
@@ -935,14 +918,7 @@ class ReplyItem extends StatelessWidget {
|
||||
),
|
||||
recognizer: TapGestureRecognizer()
|
||||
..onTap = () {
|
||||
Get.toNamed(
|
||||
'/webview',
|
||||
parameters: {
|
||||
'url': patternStr,
|
||||
'type': 'url',
|
||||
'pageTitle': content.jumpUrl[patternStr]['title']
|
||||
},
|
||||
);
|
||||
Utils.handleWebview(patternStr);
|
||||
},
|
||||
)
|
||||
],
|
||||
@@ -997,14 +973,8 @@ class ReplyItem extends StatelessWidget {
|
||||
color: Theme.of(context).colorScheme.primary,
|
||||
),
|
||||
recognizer: TapGestureRecognizer()
|
||||
..onTap = () => Get.toNamed(
|
||||
'/webview',
|
||||
parameters: {
|
||||
'url': content.richText['note']['click_url'],
|
||||
'type': 'note',
|
||||
'pageTitle': '笔记预览'
|
||||
},
|
||||
),
|
||||
..onTap = () =>
|
||||
Utils.handleWebview(content.richText['note']['click_url']),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -870,24 +870,10 @@ class ReplyItemGrpc extends StatelessWidget {
|
||||
redirectUrl,
|
||||
);
|
||||
} else {
|
||||
Get.toNamed(
|
||||
'/webview',
|
||||
parameters: {
|
||||
'url': redirectUrl,
|
||||
'type': 'url',
|
||||
'pageTitle': title
|
||||
},
|
||||
);
|
||||
Utils.handleWebview(redirectUrl);
|
||||
}
|
||||
} else {
|
||||
Get.toNamed(
|
||||
'/webview',
|
||||
parameters: {
|
||||
'url': matchStr,
|
||||
'type': 'url',
|
||||
'pageTitle': title
|
||||
},
|
||||
);
|
||||
Utils.handleWebview(matchStr);
|
||||
}
|
||||
}
|
||||
},
|
||||
@@ -922,10 +908,7 @@ class ReplyItemGrpc extends StatelessWidget {
|
||||
color: Theme.of(context).colorScheme.primary,
|
||||
),
|
||||
recognizer: TapGestureRecognizer()
|
||||
..onTap = () => Get.toNamed(
|
||||
'/webview',
|
||||
parameters: {'url': matchStr},
|
||||
),
|
||||
..onTap = () => Utils.handleWebview(matchStr),
|
||||
),
|
||||
);
|
||||
} else {
|
||||
@@ -966,14 +949,7 @@ class ReplyItemGrpc extends StatelessWidget {
|
||||
),
|
||||
recognizer: TapGestureRecognizer()
|
||||
..onTap = () {
|
||||
Get.toNamed(
|
||||
'/webview',
|
||||
parameters: {
|
||||
'url': patternStr,
|
||||
'type': 'url',
|
||||
'pageTitle': content.url[patternStr]!.title
|
||||
},
|
||||
);
|
||||
Utils.handleWebview(patternStr);
|
||||
},
|
||||
)
|
||||
],
|
||||
@@ -1028,14 +1004,7 @@ class ReplyItemGrpc extends StatelessWidget {
|
||||
color: Theme.of(context).colorScheme.primary,
|
||||
),
|
||||
recognizer: TapGestureRecognizer()
|
||||
..onTap = () => Get.toNamed(
|
||||
'/webview',
|
||||
parameters: {
|
||||
'url': content.richText.note.clickUrl,
|
||||
'type': 'note',
|
||||
'pageTitle': '笔记预览'
|
||||
},
|
||||
),
|
||||
..onTap = () => Utils.handleWebview(content.richText.note.clickUrl),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -190,14 +190,7 @@ class AiDetail extends StatelessWidget {
|
||||
..onTap = () {
|
||||
// 处理点击事件
|
||||
try {
|
||||
Get.toNamed(
|
||||
'/webview',
|
||||
parameters: {
|
||||
'url': match.group(0)!,
|
||||
'type': 'url',
|
||||
'pageTitle': match.group(0)!,
|
||||
},
|
||||
);
|
||||
Utils.handleWebview(match.group(0)!);
|
||||
} catch (err) {
|
||||
SmartDialog.showToast(err.toString());
|
||||
}
|
||||
|
||||
@@ -313,8 +313,7 @@ class ChatItem extends StatelessWidget {
|
||||
}
|
||||
} else {
|
||||
SmartDialog.showToast('未匹配到 BV 号');
|
||||
Get.toNamed('/webview',
|
||||
arguments: {'url': i['jump_url']});
|
||||
Utils.handleWebview(i['jump_url']);
|
||||
}
|
||||
},
|
||||
child: Row(
|
||||
|
||||
@@ -318,6 +318,9 @@ class GStorage {
|
||||
static bool get horizontalPreview => GStorage.setting
|
||||
.get(SettingBoxKey.horizontalPreview, defaultValue: false);
|
||||
|
||||
static bool get openInBrowser =>
|
||||
GStorage.setting.get(SettingBoxKey.openInBrowser, defaultValue: false);
|
||||
|
||||
static bool get savedRcmdTip =>
|
||||
GStorage.setting.get(SettingBoxKey.savedRcmdTip, defaultValue: true);
|
||||
|
||||
@@ -534,6 +537,7 @@ class SettingBoxKey {
|
||||
banWordForReply = 'banWordForReply',
|
||||
banWordForZone = 'banWordForZone',
|
||||
savedRcmdTip = 'savedRcmdTip',
|
||||
openInBrowser = 'openInBrowser',
|
||||
|
||||
// Sponsor Block
|
||||
enableSponsorBlock = 'enableSponsorBlock',
|
||||
|
||||
@@ -66,14 +66,7 @@ class UrlUtils {
|
||||
preventDuplicates: false,
|
||||
);
|
||||
} else {
|
||||
await Get.toNamed(
|
||||
'/webview',
|
||||
parameters: {
|
||||
'url': redirectUrl,
|
||||
'type': 'url',
|
||||
'pageTitle': title,
|
||||
},
|
||||
);
|
||||
Utils.handleWebview(redirectUrl);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,6 +40,24 @@ class Utils {
|
||||
|
||||
static const channel = MethodChannel("PiliPlus");
|
||||
|
||||
static void handleWebview(String url, {bool off = false}) {
|
||||
if (GStorage.openInBrowser) {
|
||||
launchURL(url);
|
||||
} else {
|
||||
if (off) {
|
||||
Get.offNamed(
|
||||
'/webview',
|
||||
parameters: {'url': url},
|
||||
);
|
||||
} else {
|
||||
toDupNamed(
|
||||
'/webview',
|
||||
parameters: {'url': url},
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static bool viewPgcFromUri(String uri) {
|
||||
String? id = RegExp(r'(ep|ss)\d+').firstMatch(uri)?.group(0);
|
||||
if (id != null) {
|
||||
|
||||
Reference in New Issue
Block a user