Add deeplink support (#3)
Co-authored-by: wingio <wingio@users.noreply.github.com>
This commit is contained in:
parent
356ececb30
commit
e399b55877
10 changed files with 45 additions and 61 deletions
|
@ -15,11 +15,23 @@
|
|||
<activity
|
||||
android:name=".MainActivity"
|
||||
android:exported="true"
|
||||
android:configChanges="orientation|keyboardHidden|screenSize|layoutDirection">
|
||||
android:configChanges="orientation|keyboardHidden|screenSize|layoutDirection"
|
||||
android:launchMode="singleTask">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.VIEW" />
|
||||
<category android:name="android.intent.category.BROWSABLE" />
|
||||
<category android:name="android.intent.category.DEFAULT" />
|
||||
<data android:scheme="https" />
|
||||
<data android:scheme="http" />
|
||||
<data android:host="discord.com" />
|
||||
<data android:host="*.discord.com" />
|
||||
<data android:host="discordapp.com" />
|
||||
<data android:host="*.discordapp.com" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
</application>
|
||||
|
||||
|
|
|
@ -11,9 +11,11 @@ import android.webkit.ValueCallback;
|
|||
import android.webkit.WebView;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Objects;
|
||||
|
||||
public class MainActivity extends Activity {
|
||||
public static final int FILECHOOSER_RESULTCODE = 8485;
|
||||
private boolean wvInitialized = false;
|
||||
private WebView wv;
|
||||
|
||||
public ValueCallback<Uri[]> filePathCallback;
|
||||
|
@ -49,7 +51,15 @@ public class MainActivity extends Activity {
|
|||
return;
|
||||
}
|
||||
|
||||
wv.loadUrl("https://discord.com/app");
|
||||
Intent intent = getIntent();
|
||||
if (Objects.equals(intent.getAction(), Intent.ACTION_VIEW)) {
|
||||
Uri data = intent.getData();
|
||||
if (data != null) handleUrl(intent.getData());
|
||||
} else {
|
||||
wv.loadUrl("https://discord.com/app");
|
||||
}
|
||||
|
||||
wvInitialized = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -98,4 +108,24 @@ public class MainActivity extends Activity {
|
|||
.build()
|
||||
);
|
||||
}
|
||||
|
||||
public void handleUrl(Uri url) {
|
||||
if (url != null) {
|
||||
if (!url.getAuthority().contains("discord")) return;
|
||||
if (!wvInitialized) {
|
||||
wv.loadUrl(url.toString());
|
||||
} else {
|
||||
wv.evaluateJavascript("Vencord.Webpack.Common.NavigationRouter.transitionTo(\"" + url.getPath() + "\")", (result) -> {
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onNewIntent(Intent intent) {
|
||||
super.onNewIntent(intent);
|
||||
Uri data = intent.getData();
|
||||
if (data != null) handleUrl(data);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue