From b16a6c722345532075c0eaf268dd21972ecea8d3 Mon Sep 17 00:00:00 2001 From: Raunak Raj <71929976+bajrangCoder@users.noreply.github.com> Date: Thu, 23 Oct 2025 21:57:16 +0530 Subject: [PATCH 1/2] feat: add support for pinning file shortcuts to home --- src/lang/ar-ye.json | 6 +- src/lang/be-by.json | 6 +- src/lang/bn-bd.json | 6 +- src/lang/cs-cz.json | 6 +- src/lang/de-de.json | 6 +- src/lang/en-us.json | 6 +- src/lang/es-sv.json | 6 +- src/lang/fr-fr.json | 6 +- src/lang/he-il.json | 6 +- src/lang/hi-in.json | 6 +- src/lang/hu-hu.json | 6 +- src/lang/id-id.json | 6 +- src/lang/ir-fa.json | 6 +- src/lang/it-it.json | 6 +- src/lang/ja-jp.json | 6 +- src/lang/ko-kr.json | 6 +- src/lang/ml-in.json | 6 +- src/lang/mm-unicode.json | 6 +- src/lang/mm-zawgyi.json | 6 +- src/lang/pl-pl.json | 6 +- src/lang/pt-br.json | 6 +- src/lang/pu-in.json | 6 +- src/lang/ru-ru.json | 6 +- src/lang/tl-ph.json | 6 +- src/lang/tr-tr.json | 6 +- src/lang/uk-ua.json | 6 +- src/lang/uz-uz.json | 6 +- src/lang/vi-vn.json | 6 +- src/lang/zh-cn.json | 6 +- src/lang/zh-hant.json | 6 +- src/lang/zh-tw.json | 6 +- src/lib/commands.js | 54 ++++ .../android/com/foxdebug/system/System.java | 287 +++++++++++++++++- src/plugins/system/system.d.ts | 47 ++- src/plugins/system/www/plugin.js | 17 +- src/views/file-menu.hbs | 15 +- 36 files changed, 541 insertions(+), 65 deletions(-) diff --git a/src/lang/ar-ye.json b/src/lang/ar-ye.json index cb8bc1414..4ece7b708 100644 --- a/src/lang/ar-ye.json +++ b/src/lang/ar-ye.json @@ -431,5 +431,9 @@ "prompt update check consent message": "Acode can check for new app updates when you're online. Enable update checks?", "keywords": "Keywords", "author": "Author", - "filtered by": "Filtered by" + "filtered by": "Filtered by", + "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.", + "shortcut request sent": "Shortcut request opened. Tap Add to finish." } diff --git a/src/lang/be-by.json b/src/lang/be-by.json index acb0ad114..e81078957 100644 --- a/src/lang/be-by.json +++ b/src/lang/be-by.json @@ -432,5 +432,9 @@ "prompt update check consent message": "Acode can check for new app updates when you're online. Enable update checks?", "keywords": "Keywords", "author": "Author", - "filtered by": "Filtered by" + "filtered by": "Filtered by", + "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.", + "shortcut request sent": "Shortcut request opened. Tap Add to finish." } diff --git a/src/lang/bn-bd.json b/src/lang/bn-bd.json index fbcf89681..ef138c7ea 100644 --- a/src/lang/bn-bd.json +++ b/src/lang/bn-bd.json @@ -431,5 +431,9 @@ "prompt update check consent message": "Acode can check for new app updates when you're online. Enable update checks?", "keywords": "Keywords", "author": "Author", - "filtered by": "Filtered by" + "filtered by": "Filtered by", + "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.", + "shortcut request sent": "Shortcut request opened. Tap Add to finish." } diff --git a/src/lang/cs-cz.json b/src/lang/cs-cz.json index 8ca1529c3..ca1fbc83e 100644 --- a/src/lang/cs-cz.json +++ b/src/lang/cs-cz.json @@ -431,5 +431,9 @@ "prompt update check consent message": "Acode can check for new app updates when you're online. Enable update checks?", "keywords": "Keywords", "author": "Author", - "filtered by": "Filtered by" + "filtered by": "Filtered by", + "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.", + "shortcut request sent": "Shortcut request opened. Tap Add to finish." } diff --git a/src/lang/de-de.json b/src/lang/de-de.json index 1abebdb0f..a5764dddd 100644 --- a/src/lang/de-de.json +++ b/src/lang/de-de.json @@ -431,5 +431,9 @@ "prompt update check consent message": "Acode kann nach neuen App-Updates suchen, wenn Sie online sind. Update-Prüfungen aktivieren?", "keywords": "Schlüsselwörter", "author": "Autor", - "filtered by": "Gefiltert nach" + "filtered by": "Gefiltert nach", + "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.", + "shortcut request sent": "Shortcut request opened. Tap Add to finish." } diff --git a/src/lang/en-us.json b/src/lang/en-us.json index 73506f184..aaffe64f1 100644 --- a/src/lang/en-us.json +++ b/src/lang/en-us.json @@ -431,5 +431,9 @@ "prompt update check consent message": "Acode can check for new app updates when you're online. Enable update checks?", "keywords": "Keywords", "author": "Author", - "filtered by": "Filtered by" + "filtered by": "Filtered by", + "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.", + "shortcut request sent": "Shortcut request opened. Tap Add to finish." } diff --git a/src/lang/es-sv.json b/src/lang/es-sv.json index 7ec5373e7..bcffb0362 100644 --- a/src/lang/es-sv.json +++ b/src/lang/es-sv.json @@ -431,5 +431,9 @@ "prompt update check consent message": "Acode can check for new app updates when you're online. Enable update checks?", "keywords": "Keywords", "author": "Author", - "filtered by": "Filtered by" + "filtered by": "Filtered by", + "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.", + "shortcut request sent": "Shortcut request opened. Tap Add to finish." } diff --git a/src/lang/fr-fr.json b/src/lang/fr-fr.json index 1d8bfa695..28699d8c8 100644 --- a/src/lang/fr-fr.json +++ b/src/lang/fr-fr.json @@ -431,5 +431,9 @@ "prompt update check consent message": "Acode can check for new app updates when you're online. Enable update checks?", "keywords": "Keywords", "author": "Author", - "filtered by": "Filtered by" + "filtered by": "Filtered by", + "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.", + "shortcut request sent": "Shortcut request opened. Tap Add to finish." } diff --git a/src/lang/he-il.json b/src/lang/he-il.json index 47eeced10..e60986df5 100644 --- a/src/lang/he-il.json +++ b/src/lang/he-il.json @@ -432,5 +432,9 @@ "prompt update check consent message": "Acode can check for new app updates when you're online. Enable update checks?", "keywords": "Keywords", "author": "Author", - "filtered by": "Filtered by" + "filtered by": "Filtered by", + "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.", + "shortcut request sent": "Shortcut request opened. Tap Add to finish." } diff --git a/src/lang/hi-in.json b/src/lang/hi-in.json index c82a22a4b..6cf47f3e0 100644 --- a/src/lang/hi-in.json +++ b/src/lang/hi-in.json @@ -432,5 +432,9 @@ "prompt update check consent message": "Acode can check for new app updates when you're online. Enable update checks?", "keywords": "Keywords", "author": "Author", - "filtered by": "Filtered by" + "filtered by": "Filtered by", + "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.", + "shortcut request sent": "Shortcut request opened. Tap Add to finish." } diff --git a/src/lang/hu-hu.json b/src/lang/hu-hu.json index 1833243e4..5dc5cecd0 100644 --- a/src/lang/hu-hu.json +++ b/src/lang/hu-hu.json @@ -431,5 +431,9 @@ "prompt update check consent message": "Internetkapcsolat esetén az Acode ellenőrizheti az új alkalmazásfrissítéseket. Engedélyezi a frissítések ellenőrzését?", "keywords": "Kulcsszavak", "author": "Szerző", - "filtered by": "Szűrési szempont" + "filtered by": "Szűrési szempont", + "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.", + "shortcut request sent": "Shortcut request opened. Tap Add to finish." } diff --git a/src/lang/id-id.json b/src/lang/id-id.json index 9bef5e06d..273f8e16e 100644 --- a/src/lang/id-id.json +++ b/src/lang/id-id.json @@ -432,5 +432,9 @@ "prompt update check consent message": "Acode dapat memeriksa pembaruan aplikasi baru saat Anda online. Aktifkan pemeriksaan pembaruan?", "keywords": "Kata kunci", "author": "Pembuat", - "filtered by": "Disaring oleh" + "filtered by": "Disaring oleh", + "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.", + "shortcut request sent": "Shortcut request opened. Tap Add to finish." } diff --git a/src/lang/ir-fa.json b/src/lang/ir-fa.json index 42eb53298..a8a1eefdf 100644 --- a/src/lang/ir-fa.json +++ b/src/lang/ir-fa.json @@ -432,5 +432,9 @@ "prompt update check consent message": "Acode can check for new app updates when you're online. Enable update checks?", "keywords": "Keywords", "author": "Author", - "filtered by": "Filtered by" + "filtered by": "Filtered by", + "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.", + "shortcut request sent": "Shortcut request opened. Tap Add to finish." } diff --git a/src/lang/it-it.json b/src/lang/it-it.json index ae0dc623a..872dac4f8 100644 --- a/src/lang/it-it.json +++ b/src/lang/it-it.json @@ -431,5 +431,9 @@ "prompt update check consent message": "Acode can check for new app updates when you're online. Enable update checks?", "keywords": "Keywords", "author": "Author", - "filtered by": "Filtered by" + "filtered by": "Filtered by", + "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.", + "shortcut request sent": "Shortcut request opened. Tap Add to finish." } diff --git a/src/lang/ja-jp.json b/src/lang/ja-jp.json index 0cd7eec85..bb72b4654 100644 --- a/src/lang/ja-jp.json +++ b/src/lang/ja-jp.json @@ -431,5 +431,9 @@ "prompt update check consent message": "Acode can check for new app updates when you're online. Enable update checks?", "keywords": "Keywords", "author": "Author", - "filtered by": "Filtered by" + "filtered by": "Filtered by", + "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.", + "shortcut request sent": "Shortcut request opened. Tap Add to finish." } diff --git a/src/lang/ko-kr.json b/src/lang/ko-kr.json index 0a90b986f..137aab522 100644 --- a/src/lang/ko-kr.json +++ b/src/lang/ko-kr.json @@ -431,5 +431,9 @@ "prompt update check consent message": "Acode can check for new app updates when you're online. Enable update checks?", "keywords": "Keywords", "author": "Author", - "filtered by": "Filtered by" + "filtered by": "Filtered by", + "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.", + "shortcut request sent": "Shortcut request opened. Tap Add to finish." } diff --git a/src/lang/ml-in.json b/src/lang/ml-in.json index 2194c23a3..4107f42d6 100644 --- a/src/lang/ml-in.json +++ b/src/lang/ml-in.json @@ -431,5 +431,9 @@ "prompt update check consent message": "Acode can check for new app updates when you're online. Enable update checks?", "keywords": "Keywords", "author": "Author", - "filtered by": "Filtered by" + "filtered by": "Filtered by", + "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.", + "shortcut request sent": "Shortcut request opened. Tap Add to finish." } diff --git a/src/lang/mm-unicode.json b/src/lang/mm-unicode.json index 0fd284657..c01ba0dd7 100644 --- a/src/lang/mm-unicode.json +++ b/src/lang/mm-unicode.json @@ -431,5 +431,9 @@ "prompt update check consent message": "Acode can check for new app updates when you're online. Enable update checks?", "keywords": "Keywords", "author": "Author", - "filtered by": "Filtered by" + "filtered by": "Filtered by", + "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.", + "shortcut request sent": "Shortcut request opened. Tap Add to finish." } diff --git a/src/lang/mm-zawgyi.json b/src/lang/mm-zawgyi.json index 592873ccc..e3fd37366 100644 --- a/src/lang/mm-zawgyi.json +++ b/src/lang/mm-zawgyi.json @@ -431,5 +431,9 @@ "prompt update check consent message": "Acode can check for new app updates when you're online. Enable update checks?", "keywords": "Keywords", "author": "Author", - "filtered by": "Filtered by" + "filtered by": "Filtered by", + "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.", + "shortcut request sent": "Shortcut request opened. Tap Add to finish." } diff --git a/src/lang/pl-pl.json b/src/lang/pl-pl.json index f28fab450..706cc59d6 100644 --- a/src/lang/pl-pl.json +++ b/src/lang/pl-pl.json @@ -431,5 +431,9 @@ "prompt update check consent message": "Acode can check for new app updates when you're online. Enable update checks?", "keywords": "Keywords", "author": "Author", - "filtered by": "Filtered by" + "filtered by": "Filtered by", + "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.", + "shortcut request sent": "Shortcut request opened. Tap Add to finish." } diff --git a/src/lang/pt-br.json b/src/lang/pt-br.json index a6867794c..db5913cd9 100644 --- a/src/lang/pt-br.json +++ b/src/lang/pt-br.json @@ -431,5 +431,9 @@ "prompt update check consent message": "Acode can check for new app updates when you're online. Enable update checks?", "keywords": "Keywords", "author": "Author", - "filtered by": "Filtered by" + "filtered by": "Filtered by", + "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.", + "shortcut request sent": "Shortcut request opened. Tap Add to finish." } diff --git a/src/lang/pu-in.json b/src/lang/pu-in.json index 93ad13448..49abdc233 100644 --- a/src/lang/pu-in.json +++ b/src/lang/pu-in.json @@ -431,5 +431,9 @@ "prompt update check consent message": "Acode can check for new app updates when you're online. Enable update checks?", "keywords": "Keywords", "author": "Author", - "filtered by": "Filtered by" + "filtered by": "Filtered by", + "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.", + "shortcut request sent": "Shortcut request opened. Tap Add to finish." } diff --git a/src/lang/ru-ru.json b/src/lang/ru-ru.json index 98d088c09..2cbebe726 100644 --- a/src/lang/ru-ru.json +++ b/src/lang/ru-ru.json @@ -431,5 +431,9 @@ "prompt update check consent message": "Acode can check for new app updates when you're online. Enable update checks?", "keywords": "Keywords", "author": "Author", - "filtered by": "Filtered by" + "filtered by": "Filtered by", + "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.", + "shortcut request sent": "Shortcut request opened. Tap Add to finish." } diff --git a/src/lang/tl-ph.json b/src/lang/tl-ph.json index 874736e9f..514f45c90 100644 --- a/src/lang/tl-ph.json +++ b/src/lang/tl-ph.json @@ -431,5 +431,9 @@ "prompt update check consent message": "Acode can check for new app updates when you're online. Enable update checks?", "keywords": "Keywords", "author": "Author", - "filtered by": "Filtered by" + "filtered by": "Filtered by", + "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.", + "shortcut request sent": "Shortcut request opened. Tap Add to finish." } diff --git a/src/lang/tr-tr.json b/src/lang/tr-tr.json index c33509167..1a5e31c2d 100644 --- a/src/lang/tr-tr.json +++ b/src/lang/tr-tr.json @@ -431,5 +431,9 @@ "prompt update check consent message": "Acode can check for new app updates when you're online. Enable update checks?", "keywords": "Keywords", "author": "Author", - "filtered by": "Filtered by" + "filtered by": "Filtered by", + "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.", + "shortcut request sent": "Shortcut request opened. Tap Add to finish." } diff --git a/src/lang/uk-ua.json b/src/lang/uk-ua.json index c2784ea9c..a611bfe56 100644 --- a/src/lang/uk-ua.json +++ b/src/lang/uk-ua.json @@ -431,5 +431,9 @@ "prompt update check consent message": "Acode can check for new app updates when you're online. Enable update checks?", "keywords": "Keywords", "author": "Author", - "filtered by": "Filtered by" + "filtered by": "Filtered by", + "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.", + "shortcut request sent": "Shortcut request opened. Tap Add to finish." } diff --git a/src/lang/uz-uz.json b/src/lang/uz-uz.json index 7528eec4d..09a67f041 100644 --- a/src/lang/uz-uz.json +++ b/src/lang/uz-uz.json @@ -431,5 +431,9 @@ "prompt update check consent message": "Acode can check for new app updates when you're online. Enable update checks?", "keywords": "Keywords", "author": "Author", - "filtered by": "Filtered by" + "filtered by": "Filtered by", + "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.", + "shortcut request sent": "Shortcut request opened. Tap Add to finish." } diff --git a/src/lang/vi-vn.json b/src/lang/vi-vn.json index 85df2bdbb..708480c4e 100644 --- a/src/lang/vi-vn.json +++ b/src/lang/vi-vn.json @@ -432,5 +432,9 @@ "prompt update check consent message": "Acode can check for new app updates when you're online. Enable update checks?", "keywords": "Keywords", "author": "Author", - "filtered by": "Filtered by" + "filtered by": "Filtered by", + "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.", + "shortcut request sent": "Shortcut request opened. Tap Add to finish." } diff --git a/src/lang/zh-cn.json b/src/lang/zh-cn.json index b72668b1f..e83e2f4dd 100644 --- a/src/lang/zh-cn.json +++ b/src/lang/zh-cn.json @@ -431,5 +431,9 @@ "prompt update check consent message": "Acode can check for new app updates when you're online. Enable update checks?", "keywords": "Keywords", "author": "Author", - "filtered by": "Filtered by" + "filtered by": "Filtered by", + "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.", + "shortcut request sent": "Shortcut request opened. Tap Add to finish." } diff --git a/src/lang/zh-hant.json b/src/lang/zh-hant.json index 54202d18b..5a838e2cb 100644 --- a/src/lang/zh-hant.json +++ b/src/lang/zh-hant.json @@ -431,5 +431,9 @@ "prompt update check consent message": "Acode can check for new app updates when you're online. Enable update checks?", "keywords": "Keywords", "author": "Author", - "filtered by": "Filtered by" + "filtered by": "Filtered by", + "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.", + "shortcut request sent": "Shortcut request opened. Tap Add to finish." } diff --git a/src/lang/zh-tw.json b/src/lang/zh-tw.json index becdaef5b..73ff3cade 100644 --- a/src/lang/zh-tw.json +++ b/src/lang/zh-tw.json @@ -431,5 +431,9 @@ "prompt update check consent message": "Acode can check for new app updates when you're online. Enable update checks?", "keywords": "Keywords", "author": "Author", - "filtered by": "Filtered by" + "filtered by": "Filtered by", + "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.", + "shortcut request sent": "Shortcut request opened. Tap Add to finish." } 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 087ef1d16..0b588d53a 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) @@ -155,6 +154,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": @@ -332,7 +332,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; @@ -468,6 +468,9 @@ public void run() { callbackContext ); break; + case "pin-file-shortcut": + pinFileShortcut(args.optJSONObject(0), callbackContext); + break; case "remove-shortcut": removeShortcut(arg1, callbackContext); break; @@ -1022,6 +1025,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..1527cb9a1 100644 --- a/src/views/file-menu.hbs +++ b/src/views/file-menu.hbs @@ -53,12 +53,15 @@ {{open with}} -
  • - {{edit with}} - -
  • -{{/file_on_disk}} - +
  • + {{edit with}} +
  • +
  • + {{add to home screen}} + +
  • +{{/file_on_disk}} + {{#is_editor}}
  • From a68fb0aadccb4e3a10a10e9e66dcf31ff4b5e724 Mon Sep 17 00:00:00 2001 From: Raunak Raj <71929976+bajrangCoder@users.noreply.github.com> Date: Thu, 23 Oct 2025 21:59:14 +0530 Subject: [PATCH 2/2] fix --- src/views/file-menu.hbs | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/src/views/file-menu.hbs b/src/views/file-menu.hbs index 1527cb9a1..f55949de2 100644 --- a/src/views/file-menu.hbs +++ b/src/views/file-menu.hbs @@ -53,15 +53,16 @@ {{open with}}
  • -
  • - {{edit with}} -
  • -
  • - {{add to home screen}} - -
  • -{{/file_on_disk}} - +
  • + {{edit with}} + +
  • +
  • + {{add to home screen}} + +
  • +{{/file_on_disk}} + {{#is_editor}}