Skip to content

Commit bc69a17

Browse files
committed
add deeplink for other host
1 parent 066b504 commit bc69a17

File tree

3 files changed

+85
-14
lines changed

3 files changed

+85
-14
lines changed

app/build.gradle.kts

Lines changed: 60 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,12 @@ android {
3737
applicationId = "dev.dimension.flare"
3838
minSdk = libs.versions.minSdk.get().toInt()
3939
targetSdk = libs.versions.compileSdk.get().toInt()
40-
versionCode = System.getenv("BUILD_NUMBER")?.toIntOrNull() ?: fdroidProp.getProperty("versionCode")?.toIntOrNull() ?: 1
41-
versionName = System.getenv("BUILD_VERSION")?.toString() ?: fdroidProp.getProperty("versionName")?.toString() ?: "0.0.0"
40+
versionCode =
41+
System.getenv("BUILD_NUMBER")?.toIntOrNull() ?: fdroidProp.getProperty("versionCode")
42+
?.toIntOrNull() ?: 1
43+
versionName =
44+
System.getenv("BUILD_VERSION")?.toString() ?: fdroidProp.getProperty("versionName")
45+
?.toString() ?: "0.0.0"
4246

4347
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
4448
vectorDrawables {
@@ -188,3 +192,57 @@ if (project.file("google-services.json").exists()) {
188192
uploadCrashlyticsMappingFileRelease.dependsOn(processDebugGoogleServices)
189193
}
190194
}
195+
196+
197+
abstract class GenerateDeepLinkManifestTask : DefaultTask() {
198+
@get:InputFile
199+
@get:PathSensitive(PathSensitivity.RELATIVE)
200+
abstract val hostsFile: RegularFileProperty
201+
@get:OutputFile
202+
abstract val manifest: RegularFileProperty
203+
204+
@TaskAction
205+
fun run() {
206+
val hosts = hostsFile.get().asFile.readLines()
207+
.map { it.trim() }
208+
.filter { it.isNotEmpty() && !it.startsWith("#") }
209+
.distinct()
210+
val dataTags = hosts.joinToString("\n") { host ->
211+
"""<data android:host="$host" />"""
212+
}
213+
214+
manifest.get().asFile.writeText(
215+
"""
216+
<?xml version="1.0" encoding="utf-8"?>
217+
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
218+
<application>
219+
<activity android:name="dev.dimension.flare.MainActivity">
220+
<intent-filter android:autoVerify="false">
221+
<action android:name="android.intent.action.VIEW"/>
222+
<category android:name="android.intent.category.DEFAULT"/>
223+
<category android:name="android.intent.category.BROWSABLE"/>
224+
<data android:scheme="https" />
225+
$dataTags
226+
</intent-filter>
227+
</activity>
228+
</application>
229+
</manifest>
230+
""".trimIndent()
231+
)
232+
}
233+
}
234+
235+
extensions.getByType(com.android.build.api.variant.AndroidComponentsExtension::class.java)
236+
.onVariants { variant: com.android.build.api.variant.Variant ->
237+
val t = tasks.register(
238+
"generate${variant.name.replaceFirstChar { it.uppercase() }}DeepLinkManifest",
239+
GenerateDeepLinkManifestTask::class.java
240+
) {
241+
hostsFile = project.layout.projectDirectory.file("deeplink.txt")
242+
}
243+
244+
variant.sources.manifests.addGeneratedManifestFile(
245+
t,
246+
GenerateDeepLinkManifestTask::manifest
247+
)
248+
}

app/deeplink.txt

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
x.com
2+
twitter.com
3+
bsky.app
4+
pawoo.net
5+
mastodon.social
6+
misskey.io
7+
next.misskey.io
8+
mstdn.jp
9+
mstdn.social
10+
mastodon.world
11+
mastodon.sdf.org
12+
universeodon.com
13+
techhub.social
14+
mastodonapp.uk
15+
mastodon.uno
16+
m.cmx.im
17+
mstdn.party
18+
infosec.exchange
19+
hachyderm.io
20+
sfba.social
21+
misskey.design
22+
ohai.social
23+
mastodon.nl
24+
troet.cafe

app/src/main/AndroidManifest.xml

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
<activity
2828
android:windowSoftInputMode="adjustResize"
2929
android:launchMode="singleTask"
30-
android:name=".MainActivity"
30+
android:name="dev.dimension.flare.MainActivity"
3131
android:exported="true"
3232
android:theme="@style/Theme.Flare.Starting">
3333
<intent-filter>
@@ -41,17 +41,6 @@
4141
<category android:name="android.intent.category.DEFAULT" />
4242
<category android:name="android.intent.category.BROWSABLE" />
4343
</intent-filter>
44-
<intent-filter android:autoVerify="false">
45-
<action android:name="android.intent.action.VIEW" />
46-
<data android:scheme="https" />
47-
<data android:host="x.com" />
48-
<data android:host="twitter.com" />
49-
<data android:host="www.x.com" />
50-
<data android:host="www.twitter.com" />
51-
52-
<category android:name="android.intent.category.DEFAULT" />
53-
<category android:name="android.intent.category.BROWSABLE" />
54-
</intent-filter>
5544
<meta-data android:name="android.app.shortcuts"
5645
android:resource="@xml/shortcuts" />
5746
</activity>

0 commit comments

Comments
 (0)