1
0
Fork 0

Add deeplink support (#3)

Co-authored-by: wingio <wingio@users.noreply.github.com>
This commit is contained in:
Wing 2022-12-13 15:26:41 -05:00 committed by GitHub
parent 356ececb30
commit e399b55877
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 45 additions and 61 deletions

7
.gitignore vendored
View file

@ -1,12 +1,7 @@
*.iml
.gradle
/local.properties
/.idea/caches
/.idea/libraries
/.idea/modules.xml
/.idea/workspace.xml
/.idea/navEditor.xml
/.idea/assetWizardSettings.xml
.idea
.DS_Store
/build
/captures

3
.idea/.gitignore generated vendored
View file

@ -1,3 +0,0 @@
# Default ignored files
/shelf/
/workspace.xml

1
.idea/.name generated
View file

@ -1 +0,0 @@
VencordMobile

6
.idea/compiler.xml generated
View file

@ -1,6 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="CompilerConfiguration">
<bytecodeTargetLevel target="11" />
</component>
</project>

7
.idea/discord.xml generated
View file

@ -1,7 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="DiscordProjectSettings">
<option name="show" value="ASK" />
<option name="description" value="" />
</component>
</project>

20
.idea/gradle.xml generated
View file

@ -1,20 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="GradleMigrationSettings" migrationVersion="1" />
<component name="GradleSettings">
<option name="linkedExternalProjectsSettings">
<GradleProjectSettings>
<option name="testRunner" value="GRADLE" />
<option name="distributionType" value="DEFAULT_WRAPPED" />
<option name="externalProjectPath" value="$PROJECT_DIR$" />
<option name="gradleJvm" value="Embedded JDK" />
<option name="modules">
<set>
<option value="$PROJECT_DIR$" />
<option value="$PROJECT_DIR$/app" />
</set>
</option>
</GradleProjectSettings>
</option>
</component>
</project>

10
.idea/misc.xml generated
View file

@ -1,10 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ExternalStorageConfigurationManager" enabled="true" />
<component name="ProjectRootManager" version="2" languageLevel="JDK_11" project-jdk-name="11" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/build/classes" />
</component>
<component name="ProjectType">
<option name="id" value="Android" />
</component>
</project>

6
.idea/vcs.xml generated
View file

@ -1,6 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>

View file

@ -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>

View file

@ -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);
}
}