diff --git a/src/lang/ar-ye.json b/src/lang/ar-ye.json index 0d438e90b..42a338296 100644 --- a/src/lang/ar-ye.json +++ b/src/lang/ar-ye.json @@ -489,5 +489,9 @@ "issues found": "Issues found", "error details": "Error details", "active tools": "Active tools", - "available tools": "Available tools" + "available tools": "Available tools", + "shortcut request sent": "Shortcut request opened. Tap Add to finish.", + "add to home screen": "Add to home screen", + "pin shortcuts not supported": "Home screen shortcuts are not supported on this device.", + "save file before home shortcut": "Save the file before adding it to the home screen." } diff --git a/src/lang/be-by.json b/src/lang/be-by.json index a5d332699..bb6cd67ce 100644 --- a/src/lang/be-by.json +++ b/src/lang/be-by.json @@ -490,5 +490,9 @@ "issues found": "Issues found", "error details": "Error details", "active tools": "Active tools", - "available tools": "Available tools" + "available tools": "Available tools", + "shortcut request sent": "Shortcut request opened. Tap Add to finish.", + "add to home screen": "Add to home screen", + "pin shortcuts not supported": "Home screen shortcuts are not supported on this device.", + "save file before home shortcut": "Save the file before adding it to the home screen." } diff --git a/src/lang/bn-bd.json b/src/lang/bn-bd.json index 95d8086b2..914ebd71a 100644 --- a/src/lang/bn-bd.json +++ b/src/lang/bn-bd.json @@ -489,5 +489,9 @@ "issues found": "Issues found", "error details": "Error details", "active tools": "Active tools", - "available tools": "Available tools" + "available tools": "Available tools", + "shortcut request sent": "Shortcut request opened. Tap Add to finish.", + "add to home screen": "Add to home screen", + "pin shortcuts not supported": "Home screen shortcuts are not supported on this device.", + "save file before home shortcut": "Save the file before adding it to the home screen." } diff --git a/src/lang/cs-cz.json b/src/lang/cs-cz.json index 518986169..e8a7c4adf 100644 --- a/src/lang/cs-cz.json +++ b/src/lang/cs-cz.json @@ -489,5 +489,9 @@ "issues found": "Nalezené problémy", "error details": "Podrobnosti o chybě", "active tools": "Active tools", - "available tools": "Available tools" + "available tools": "Available tools", + "shortcut request sent": "Shortcut request opened. Tap Add to finish.", + "add to home screen": "Add to home screen", + "pin shortcuts not supported": "Home screen shortcuts are not supported on this device.", + "save file before home shortcut": "Save the file before adding it to the home screen." } diff --git a/src/lang/de-de.json b/src/lang/de-de.json index d80e531c6..03f2ebb1b 100644 --- a/src/lang/de-de.json +++ b/src/lang/de-de.json @@ -489,5 +489,9 @@ "issues found": "Gefundene Probleme", "error details": "Fehlerdetails", "active tools": "Aktive Tools", - "available tools": "Verfügbare Tools" + "available tools": "Verfügbare Tools", + "shortcut request sent": "Shortcut request opened. Tap Add to finish.", + "add to home screen": "Add to home screen", + "pin shortcuts not supported": "Home screen shortcuts are not supported on this device.", + "save file before home shortcut": "Save the file before adding it to the home screen." } diff --git a/src/lang/en-us.json b/src/lang/en-us.json index 0298be386..3b4e9b9ff 100644 --- a/src/lang/en-us.json +++ b/src/lang/en-us.json @@ -489,5 +489,9 @@ "issues found": "Issues found", "error details": "Error details", "active tools": "Active tools", - "available tools": "Available tools" + "available tools": "Available tools", + "shortcut request sent": "Shortcut request opened. Tap Add to finish.", + "add to home screen": "Add to home screen", + "pin shortcuts not supported": "Home screen shortcuts are not supported on this device.", + "save file before home shortcut": "Save the file before adding it to the home screen." } diff --git a/src/lang/es-sv.json b/src/lang/es-sv.json index 7e8307fc7..a3b57630c 100644 --- a/src/lang/es-sv.json +++ b/src/lang/es-sv.json @@ -489,5 +489,9 @@ "issues found": "Issues found", "error details": "Error details", "active tools": "Active tools", - "available tools": "Available tools" + "available tools": "Available tools", + "shortcut request sent": "Shortcut request opened. Tap Add to finish.", + "add to home screen": "Add to home screen", + "pin shortcuts not supported": "Home screen shortcuts are not supported on this device.", + "save file before home shortcut": "Save the file before adding it to the home screen." } diff --git a/src/lang/fr-fr.json b/src/lang/fr-fr.json index 3496cba20..9744e808f 100644 --- a/src/lang/fr-fr.json +++ b/src/lang/fr-fr.json @@ -489,5 +489,9 @@ "issues found": "Issues found", "error details": "Error details", "active tools": "Active tools", - "available tools": "Available tools" + "available tools": "Available tools", + "shortcut request sent": "Shortcut request opened. Tap Add to finish.", + "add to home screen": "Add to home screen", + "pin shortcuts not supported": "Home screen shortcuts are not supported on this device.", + "save file before home shortcut": "Save the file before adding it to the home screen." } diff --git a/src/lang/he-il.json b/src/lang/he-il.json index f62b5a376..0c53e7ecf 100644 --- a/src/lang/he-il.json +++ b/src/lang/he-il.json @@ -490,5 +490,9 @@ "issues found": "Issues found", "error details": "Error details", "active tools": "Active tools", - "available tools": "Available tools" + "available tools": "Available tools", + "shortcut request sent": "Shortcut request opened. Tap Add to finish.", + "add to home screen": "Add to home screen", + "pin shortcuts not supported": "Home screen shortcuts are not supported on this device.", + "save file before home shortcut": "Save the file before adding it to the home screen." } diff --git a/src/lang/hi-in.json b/src/lang/hi-in.json index 240a114b9..af4104b72 100644 --- a/src/lang/hi-in.json +++ b/src/lang/hi-in.json @@ -490,5 +490,9 @@ "issues found": "Issues found", "error details": "Error details", "active tools": "Active tools", - "available tools": "Available tools" + "available tools": "Available tools", + "shortcut request sent": "Shortcut request opened. Tap Add to finish.", + "add to home screen": "Add to home screen", + "pin shortcuts not supported": "Home screen shortcuts are not supported on this device.", + "save file before home shortcut": "Save the file before adding it to the home screen." } diff --git a/src/lang/hu-hu.json b/src/lang/hu-hu.json index 1804583c1..aeccd4676 100644 --- a/src/lang/hu-hu.json +++ b/src/lang/hu-hu.json @@ -489,5 +489,9 @@ "issues found": "Problémák találhatók", "error details": "Hiba részletei", "active tools": "Aktív eszközök", - "available tools": "Elérhető eszközök" + "available tools": "Elérhető eszközök", + "shortcut request sent": "Shortcut request opened. Tap Add to finish.", + "add to home screen": "Add to home screen", + "pin shortcuts not supported": "Home screen shortcuts are not supported on this device.", + "save file before home shortcut": "Save the file before adding it to the home screen." } diff --git a/src/lang/id-id.json b/src/lang/id-id.json index c447d0915..b4234168d 100644 --- a/src/lang/id-id.json +++ b/src/lang/id-id.json @@ -490,5 +490,9 @@ "issues found": "Issues found", "error details": "Error details", "active tools": "Active tools", - "available tools": "Available tools" + "available tools": "Available tools", + "shortcut request sent": "Shortcut request opened. Tap Add to finish.", + "add to home screen": "Add to home screen", + "pin shortcuts not supported": "Home screen shortcuts are not supported on this device.", + "save file before home shortcut": "Save the file before adding it to the home screen." } diff --git a/src/lang/ir-fa.json b/src/lang/ir-fa.json index fcc3340c0..15333c243 100644 --- a/src/lang/ir-fa.json +++ b/src/lang/ir-fa.json @@ -490,5 +490,9 @@ "issues found": "Issues found", "error details": "Error details", "active tools": "Active tools", - "available tools": "Available tools" + "available tools": "Available tools", + "shortcut request sent": "Shortcut request opened. Tap Add to finish.", + "add to home screen": "Add to home screen", + "pin shortcuts not supported": "Home screen shortcuts are not supported on this device.", + "save file before home shortcut": "Save the file before adding it to the home screen." } diff --git a/src/lang/it-it.json b/src/lang/it-it.json index 84ba1daec..98565a508 100644 --- a/src/lang/it-it.json +++ b/src/lang/it-it.json @@ -489,5 +489,9 @@ "issues found": "Issues found", "error details": "Error details", "active tools": "Active tools", - "available tools": "Available tools" + "available tools": "Available tools", + "shortcut request sent": "Shortcut request opened. Tap Add to finish.", + "add to home screen": "Add to home screen", + "pin shortcuts not supported": "Home screen shortcuts are not supported on this device.", + "save file before home shortcut": "Save the file before adding it to the home screen." } diff --git a/src/lang/ja-jp.json b/src/lang/ja-jp.json index 0abb0e59f..437f8d8ed 100644 --- a/src/lang/ja-jp.json +++ b/src/lang/ja-jp.json @@ -489,5 +489,9 @@ "issues found": "Issues found", "error details": "Error details", "active tools": "Active tools", - "available tools": "Available tools" + "available tools": "Available tools", + "shortcut request sent": "Shortcut request opened. Tap Add to finish.", + "add to home screen": "Add to home screen", + "pin shortcuts not supported": "Home screen shortcuts are not supported on this device.", + "save file before home shortcut": "Save the file before adding it to the home screen." } diff --git a/src/lang/ko-kr.json b/src/lang/ko-kr.json index 0c2fbec45..9a2f83e67 100644 --- a/src/lang/ko-kr.json +++ b/src/lang/ko-kr.json @@ -489,5 +489,9 @@ "issues found": "Issues found", "error details": "Error details", "active tools": "Active tools", - "available tools": "Available tools" + "available tools": "Available tools", + "shortcut request sent": "Shortcut request opened. Tap Add to finish.", + "add to home screen": "Add to home screen", + "pin shortcuts not supported": "Home screen shortcuts are not supported on this device.", + "save file before home shortcut": "Save the file before adding it to the home screen." } diff --git a/src/lang/ml-in.json b/src/lang/ml-in.json index 0c2c8ebb8..5882a1a9f 100644 --- a/src/lang/ml-in.json +++ b/src/lang/ml-in.json @@ -489,5 +489,9 @@ "issues found": "Issues found", "error details": "Error details", "active tools": "Active tools", - "available tools": "Available tools" + "available tools": "Available tools", + "shortcut request sent": "Shortcut request opened. Tap Add to finish.", + "add to home screen": "Add to home screen", + "pin shortcuts not supported": "Home screen shortcuts are not supported on this device.", + "save file before home shortcut": "Save the file before adding it to the home screen." } diff --git a/src/lang/mm-unicode.json b/src/lang/mm-unicode.json index 8e9aeedad..c63a56e33 100644 --- a/src/lang/mm-unicode.json +++ b/src/lang/mm-unicode.json @@ -489,5 +489,9 @@ "issues found": "Issues found", "error details": "Error details", "active tools": "Active tools", - "available tools": "Available tools" + "available tools": "Available tools", + "shortcut request sent": "Shortcut request opened. Tap Add to finish.", + "add to home screen": "Add to home screen", + "pin shortcuts not supported": "Home screen shortcuts are not supported on this device.", + "save file before home shortcut": "Save the file before adding it to the home screen." } diff --git a/src/lang/mm-zawgyi.json b/src/lang/mm-zawgyi.json index b22ebf425..c1611d196 100644 --- a/src/lang/mm-zawgyi.json +++ b/src/lang/mm-zawgyi.json @@ -489,5 +489,9 @@ "issues found": "Issues found", "error details": "Error details", "active tools": "Active tools", - "available tools": "Available tools" + "available tools": "Available tools", + "shortcut request sent": "Shortcut request opened. Tap Add to finish.", + "add to home screen": "Add to home screen", + "pin shortcuts not supported": "Home screen shortcuts are not supported on this device.", + "save file before home shortcut": "Save the file before adding it to the home screen." } diff --git a/src/lang/pl-pl.json b/src/lang/pl-pl.json index 6ec2c2bb5..2a890c0f0 100644 --- a/src/lang/pl-pl.json +++ b/src/lang/pl-pl.json @@ -489,5 +489,9 @@ "issues found": "Issues found", "error details": "Error details", "active tools": "Active tools", - "available tools": "Available tools" + "available tools": "Available tools", + "shortcut request sent": "Shortcut request opened. Tap Add to finish.", + "add to home screen": "Add to home screen", + "pin shortcuts not supported": "Home screen shortcuts are not supported on this device.", + "save file before home shortcut": "Save the file before adding it to the home screen." } diff --git a/src/lang/pt-br.json b/src/lang/pt-br.json index 31260eb89..b67725209 100644 --- a/src/lang/pt-br.json +++ b/src/lang/pt-br.json @@ -489,5 +489,9 @@ "issues found": "Problemas encontrados", "error details": "Detalhes do erro", "active tools": "Ferramentas ativas", - "available tools": "Ferramentas disponíveis" + "available tools": "Ferramentas disponíveis", + "shortcut request sent": "Shortcut request opened. Tap Add to finish.", + "add to home screen": "Add to home screen", + "pin shortcuts not supported": "Home screen shortcuts are not supported on this device.", + "save file before home shortcut": "Save the file before adding it to the home screen." } diff --git a/src/lang/pu-in.json b/src/lang/pu-in.json index 0f6964396..f0b636153 100644 --- a/src/lang/pu-in.json +++ b/src/lang/pu-in.json @@ -489,5 +489,9 @@ "issues found": "Issues found", "error details": "Error details", "active tools": "Active tools", - "available tools": "Available tools" + "available tools": "Available tools", + "shortcut request sent": "Shortcut request opened. Tap Add to finish.", + "add to home screen": "Add to home screen", + "pin shortcuts not supported": "Home screen shortcuts are not supported on this device.", + "save file before home shortcut": "Save the file before adding it to the home screen." } diff --git a/src/lang/ru-ru.json b/src/lang/ru-ru.json index 0ef4ad23a..1dd4c1a40 100644 --- a/src/lang/ru-ru.json +++ b/src/lang/ru-ru.json @@ -489,5 +489,9 @@ "issues found": "Issues found", "error details": "Error details", "active tools": "Active tools", - "available tools": "Available tools" + "available tools": "Available tools", + "shortcut request sent": "Shortcut request opened. Tap Add to finish.", + "add to home screen": "Add to home screen", + "pin shortcuts not supported": "Home screen shortcuts are not supported on this device.", + "save file before home shortcut": "Save the file before adding it to the home screen." } diff --git a/src/lang/tl-ph.json b/src/lang/tl-ph.json index 8fcf73751..e4e39e409 100644 --- a/src/lang/tl-ph.json +++ b/src/lang/tl-ph.json @@ -489,5 +489,9 @@ "issues found": "Issues found", "error details": "Error details", "active tools": "Active tools", - "available tools": "Available tools" + "available tools": "Available tools", + "shortcut request sent": "Shortcut request opened. Tap Add to finish.", + "add to home screen": "Add to home screen", + "pin shortcuts not supported": "Home screen shortcuts are not supported on this device.", + "save file before home shortcut": "Save the file before adding it to the home screen." } diff --git a/src/lang/tr-tr.json b/src/lang/tr-tr.json index 98ea05edd..8d1fbb845 100644 --- a/src/lang/tr-tr.json +++ b/src/lang/tr-tr.json @@ -489,5 +489,9 @@ "issues found": "Issues found", "error details": "Error details", "active tools": "Active tools", - "available tools": "Available tools" + "available tools": "Available tools", + "shortcut request sent": "Shortcut request opened. Tap Add to finish.", + "add to home screen": "Add to home screen", + "pin shortcuts not supported": "Home screen shortcuts are not supported on this device.", + "save file before home shortcut": "Save the file before adding it to the home screen." } diff --git a/src/lang/uk-ua.json b/src/lang/uk-ua.json index 259a22b1d..51af526f9 100644 --- a/src/lang/uk-ua.json +++ b/src/lang/uk-ua.json @@ -489,5 +489,9 @@ "issues found": "Issues found", "error details": "Error details", "active tools": "Active tools", - "available tools": "Available tools" + "available tools": "Available tools", + "shortcut request sent": "Shortcut request opened. Tap Add to finish.", + "add to home screen": "Add to home screen", + "pin shortcuts not supported": "Home screen shortcuts are not supported on this device.", + "save file before home shortcut": "Save the file before adding it to the home screen." } diff --git a/src/lang/uz-uz.json b/src/lang/uz-uz.json index 04b020051..5c82fe8ee 100644 --- a/src/lang/uz-uz.json +++ b/src/lang/uz-uz.json @@ -489,5 +489,9 @@ "issues found": "Issues found", "error details": "Error details", "active tools": "Active tools", - "available tools": "Available tools" + "available tools": "Available tools", + "shortcut request sent": "Shortcut request opened. Tap Add to finish.", + "add to home screen": "Add to home screen", + "pin shortcuts not supported": "Home screen shortcuts are not supported on this device.", + "save file before home shortcut": "Save the file before adding it to the home screen." } diff --git a/src/lang/vi-vn.json b/src/lang/vi-vn.json index fad4d1d60..81e8caa6c 100644 --- a/src/lang/vi-vn.json +++ b/src/lang/vi-vn.json @@ -490,5 +490,9 @@ "issues found": "Issues found", "error details": "Error details", "active tools": "Active tools", - "available tools": "Available tools" + "available tools": "Available tools", + "shortcut request sent": "Shortcut request opened. Tap Add to finish.", + "add to home screen": "Add to home screen", + "pin shortcuts not supported": "Home screen shortcuts are not supported on this device.", + "save file before home shortcut": "Save the file before adding it to the home screen." } diff --git a/src/lang/zh-cn.json b/src/lang/zh-cn.json index b3c7f5244..9239b84c8 100644 --- a/src/lang/zh-cn.json +++ b/src/lang/zh-cn.json @@ -489,5 +489,9 @@ "issues found": "出现问题", "error details": "详细错误信息", "active tools": "已启用工具", - "available tools": "可用的工具" + "available tools": "可用的工具", + "shortcut request sent": "Shortcut request opened. Tap Add to finish.", + "add to home screen": "Add to home screen", + "pin shortcuts not supported": "Home screen shortcuts are not supported on this device.", + "save file before home shortcut": "Save the file before adding it to the home screen." } diff --git a/src/lang/zh-hant.json b/src/lang/zh-hant.json index 13a86e5a8..59b9a220b 100644 --- a/src/lang/zh-hant.json +++ b/src/lang/zh-hant.json @@ -489,5 +489,9 @@ "issues found": "發現問題", "error details": "詳細錯誤資訊", "active tools": "已啟用工具", - "available tools": "可用的工具" + "available tools": "可用的工具", + "shortcut request sent": "Shortcut request opened. Tap Add to finish.", + "add to home screen": "Add to home screen", + "pin shortcuts not supported": "Home screen shortcuts are not supported on this device.", + "save file before home shortcut": "Save the file before adding it to the home screen." } diff --git a/src/lang/zh-tw.json b/src/lang/zh-tw.json index 19b3fda1e..879c2cc3a 100644 --- a/src/lang/zh-tw.json +++ b/src/lang/zh-tw.json @@ -489,5 +489,9 @@ "issues found": "Issues found", "error details": "Error details", "active tools": "Active tools", - "available tools": "Available tools" + "available tools": "Available tools", + "shortcut request sent": "Shortcut request opened. Tap Add to finish.", + "add to home screen": "Add to home screen", + "pin shortcuts not supported": "Home screen shortcuts are not supported on this device.", + "save file before home shortcut": "Save the file before adding it to the home screen." } diff --git a/src/lib/commands.js b/src/lib/commands.js index 8f70ba391..05c89d43d 100644 --- a/src/lib/commands.js +++ b/src/lib/commands.js @@ -280,6 +280,60 @@ export default { share() { editorManager.activeFile.share(); }, + async "pin-file-shortcut"() { + const file = editorManager.activeFile; + if (!file?.uri) { + toast(strings["save file before home shortcut"]); + return; + } + + if (typeof system?.pinFileShortcut !== "function") { + toast(strings["pin shortcuts not supported"]); + return; + } + + const { uri, filename } = file; + const label = filename; + const description = filename; + + let id = uri.replace(/[^a-zA-Z0-9]/g, "").toLowerCase(); + if (!id) { + id = helpers.uuid(); + } + if (id.length > 40) { + id = id.slice(-40); + } + id = `file-${id}`; + + const shortcut = { + id, + label, + description, + uri, + }; + + const requestShortcut = new Promise((resolve, reject) => { + system.pinFileShortcut( + shortcut, + () => resolve(true), + (err) => reject(err), + ); + }); + + try { + await requestShortcut; + toast(strings["shortcut request sent"]); + } catch (error) { + if ( + typeof error === "string" && + error.toLowerCase().includes("not supported") + ) { + toast(strings["pin shortcuts not supported"]); + return; + } + helpers.error(error); + } + }, syntax() { changeMode(); }, diff --git a/src/plugins/system/android/com/foxdebug/system/System.java b/src/plugins/system/android/com/foxdebug/system/System.java index 517550fc4..f6c8eeb81 100644 --- a/src/plugins/system/android/com/foxdebug/system/System.java +++ b/src/plugins/system/android/com/foxdebug/system/System.java @@ -16,14 +16,19 @@ import android.content.pm.*; import java.util.*; import android.graphics.Bitmap; +import android.graphics.Canvas; import android.graphics.Color; import android.graphics.ImageDecoder; +import android.graphics.Paint; +import android.graphics.RectF; +import android.graphics.Typeface; import android.net.Uri; import android.os.Build; import android.os.Bundle; import android.os.PowerManager; import android.provider.Settings.Global; import android.util.Base64; +import android.util.TypedValue; import android.view.View; import android.view.Window; import android.view.WindowInsetsController; @@ -60,12 +65,6 @@ import android.net.Uri; import android.util.Log; -import java.io.File; -import java.io.FileInputStream; -import java.io.FileOutputStream; -import java.io.InputStream; -import java.io.OutputStream; -import java.io.IOException; import android.webkit.MimeTypeMap; // DocumentFile import (AndroidX library) @@ -156,6 +155,7 @@ public boolean execute( case "is-powersave-mode": case "get-app-info": case "add-shortcut": + case "pin-file-shortcut": case "remove-shortcut": case "pin-shortcut": case "get-android-version": @@ -333,7 +333,7 @@ public void run() { if (new File(args.getString(0)).setExecutable(Boolean.parseBoolean(args.getString(1)))) { callbackContext.success(); } else { - callbackContext.error("set exec faild"); + callbackContext.error("set exec failed"); } return true; @@ -469,6 +469,9 @@ public void run() { callbackContext ); break; + case "pin-file-shortcut": + pinFileShortcut(args.optJSONObject(0), callbackContext); + break; case "remove-shortcut": removeShortcut(arg1, callbackContext); break; @@ -1082,6 +1085,276 @@ private void addShortcut( } } + private void pinFileShortcut(JSONObject shortcutJson, CallbackContext callback) { + if (shortcutJson == null) { + callback.error("Invalid shortcut data"); + return; + } + + String id = shortcutJson.optString("id", ""); + String label = shortcutJson.optString("label", ""); + String description = shortcutJson.optString("description", label); + String iconSrc = shortcutJson.optString("icon", ""); + String uriString = shortcutJson.optString("uri", ""); + + if (id.isEmpty() || label.isEmpty() || uriString.isEmpty()) { + callback.error("Missing required shortcut fields"); + return; + } + + if (!ShortcutManagerCompat.isRequestPinShortcutSupported(context)) { + callback.error("Not supported"); + return; + } + + try { + Uri dataUri = Uri.parse(uriString); + Intent intent = new Intent(context, activity.getClass()); + intent.setAction(Intent.ACTION_VIEW); + intent.setData(dataUri); + intent.putExtra("acodeFileUri", uriString); + intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); + intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP); + intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); + + IconCompat icon; + if (iconSrc != null && !iconSrc.isEmpty()) { + ImageDecoder.Source imgSrc = ImageDecoder.createSource( + context.getContentResolver(), + Uri.parse(iconSrc) + ); + Bitmap bitmap = ImageDecoder.decodeBitmap(imgSrc); + icon = IconCompat.createWithBitmap(bitmap); + } else { + icon = getFileShortcutIcon(label); + } + + ShortcutInfoCompat shortcut = new ShortcutInfoCompat.Builder(context, id) + .setShortLabel(label) + .setLongLabel( + description != null && !description.isEmpty() ? description : label + ) + .setIcon(icon) + .setIntent(intent) + .build(); + + ShortcutManagerCompat.pushDynamicShortcut(context, shortcut); + + boolean requested = ShortcutManagerCompat.requestPinShortcut( + context, + shortcut, + null + ); + + if (!requested) { + callback.error("Failed to request pin shortcut"); + return; + } + + callback.success(); + } catch (Exception e) { + callback.error(e.toString()); + } + } + + private IconCompat getFileShortcutIcon(String filename) { + Bitmap fallback = createFileShortcutBitmap(filename); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { + return IconCompat.createWithAdaptiveBitmap(fallback); + } + return IconCompat.createWithBitmap(fallback); + } + + private Bitmap createFileShortcutBitmap(String filename) { + final float baseSizeDp = 72f; + float sizePx = TypedValue.applyDimension( + TypedValue.COMPLEX_UNIT_DIP, + baseSizeDp, + context.getResources().getDisplayMetrics() + ); + if (sizePx <= 0) { + sizePx = baseSizeDp; + } + int size = Math.round(sizePx); + Bitmap bitmap = Bitmap.createBitmap(size, size, Bitmap.Config.ARGB_8888); + Canvas canvas = new Canvas(bitmap); + Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG | Paint.DITHER_FLAG | Paint.FILTER_BITMAP_FLAG); + + int backgroundColor = pickShortcutColor(filename); + paint.setColor(backgroundColor); + float radius = size * 0.24f; + RectF bounds = new RectF(0, 0, size, size); + canvas.drawRoundRect(bounds, radius, radius, paint); + + paint.setColor(Color.WHITE); + paint.setTextAlign(Paint.Align.CENTER); + paint.setTypeface(Typeface.create("sans-serif-medium", Typeface.BOLD)); + + String label = getShortcutLabel(filename); + float textLength = Math.max(1, label.length()); + float factor = textLength > 4 ? 0.22f : textLength > 3 ? 0.26f : 0.34f; + paint.setTextSize(size * factor); + Paint.FontMetrics metrics = paint.getFontMetrics(); + float baseline = (size - metrics.bottom - metrics.top) / 2f; + canvas.drawText(label, size / 2f, baseline, paint); + + return bitmap; + } + + private String getFileExtension(String filename) { + if (filename == null) return ""; + int dot = filename.lastIndexOf('.'); + if (dot < 0 || dot == filename.length() - 1) return ""; + return filename.substring(dot + 1).toLowerCase(Locale.getDefault()); + } + + private String getShortcutLabel(String filename) { + String ext = getFileExtension(filename); + if (!ext.isEmpty()) { + switch (ext) { + case "js": + case "jsx": + return "JS"; + case "ts": + case "tsx": + return "TS"; + case "md": + case "markdown": + return "MD"; + case "json": + return "JSON"; + case "html": + case "htm": + return "HTML"; + case "css": + return "CSS"; + case "java": + return "JAVA"; + case "kt": + case "kts": + return "KOT"; + case "py": + return "PY"; + case "rb": + return "RB"; + case "c": + return "C"; + case "cpp": + case "cc": + case "cxx": + return "CPP"; + case "h": + case "hpp": + return "HDR"; + case "go": + return "GO"; + case "rs": + return "RS"; + case "php": + return "PHP"; + case "xml": + return "XML"; + case "yml": + case "yaml": + return "YML"; + case "txt": + return "TXT"; + case "sh": + case "bash": + return "SH"; + default: + String label = ext.replaceAll("[^A-Za-z0-9]", ""); + if (label.isEmpty()) label = ext; + if (label.length() > 4) { + label = label.substring(0, 4); + } + return label.toUpperCase(Locale.getDefault()); + } + } + + if (filename != null && !filename.trim().isEmpty()) { + String cleaned = filename.replaceAll("[^A-Za-z0-9]", ""); + if (!cleaned.isEmpty()) { + if (cleaned.length() > 3) cleaned = cleaned.substring(0, 3); + return cleaned.toUpperCase(Locale.getDefault()); + } + return filename.substring(0, 1).toUpperCase(Locale.getDefault()); + } + + return "FILE"; + } + + private int pickShortcutColor(String filename) { + String ext = getFileExtension(filename); + switch (ext) { + case "js": + case "jsx": + return 0xFFF7DF1E; + case "ts": + case "tsx": + return 0xFF3178C6; + case "md": + case "markdown": + return 0xFF546E7A; + case "json": + return 0xFF4CAF50; + case "html": + case "htm": + return 0xFFF4511E; + case "css": + return 0xFF2962FF; + case "java": + return 0xFFEC6F2D; + case "kt": + case "kts": + return 0xFF7F52FF; + case "py": + return 0xFF306998; + case "rb": + return 0xFFCC342D; + case "c": + return 0xFF546E7A; + case "cpp": + case "cc": + case "cxx": + return 0xFF00599C; + case "h": + case "hpp": + return 0xFF8D6E63; + case "go": + return 0xFF00ADD8; + case "rs": + return 0xFFB7410E; + case "php": + return 0xFF8892BF; + case "xml": + return 0xFF5C6BC0; + case "yml": + case "yaml": + return 0xFF757575; + case "txt": + return 0xFF546E7A; + case "sh": + case "bash": + return 0xFF388E3C; + default: + final int[] colors = new int[] { + 0xFF1E88E5, + 0xFF6D4C41, + 0xFF00897B, + 0xFF8E24AA, + 0xFF3949AB, + 0xFF039BE5, + 0xFFD81B60, + 0xFF43A047 + }; + String key = ext.isEmpty() + ? (filename == null ? "file" : filename) + : ext; + int hash = Math.abs(key.hashCode()); + return colors[hash % colors.length]; + } + } private void pinShortcut(String id, CallbackContext callback) { ShortcutManager shortcutManager = context.getSystemService( ShortcutManager.class diff --git a/src/plugins/system/system.d.ts b/src/plugins/system/system.d.ts index 05b1a9888..23094d3e2 100644 --- a/src/plugins/system/system.d.ts +++ b/src/plugins/system/system.d.ts @@ -10,18 +10,26 @@ interface AppInfo extends Info { lastUpdateTime: number; } -interface ShortCut { - id: string; - label: string; - description: string; - icon: string; - action: string; - data: string; -} - -interface Intent { - action: string; - data: string; +interface ShortCut { + id: string; + label: string; + description: string; + icon: string; + action: string; + data: string; +} + +interface FileShortcut { + id: string; + label: string; + description?: string; + icon?: string; + uri: string; +} + +interface Intent { + action: string; + data: string; type: string; package: string; extras: { @@ -130,8 +138,19 @@ interface System { * @param onSuccess * @param onFail */ - pinShortcut(id: string, onSuccess: OnSuccessBool, onFail: OnFail): void; - /** + pinShortcut(id: string, onSuccess: OnSuccessBool, onFail: OnFail): void; + /** + * Pin a shortcut for a specific file to the home screen + * @param shortcut Shortcut configuration + * @param onSuccess + * @param onFail + */ + pinFileShortcut( + shortcut: FileShortcut, + onSuccess: OnSuccessBool, + onFail: OnFail, + ): void; + /** * Gets android version * @param onSuccess * @param onFail diff --git a/src/plugins/system/www/plugin.js b/src/plugins/system/www/plugin.js index d63af6ddc..3aed7301c 100644 --- a/src/plugins/system/www/plugin.js +++ b/src/plugins/system/www/plugin.js @@ -93,12 +93,15 @@ module.exports = { removeShortcut: function (id, onSuccess, onFail) { cordova.exec(onSuccess, onFail, 'System', 'remove-shortcut', [id]); }, - pinShortcut: function (id, onSuccess, onFail) { - cordova.exec(onSuccess, onFail, 'System', 'pin-shortcut', [id]); - }, - manageAllFiles: function (onSuccess, onFail) { - cordova.exec(onSuccess, onFail, 'System', 'manage-all-files', []); - }, + pinShortcut: function (id, onSuccess, onFail) { + cordova.exec(onSuccess, onFail, 'System', 'pin-shortcut', [id]); + }, + pinFileShortcut: function (shortcut, onSuccess, onFail) { + cordova.exec(onSuccess, onFail, 'System', 'pin-file-shortcut', [shortcut]); + }, + manageAllFiles: function (onSuccess, onFail) { + cordova.exec(onSuccess, onFail, 'System', 'manage-all-files', []); + }, getAndroidVersion: function (onSuccess, onFail) { cordova.exec(onSuccess, onFail, 'System', 'get-android-version', []); }, @@ -156,4 +159,4 @@ module.exports = { getGlobalSetting: function (key, onSuccess, onFail) { cordova.exec(onSuccess, onFail, 'System', 'get-global-setting', [key]); } -}; \ No newline at end of file +}; diff --git a/src/views/file-menu.hbs b/src/views/file-menu.hbs index 734e2a5cb..f55949de2 100644 --- a/src/views/file-menu.hbs +++ b/src/views/file-menu.hbs @@ -57,6 +57,10 @@ {{edit with}} +
  • + {{add to home screen}} + +
  • {{/file_on_disk}} {{#is_editor}}