react-native-kookit 0.4.1 → 0.4.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/android/src/main/java/expo/modules/kookit/ReactNativeKookitModule.kt +36 -6
- package/app.plugin.js +2 -2
- package/ios/ReactNativeKookitModule.swift +4 -1
- package/package.json +9 -4
- package/plugin/build/index.d.ts +12 -0
- package/plugin/build/index.d.ts.map +1 -0
- package/plugin/build/index.js +22 -0
- package/plugin/build/index.js.map +1 -0
- package/plugin/build/withContentUriCopy.d.ts +15 -0
- package/plugin/build/withContentUriCopy.d.ts.map +1 -0
- package/plugin/build/withContentUriCopy.js +253 -0
- package/plugin/build/withContentUriCopy.js.map +1 -0
- package/plugin/build/withVolumeKeyIntercept.d.ts.map +1 -1
- package/plugin/build/withVolumeKeyIntercept.js.map +1 -1
- package/plugin/package.json +1 -1
|
@@ -847,11 +847,35 @@ class ReactNativeKookitModule : Module() {
|
|
|
847
847
|
latch.await()
|
|
848
848
|
}
|
|
849
849
|
|
|
850
|
-
// Set language
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
850
|
+
// Set language with fallback for devices (e.g. OPPO ColorOS) that
|
|
851
|
+
// reject certain locale variants like "zh-CN" but accept "zh".
|
|
852
|
+
fun trySetLanguage(tts: TextToSpeech, loc: Locale): Int =
|
|
853
|
+
tts.setLanguage(loc)
|
|
854
|
+
|
|
855
|
+
val primaryLocale = parseLocale(language)
|
|
856
|
+
val fallbackLocales: List<Locale> = buildList {
|
|
857
|
+
add(primaryLocale)
|
|
858
|
+
// BCP-47 tag (handles script variants such as zh-Hans-CN)
|
|
859
|
+
add(Locale.forLanguageTag(language))
|
|
860
|
+
// language-only, e.g. Locale("zh") for "zh-CN"
|
|
861
|
+
if (primaryLocale.country.isNotEmpty()) add(Locale(primaryLocale.language))
|
|
862
|
+
// device default as last resort
|
|
863
|
+
add(Locale.getDefault())
|
|
864
|
+
}
|
|
865
|
+
|
|
866
|
+
var langSetResult = TextToSpeech.LANG_NOT_SUPPORTED
|
|
867
|
+
for (loc in fallbackLocales) {
|
|
868
|
+
val r = textToSpeech?.let { trySetLanguage(it, loc) }
|
|
869
|
+
?: TextToSpeech.LANG_NOT_SUPPORTED
|
|
870
|
+
if (r != TextToSpeech.LANG_MISSING_DATA && r != TextToSpeech.LANG_NOT_SUPPORTED) {
|
|
871
|
+
langSetResult = r
|
|
872
|
+
break
|
|
873
|
+
}
|
|
874
|
+
}
|
|
875
|
+
if (langSetResult == TextToSpeech.LANG_MISSING_DATA || langSetResult == TextToSpeech.LANG_NOT_SUPPORTED) {
|
|
876
|
+
// Last resort: proceed anyway; some OEM TTS engines ignore setLanguage
|
|
877
|
+
// but still synthesize correctly when a voice is set via voiceId.
|
|
878
|
+
android.util.Log.w("ReactNativeKookit", "Language not supported by TTS engine: $language, proceeding anyway")
|
|
855
879
|
}
|
|
856
880
|
|
|
857
881
|
// Set voice if specified
|
|
@@ -1059,9 +1083,15 @@ class ReactNativeKookitModule : Module() {
|
|
|
1059
1083
|
}
|
|
1060
1084
|
|
|
1061
1085
|
/**
|
|
1062
|
-
* Parse locale string (e.g., "en-US", "zh-CN") to Locale object
|
|
1086
|
+
* Parse locale string (e.g., "en-US", "zh-CN") to Locale object.
|
|
1087
|
+
* Uses Locale.forLanguageTag first (proper BCP-47 support), then falls back
|
|
1088
|
+
* to the manual split approach for older-style identifiers.
|
|
1063
1089
|
*/
|
|
1064
1090
|
private fun parseLocale(localeString: String): Locale {
|
|
1091
|
+
// Locale.forLanguageTag handles "zh-CN", "zh-Hans-CN", etc. correctly.
|
|
1092
|
+
val tag = Locale.forLanguageTag(localeString)
|
|
1093
|
+
if (tag.language.isNotEmpty()) return tag
|
|
1094
|
+
// Fallback for underscore-separated identifiers (e.g. "zh_CN")
|
|
1065
1095
|
val parts = localeString.split("-", "_")
|
|
1066
1096
|
return when (parts.size) {
|
|
1067
1097
|
1 -> Locale(parts[0])
|
package/app.plugin.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
try {
|
|
2
|
-
const { default: withVolumeKeyIntercept } = require(
|
|
2
|
+
const { default: withVolumeKeyIntercept } = require("./plugin/build/index");
|
|
3
3
|
module.exports = withVolumeKeyIntercept;
|
|
4
4
|
} catch (error) {
|
|
5
|
-
console.warn(
|
|
5
|
+
console.warn("Failed to load react-native-kookit plugin:", error.message);
|
|
6
6
|
// Return a no-op plugin as fallback
|
|
7
7
|
module.exports = (config) => config;
|
|
8
8
|
}
|
|
@@ -1553,7 +1553,10 @@ public class ReactNativeKookitModule: Module {
|
|
|
1553
1553
|
DispatchQueue.global(qos: .userInitiated).async {
|
|
1554
1554
|
do {
|
|
1555
1555
|
// Parse source URL
|
|
1556
|
-
let sourceURL = URL(string: sourceUri) ?? URL(fileURLWithPath: sourceUri.replacingOccurrences(of: "file://", with: ""))
|
|
1556
|
+
guard let sourceURL = URL(string: sourceUri) ?? URL(fileURLWithPath: sourceUri.replacingOccurrences(of: "file://", with: "")) else {
|
|
1557
|
+
promise.reject("COPY_ERROR", "Invalid source URI: \(sourceUri)")
|
|
1558
|
+
return
|
|
1559
|
+
}
|
|
1557
1560
|
|
|
1558
1561
|
let destURL = URL(fileURLWithPath: destinationPath.replacingOccurrences(of: "file://", with: ""))
|
|
1559
1562
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-native-kookit",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.3",
|
|
4
4
|
"description": "React Native module for intercepting volume button presses on iOS and Android, with FTP client functionality",
|
|
5
5
|
"main": "build/index.js",
|
|
6
6
|
"types": "build/index.d.ts",
|
|
@@ -31,12 +31,14 @@
|
|
|
31
31
|
"react-native-kookit",
|
|
32
32
|
"ReactNativeKookit"
|
|
33
33
|
],
|
|
34
|
-
"repository":
|
|
34
|
+
"repository": {
|
|
35
|
+
"type": "git",
|
|
36
|
+
"url": "git+https://github.com/troyeguo/react-native-kookit.git"
|
|
37
|
+
},
|
|
35
38
|
"bugs": {
|
|
36
39
|
"url": "https://github.com/troyeguo/react-native-kookit/issues"
|
|
37
40
|
},
|
|
38
41
|
"author": "troyeguo <13820674+troyeguo@users.noreply.github.com> (https://github.com/troyeguo)",
|
|
39
|
-
"license": "MIT",
|
|
40
42
|
"homepage": "https://github.com/troyeguo/react-native-kookit#readme",
|
|
41
43
|
"files": [
|
|
42
44
|
"build",
|
|
@@ -49,7 +51,6 @@
|
|
|
49
51
|
"plugin/package.json",
|
|
50
52
|
"*.md"
|
|
51
53
|
],
|
|
52
|
-
"dependencies": {},
|
|
53
54
|
"devDependencies": {
|
|
54
55
|
"@expo/config-plugins": "^8.0.0",
|
|
55
56
|
"@types/react": "~19.0.0",
|
|
@@ -68,5 +69,9 @@
|
|
|
68
69
|
"configPlugins": [
|
|
69
70
|
"./app.plugin.js"
|
|
70
71
|
]
|
|
72
|
+
},
|
|
73
|
+
"directories": {
|
|
74
|
+
"doc": "docs",
|
|
75
|
+
"example": "example"
|
|
71
76
|
}
|
|
72
77
|
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { ConfigPlugin } from "@expo/config-plugins";
|
|
2
|
+
/**
|
|
3
|
+
* Main entry point for the react-native-kookit Expo config plugin.
|
|
4
|
+
*
|
|
5
|
+
* Composes:
|
|
6
|
+
* 1. withVolumeKeyIntercept – patches MainActivity with VolumeKeyInterceptActivity
|
|
7
|
+
* 2. withContentUriCopy – patches MainActivity to eagerly copy content:// URIs
|
|
8
|
+
* on cold/warm start to avoid URI permission expiry
|
|
9
|
+
*/
|
|
10
|
+
declare const withKookit: ConfigPlugin;
|
|
11
|
+
export default withKookit;
|
|
12
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAIpD;;;;;;;GAOG;AACH,QAAA,MAAM,UAAU,EAAE,YAIjB,CAAC;AAEF,eAAe,UAAU,CAAC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const withVolumeKeyIntercept_1 = __importDefault(require("./withVolumeKeyIntercept"));
|
|
7
|
+
const withContentUriCopy_1 = __importDefault(require("./withContentUriCopy"));
|
|
8
|
+
/**
|
|
9
|
+
* Main entry point for the react-native-kookit Expo config plugin.
|
|
10
|
+
*
|
|
11
|
+
* Composes:
|
|
12
|
+
* 1. withVolumeKeyIntercept – patches MainActivity with VolumeKeyInterceptActivity
|
|
13
|
+
* 2. withContentUriCopy – patches MainActivity to eagerly copy content:// URIs
|
|
14
|
+
* on cold/warm start to avoid URI permission expiry
|
|
15
|
+
*/
|
|
16
|
+
const withKookit = (config) => {
|
|
17
|
+
config = (0, withVolumeKeyIntercept_1.default)(config);
|
|
18
|
+
config = (0, withContentUriCopy_1.default)(config);
|
|
19
|
+
return config;
|
|
20
|
+
};
|
|
21
|
+
exports.default = withKookit;
|
|
22
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;AACA,sFAA8D;AAC9D,8EAAsD;AAEtD;;;;;;;GAOG;AACH,MAAM,UAAU,GAAiB,CAAC,MAAM,EAAE,EAAE;IAC1C,MAAM,GAAG,IAAA,gCAAsB,EAAC,MAAM,CAAC,CAAC;IACxC,MAAM,GAAG,IAAA,4BAAkB,EAAC,MAAM,CAAC,CAAC;IACpC,OAAO,MAAM,CAAC;AAChB,CAAC,CAAC;AAEF,kBAAe,UAAU,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { ConfigPlugin } from "@expo/config-plugins";
|
|
2
|
+
/**
|
|
3
|
+
* Expo config plugin that patches MainActivity to eagerly copy content:// URIs
|
|
4
|
+
* into the app's cache directory on cold start (and warm start via onNewIntent).
|
|
5
|
+
*
|
|
6
|
+
* This solves the "URI permission expired" problem that occurs when Android
|
|
7
|
+
* grants a one-shot content:// permission tied to the launching intent: by the
|
|
8
|
+
* time the JS layer is ready to read the file, the permission may already be
|
|
9
|
+
* revoked. Copying the file synchronously in onCreate / onNewIntent consumes
|
|
10
|
+
* the permission while it is still valid, and the intent is rewritten to a
|
|
11
|
+
* plain file:// URI so the JS layer never sees the original content:// URI.
|
|
12
|
+
*/
|
|
13
|
+
declare const withContentUriCopy: ConfigPlugin;
|
|
14
|
+
export default withContentUriCopy;
|
|
15
|
+
//# sourceMappingURL=withContentUriCopy.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"withContentUriCopy.d.ts","sourceRoot":"","sources":["../src/withContentUriCopy.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,YAAY,EAGb,MAAM,sBAAsB,CAAC;AAE9B;;;;;;;;;;GAUG;AACH,QAAA,MAAM,kBAAkB,EAAE,YAKzB,CAAC;AAuQF,eAAe,kBAAkB,CAAC"}
|
|
@@ -0,0 +1,253 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const config_plugins_1 = require("@expo/config-plugins");
|
|
4
|
+
/**
|
|
5
|
+
* Expo config plugin that patches MainActivity to eagerly copy content:// URIs
|
|
6
|
+
* into the app's cache directory on cold start (and warm start via onNewIntent).
|
|
7
|
+
*
|
|
8
|
+
* This solves the "URI permission expired" problem that occurs when Android
|
|
9
|
+
* grants a one-shot content:// permission tied to the launching intent: by the
|
|
10
|
+
* time the JS layer is ready to read the file, the permission may already be
|
|
11
|
+
* revoked. Copying the file synchronously in onCreate / onNewIntent consumes
|
|
12
|
+
* the permission while it is still valid, and the intent is rewritten to a
|
|
13
|
+
* plain file:// URI so the JS layer never sees the original content:// URI.
|
|
14
|
+
*/
|
|
15
|
+
const withContentUriCopy = (config) => {
|
|
16
|
+
return (0, config_plugins_1.withMainActivity)(config, (config) => {
|
|
17
|
+
config.modResults = addContentUriCopyToMainActivity(config.modResults);
|
|
18
|
+
return config;
|
|
19
|
+
});
|
|
20
|
+
};
|
|
21
|
+
function addContentUriCopyToMainActivity(mainActivity) {
|
|
22
|
+
const { language, contents } = mainActivity;
|
|
23
|
+
if (language === "kt") {
|
|
24
|
+
mainActivity.contents = addContentUriCopyKotlin(contents);
|
|
25
|
+
}
|
|
26
|
+
else if (language === "java") {
|
|
27
|
+
mainActivity.contents = addContentUriCopyJava(contents);
|
|
28
|
+
}
|
|
29
|
+
return mainActivity;
|
|
30
|
+
}
|
|
31
|
+
// ─── Kotlin ──────────────────────────────────────────────────────────────────
|
|
32
|
+
function addContentUriCopyKotlin(contents) {
|
|
33
|
+
// Idempotency guard
|
|
34
|
+
if (contents.includes("copyContentUriOnColdStart")) {
|
|
35
|
+
return contents;
|
|
36
|
+
}
|
|
37
|
+
const imports = [
|
|
38
|
+
"import android.content.Intent",
|
|
39
|
+
"import android.net.Uri",
|
|
40
|
+
"import android.os.Build",
|
|
41
|
+
"import android.util.Log",
|
|
42
|
+
"import java.io.File",
|
|
43
|
+
"import java.io.FileOutputStream",
|
|
44
|
+
];
|
|
45
|
+
let modifiedContents = contents;
|
|
46
|
+
// Inject missing imports after the last existing import line
|
|
47
|
+
const lastImportMatch = modifiedContents.match(/import\s+[^\n]+\n(?!import)/);
|
|
48
|
+
if (lastImportMatch) {
|
|
49
|
+
const insertIndex = lastImportMatch.index + lastImportMatch[0].length;
|
|
50
|
+
const toAdd = imports.filter((imp) => !modifiedContents.includes(imp));
|
|
51
|
+
if (toAdd.length > 0) {
|
|
52
|
+
modifiedContents =
|
|
53
|
+
modifiedContents.slice(0, insertIndex) +
|
|
54
|
+
toAdd.join("\n") +
|
|
55
|
+
"\n" +
|
|
56
|
+
modifiedContents.slice(insertIndex);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
// Inject call before super.onCreate
|
|
60
|
+
modifiedContents = modifiedContents.replace(/(\bsuper\.onCreate\()/, "intent?.let { copyContentUriOnColdStart(it) }\n $1");
|
|
61
|
+
// Append onNewIntent override + copyContentUriOnColdStart before the last }
|
|
62
|
+
const methods = `
|
|
63
|
+
// content:// URI cold-start copy - Added by react-native-kookit
|
|
64
|
+
override fun onNewIntent(intent: Intent) {
|
|
65
|
+
copyContentUriOnColdStart(intent)
|
|
66
|
+
super.onNewIntent(intent)
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* If [intent] carries a content:// URI (ACTION_VIEW or ACTION_SEND), copy
|
|
71
|
+
* the file to the app's cache directory synchronously and rewrite the intent
|
|
72
|
+
* so that downstream code receives a plain file:// URI instead.
|
|
73
|
+
*
|
|
74
|
+
* This consumes the one-shot URI permission while it is still valid,
|
|
75
|
+
* preventing "permission denied" errors in the JS layer.
|
|
76
|
+
*/
|
|
77
|
+
private fun copyContentUriOnColdStart(intent: Intent) {
|
|
78
|
+
try {
|
|
79
|
+
val action = intent.action
|
|
80
|
+
val uri: Uri? = when (action) {
|
|
81
|
+
Intent.ACTION_VIEW -> intent.data
|
|
82
|
+
Intent.ACTION_SEND -> if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
|
|
83
|
+
intent.getParcelableExtra(Intent.EXTRA_STREAM, Uri::class.java)
|
|
84
|
+
} else {
|
|
85
|
+
@Suppress("DEPRECATION")
|
|
86
|
+
intent.getParcelableExtra(Intent.EXTRA_STREAM)
|
|
87
|
+
}
|
|
88
|
+
else -> null
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
if (uri == null || uri.scheme != "content") return
|
|
92
|
+
|
|
93
|
+
val tempDir = File(cacheDir, "temp")
|
|
94
|
+
if (!tempDir.exists()) tempDir.mkdirs()
|
|
95
|
+
|
|
96
|
+
val rawName = uri.lastPathSegment
|
|
97
|
+
?.substringAfterLast('/')
|
|
98
|
+
?.substringAfterLast('%')
|
|
99
|
+
?: "imported_file_\${System.currentTimeMillis()}"
|
|
100
|
+
|
|
101
|
+
val safeName = rawName.replace(Regex("[\\\\/:*?\"<>|]"), "_")
|
|
102
|
+
.ifBlank { "imported_file_\${System.currentTimeMillis()}" }
|
|
103
|
+
|
|
104
|
+
val destFile = File(tempDir, safeName)
|
|
105
|
+
|
|
106
|
+
contentResolver.openInputStream(uri)?.use { input ->
|
|
107
|
+
FileOutputStream(destFile).use { output ->
|
|
108
|
+
val buffer = ByteArray(8192)
|
|
109
|
+
var read: Int
|
|
110
|
+
while (input.read(buffer).also { read = it } != -1) {
|
|
111
|
+
output.write(buffer, 0, read)
|
|
112
|
+
}
|
|
113
|
+
output.flush()
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
Log.i("MainActivity", "Copied content URI to: \${destFile.absolutePath}")
|
|
118
|
+
|
|
119
|
+
val fileUri = Uri.fromFile(destFile)
|
|
120
|
+
when (action) {
|
|
121
|
+
Intent.ACTION_VIEW -> intent.data = fileUri
|
|
122
|
+
Intent.ACTION_SEND -> intent.putExtra(Intent.EXTRA_STREAM, fileUri)
|
|
123
|
+
}
|
|
124
|
+
} catch (e: Exception) {
|
|
125
|
+
Log.w("MainActivity", "Failed to copy content URI: \${e.message}")
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
`;
|
|
129
|
+
const lastBrace = modifiedContents.lastIndexOf("}");
|
|
130
|
+
modifiedContents =
|
|
131
|
+
modifiedContents.slice(0, lastBrace) +
|
|
132
|
+
methods +
|
|
133
|
+
"\n" +
|
|
134
|
+
modifiedContents.slice(lastBrace);
|
|
135
|
+
return modifiedContents;
|
|
136
|
+
}
|
|
137
|
+
// ─── Java ─────────────────────────────────────────────────────────────────────
|
|
138
|
+
function addContentUriCopyJava(contents) {
|
|
139
|
+
// Idempotency guard
|
|
140
|
+
if (contents.includes("copyContentUriOnColdStart")) {
|
|
141
|
+
return contents;
|
|
142
|
+
}
|
|
143
|
+
const imports = [
|
|
144
|
+
"import android.content.Intent;",
|
|
145
|
+
"import android.net.Uri;",
|
|
146
|
+
"import android.os.Build;",
|
|
147
|
+
"import android.util.Log;",
|
|
148
|
+
"import java.io.File;",
|
|
149
|
+
"import java.io.FileOutputStream;",
|
|
150
|
+
"import java.io.InputStream;",
|
|
151
|
+
];
|
|
152
|
+
let modifiedContents = contents;
|
|
153
|
+
// Inject missing imports after the last existing import line
|
|
154
|
+
const lastImportMatch = modifiedContents.match(/import\s+[^;]+;(?!\s*import)/);
|
|
155
|
+
if (lastImportMatch) {
|
|
156
|
+
const insertIndex = lastImportMatch.index + lastImportMatch[0].length;
|
|
157
|
+
const toAdd = imports.filter((imp) => !modifiedContents.includes(imp));
|
|
158
|
+
if (toAdd.length > 0) {
|
|
159
|
+
modifiedContents =
|
|
160
|
+
modifiedContents.slice(0, insertIndex) +
|
|
161
|
+
"\n" +
|
|
162
|
+
toAdd.join("\n") +
|
|
163
|
+
modifiedContents.slice(insertIndex);
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
// Inject call before super.onCreate
|
|
167
|
+
modifiedContents = modifiedContents.replace(/(\bsuper\.onCreate\()/, "copyContentUriOnColdStart(getIntent());\n $1");
|
|
168
|
+
// Append onNewIntent override + copyContentUriOnColdStart before the last }
|
|
169
|
+
const methods = `
|
|
170
|
+
// content:// URI cold-start copy - Added by react-native-kookit
|
|
171
|
+
@Override
|
|
172
|
+
public void onNewIntent(Intent intent) {
|
|
173
|
+
copyContentUriOnColdStart(intent);
|
|
174
|
+
super.onNewIntent(intent);
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
/**
|
|
178
|
+
* If intent carries a content:// URI (ACTION_VIEW or ACTION_SEND), copy
|
|
179
|
+
* the file to the app's cache directory synchronously and rewrite the intent
|
|
180
|
+
* so that downstream code receives a plain file:// URI instead.
|
|
181
|
+
*
|
|
182
|
+
* This consumes the one-shot URI permission while it is still valid,
|
|
183
|
+
* preventing "permission denied" errors in the JS layer.
|
|
184
|
+
*/
|
|
185
|
+
private void copyContentUriOnColdStart(Intent intent) {
|
|
186
|
+
if (intent == null) return;
|
|
187
|
+
try {
|
|
188
|
+
String action = intent.getAction();
|
|
189
|
+
Uri uri = null;
|
|
190
|
+
if (Intent.ACTION_VIEW.equals(action)) {
|
|
191
|
+
uri = intent.getData();
|
|
192
|
+
} else if (Intent.ACTION_SEND.equals(action)) {
|
|
193
|
+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
|
|
194
|
+
uri = intent.getParcelableExtra(Intent.EXTRA_STREAM, Uri.class);
|
|
195
|
+
} else {
|
|
196
|
+
uri = intent.getParcelableExtra(Intent.EXTRA_STREAM);
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
if (uri == null || !"content".equals(uri.getScheme())) return;
|
|
201
|
+
|
|
202
|
+
File tempDir = new File(getCacheDir(), "temp");
|
|
203
|
+
if (!tempDir.exists()) tempDir.mkdirs();
|
|
204
|
+
|
|
205
|
+
String lastSegment = uri.getLastPathSegment();
|
|
206
|
+
String rawName = (lastSegment != null && !lastSegment.isEmpty())
|
|
207
|
+
? lastSegment.substring(lastSegment.lastIndexOf('/') + 1)
|
|
208
|
+
: "imported_file_" + System.currentTimeMillis();
|
|
209
|
+
if (rawName.isEmpty()) rawName = "imported_file_" + System.currentTimeMillis();
|
|
210
|
+
String safeName = rawName.replaceAll("[\\\\/:\\*?\"<>|]", "_");
|
|
211
|
+
if (safeName.isEmpty()) safeName = "imported_file_" + System.currentTimeMillis();
|
|
212
|
+
|
|
213
|
+
File destFile = new File(tempDir, safeName);
|
|
214
|
+
|
|
215
|
+
InputStream input = getContentResolver().openInputStream(uri);
|
|
216
|
+
if (input != null) {
|
|
217
|
+
FileOutputStream output = new FileOutputStream(destFile);
|
|
218
|
+
try {
|
|
219
|
+
byte[] buffer = new byte[8192];
|
|
220
|
+
int read;
|
|
221
|
+
while ((read = input.read(buffer)) != -1) {
|
|
222
|
+
output.write(buffer, 0, read);
|
|
223
|
+
}
|
|
224
|
+
output.flush();
|
|
225
|
+
} finally {
|
|
226
|
+
input.close();
|
|
227
|
+
output.close();
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
Log.i("MainActivity", "Copied content URI to: " + destFile.getAbsolutePath());
|
|
232
|
+
|
|
233
|
+
Uri fileUri = Uri.fromFile(destFile);
|
|
234
|
+
if (Intent.ACTION_VIEW.equals(action)) {
|
|
235
|
+
intent.setData(fileUri);
|
|
236
|
+
} else if (Intent.ACTION_SEND.equals(action)) {
|
|
237
|
+
intent.putExtra(Intent.EXTRA_STREAM, fileUri);
|
|
238
|
+
}
|
|
239
|
+
} catch (Exception e) {
|
|
240
|
+
Log.w("MainActivity", "Failed to copy content URI: " + e.getMessage());
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
`;
|
|
244
|
+
const lastBrace = modifiedContents.lastIndexOf("}");
|
|
245
|
+
modifiedContents =
|
|
246
|
+
modifiedContents.slice(0, lastBrace) +
|
|
247
|
+
methods +
|
|
248
|
+
"\n" +
|
|
249
|
+
modifiedContents.slice(lastBrace);
|
|
250
|
+
return modifiedContents;
|
|
251
|
+
}
|
|
252
|
+
exports.default = withContentUriCopy;
|
|
253
|
+
//# sourceMappingURL=withContentUriCopy.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"withContentUriCopy.js","sourceRoot":"","sources":["../src/withContentUriCopy.ts"],"names":[],"mappings":";;AAAA,yDAI8B;AAE9B;;;;;;;;;;GAUG;AACH,MAAM,kBAAkB,GAAiB,CAAC,MAAM,EAAE,EAAE;IAClD,OAAO,IAAA,iCAAgB,EAAC,MAAM,EAAE,CAAC,MAAM,EAAE,EAAE;QACzC,MAAM,CAAC,UAAU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AM,KAAK,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC,gBAAgB,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC;QACvE,IAAI,KAAK,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YACrB,gBAAgB;gBACd,gBAAgB,CAAC,KAAK,CAAC,CAAC,EAAE,WAAW,CAAC;oBACtC,IAAI;oBACJ,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC;oBAChB,gBAAgB,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC;QACxC,CAAC;IACH,CAAC;IAED,oCAAoC;IACpC,gBAAgB,GAAG,gBAAgB,CAAC,OAAO,CACzC,uBAAuB,EACvB,iDAAiD,CAClD,CAAC;IAEF,4EAA4E;IAC5E,MAAM,OAAO,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA0EjB,CAAC;IAEA,MAAM,SAAS,GAAG,gBAAgB,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC;IACpD,gBAAgB;QACd,gBAAgB,CAAC,KAAK,CAAC,CAAC,EAAE,SAAS,CAAC;YACpC,OAAO;YACP,IAAI;YACJ,gBAAgB,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC;IAEpC,OAAO,gBAAgB,CAAC;AAC1B,CAAC;AAED,kBAAe,kBAAkB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"withVolumeKeyIntercept.d.ts","sourceRoot":"","sources":["../src/withVolumeKeyIntercept.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,YAAY,EAGb,MAAM,sBAAsB,CAAC;
|
|
1
|
+
{"version":3,"file":"withVolumeKeyIntercept.d.ts","sourceRoot":"","sources":["../src/withVolumeKeyIntercept.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,YAAY,EAGb,MAAM,sBAAsB,CAAC;AAE9B;;GAEG;AACH,QAAA,MAAM,sBAAsB,EAAE,YAO7B,CAAC;AAqKF,eAAe,sBAAsB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"withVolumeKeyIntercept.js","sourceRoot":"","sources":["../src/withVolumeKeyIntercept.ts"],"names":[],"mappings":";;AAAA,yDAI8B;
|
|
1
|
+
{"version":3,"file":"withVolumeKeyIntercept.js","sourceRoot":"","sources":["../src/withVolumeKeyIntercept.ts"],"names":[],"mappings":";;AAAA,yDAI8B;AAE9B;;GAEG;AACH,MAAM,sBAAsB,GAAiB,CAAC,MAAM,EAAE,EAAE;IACtD,OAAO,IAAA,iCAAgB,EAAC,MAAM,EAAE,CAAC,MAAM,EAAE,EAAE;QACzC,MAAM,CAAC,UAAU,GAAG,sCAAsC,CACxD,MAAM,CAAC,UAAU,CAClB,CAAC;QACF,OAAO,MAAM,CAAC;IAChB,CAAC,CAAC,CAAC;AACL,CAAC,CAAC;AAEF,SAAS,sCAAsC,CAC7C,YAAwD;IAExD,MAAM,EAAE,QAAQ,EAAE,QAAQ,EAAE,GAAG,YAAY,CAAC;IAE5C,IAAI,QAAQ,KAAK,MAAM,EAAE,CAAC;QACxB,YAAY,CAAC,QAAQ,GAAG,4BAA4B,CAAC,QAAQ,CAAC,CAAC;IACjE,CAAC;SAAM,IAAI,QAAQ,KAAK,IAAI,EAAE,CAAC;QAC7B,YAAY,CAAC,QAAQ,GAAG,8BAA8B,CAAC,QAAQ,CAAC,CAAC;IACnE,CAAC;IAED,OAAO,YAAY,CAAC;AACtB,CAAC;AAED,SAAS,8BAA8B,CAAC,QAAgB;IACtD,+BAA+B;IAC/B,IAAI,QAAQ,CAAC,QAAQ,CAAC,4BAA4B,CAAC,EAAE,CAAC;QACpD,OAAO,QAAQ,CAAC;IAClB,CAAC;IAED,cAAc;IACd,MAAM,OAAO,GAAG;QACd,8BAA8B;QAC9B,uDAAuD;QACvD,iDAAiD;KAClD,CAAC;IAEF,IAAI,gBAAgB,GA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