Skip to content

Commit

Permalink
feat: Open Url Out Bot WebView Regex
Browse files Browse the repository at this point in the history
  • Loading branch information
omg-xtao committed Jul 13, 2024
1 parent 0532e97 commit 5a1203d
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,9 @@
import java.util.Map;
import java.util.Objects;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.regex.Pattern;

import xyz.nextalone.nagram.NaConfig;

public abstract class BotWebViewContainer extends FrameLayout implements NotificationCenter.NotificationCenterDelegate {
private final static String DURGER_KING_USERNAME = "DurgerKingBot";
Expand Down Expand Up @@ -1983,6 +1986,19 @@ public boolean onRenderProcessGone(WebView view, RenderProcessGoneDetail detail)
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
Uri uriNew = Uri.parse(url);

// ----- Nagram Hook start -----
String urlPatternStr = NaConfig.INSTANCE.getOpenUrlOutBotWebViewRegex().String();
if (botWebViewContainer != null && !urlPatternStr.isEmpty()) {
Pattern urlPattern = Pattern.compile(urlPatternStr, Pattern.MULTILINE | Pattern.CASE_INSENSITIVE);
if (urlPattern.matcher(url).find()) {
botWebViewContainer.onOpenUri(uriNew);
d("shouldOverrideUrlLoading("+url+") = true");
return true;
}
}
// ----- Nagram Hook end -----

if (botWebViewContainer != null && Browser.isInternalUri(uriNew, null)) {
if (MessagesController.getInstance(botWebViewContainer.currentAccount).webAppAllowedProtocols != null &&
MessagesController.getInstance(botWebViewContainer.currentAccount).webAppAllowedProtocols.contains(uriNew.getScheme())) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
import java.io.File;
import java.io.FileInputStream;
import java.util.ArrayList;
import java.util.regex.Pattern;

import kotlin.Unit;

Expand Down Expand Up @@ -108,6 +109,16 @@ public class NekoExperimentalSettingsActivity extends BaseNekoXSettingsActivity
private final AbstractConfigCell regexFiltersEnableInChatsRow = cellGroup.appendCell(new ConfigCellTextCheck(NaConfig.INSTANCE.getRegexFiltersEnableInChats()));
private final AbstractConfigCell disableChatActionRow = cellGroup.appendCell(new ConfigCellTextCheck(NekoConfig.disableChatAction));
private final AbstractConfigCell disableChoosingStickerRow = cellGroup.appendCell(new ConfigCellTextCheck(NekoConfig.disableChoosingSticker));
private final AbstractConfigCell openUrlOutBotWebViewRegexRow = cellGroup.appendCell(new ConfigCellTextInput(null, NaConfig.INSTANCE.getOpenUrlOutBotWebViewRegex(),
null, null,
(input) -> {
try {
Pattern.compile(input, Pattern.MULTILINE | Pattern.CASE_INSENSITIVE);
return input;
} catch (Exception ignored) {
return "";
}
}));
private final AbstractConfigCell divider1 = cellGroup.appendCell(new ConfigCellDivider());

// Story
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -638,6 +638,12 @@ object NaConfig {
ConfigItem.configTypeInt,
0
)
val openUrlOutBotWebViewRegex =
addConfig(
"OpenUrlOutBotWebViewRegex",
ConfigItem.configTypeString,
""
)

private fun addConfig(
k: String,
Expand Down
1 change: 1 addition & 0 deletions TMessagesProj/src/main/res/values-zh-rCN/strings_na.xml
Original file line number Diff line number Diff line change
Expand Up @@ -158,4 +158,5 @@
<string name="ShowTimeHint">点击消息时间显示详细信息</string>
<string name="SearchHashtagDefaultPageChannel">在频道点击标签默认搜索页面</string>
<string name="SearchHashtagDefaultPageChat">在其他对话点击标签默认搜索页面</string>
<string name="OpenUrlOutBotWebViewRegex">指定 URL Regex 跳出 bot webview</string>
</resources>
1 change: 1 addition & 0 deletions TMessagesProj/src/main/res/values/strings_na.xml
Original file line number Diff line number Diff line change
Expand Up @@ -158,4 +158,5 @@
<string name="ShowTimeHint">Click message time to display details</string>
<string name="SearchHashtagDefaultPageChannel">Channel Click Hashtag Default Search Page</string>
<string name="SearchHashtagDefaultPageChat">Chat Click Hashtag Default Search Page</string>
<string name="OpenUrlOutBotWebViewRegex">Url regex to jump out of bot webview</string>
</resources>

0 comments on commit 5a1203d

Please sign in to comment.