From ba8fbc5fa0ce7b1e60947bdf301d3d5e043fb8d9 Mon Sep 17 00:00:00 2001 From: m1ga Date: Tue, 2 Jul 2024 13:14:40 +0200 Subject: [PATCH 01/13] feat: download _alloy_ db --- Alloy/alloy.js | 4 ++++ Alloy/commands/db/index.js | 32 ++++++++++++++++++++++++++++++++ Alloy/tiapp.js | 6 ++++++ 3 files changed, 42 insertions(+) create mode 100644 Alloy/commands/db/index.js diff --git a/Alloy/alloy.js b/Alloy/alloy.js index 87d289cb0..a2b2ca0cc 100755 --- a/Alloy/alloy.js +++ b/Alloy/alloy.js @@ -81,6 +81,10 @@ program.command('purgetss') .option('--modules', 'Copy or generate the corresponding CommonJS module into `./app/lib/` folder.') .option('--vendor ', 'Use any of the following arguments to copy specific vendors: fa = Font Awesome, md = Material Design or f7 = Framework7 Icons'); +program.command('db') + .description('Fetches the default alloy database (_alloy_) from the device') + .option('get', 'Downloads the _alloy_ database to your app folder'); + program.command('info [type]', { hidden: true }); program.command('debugger', { hidden: true }); diff --git a/Alloy/commands/db/index.js b/Alloy/commands/db/index.js new file mode 100644 index 000000000..bae1291ab --- /dev/null +++ b/Alloy/commands/db/index.js @@ -0,0 +1,32 @@ +const { + exec +} = require('child_process'); +const U = require('../../utils'); +const tiapp = require('../../tiapp'); + +module.exports = async function(args, program) { + + try { + if (args.length === 0) { + execCommand('db'); + } else { + args.forEach(command => { + switch (command) { + case 'get': + tiapp.init(); + console.log('Downloading _alloy_ database to: ' + tiapp.getBundleId() + '.db'); + execCommand('adb -d shell "run-as ' + tiapp.getBundleId() + ' cat /data/data/' + tiapp.getBundleId() + '/databases/_alloy_" > ' + tiapp.getBundleId() + '.db'); + break; + } + }); + } + } catch (error) { + // + } +}; + +function execCommand(currentCommand) { + exec(currentCommand, (error, response) => { + return console.log(response); + }); +} diff --git a/Alloy/tiapp.js b/Alloy/tiapp.js index 0f15181e6..6af6d53e7 100644 --- a/Alloy/tiapp.js +++ b/Alloy/tiapp.js @@ -40,6 +40,12 @@ tiapp.getSdkVersion = function() { } } }; +tiapp.getBundleId = function() { + var elems = doc.documentElement.getElementsByTagName('id'); + if (elems && elems.length > 0) { + return U.XML.getNodeText(elems.item(elems.length - 1)); + } +}; function getSdkSelectVersion() { var homeDir = process.env[(process.platform == 'win32') ? 'USERPROFILE' : 'HOME'], file = path.join(homeDir, '.titanium', 'config.json'); From bb96725eff4898bff48512a25782692389819ded Mon Sep 17 00:00:00 2001 From: m1ga Date: Tue, 2 Jul 2024 13:16:56 +0200 Subject: [PATCH 02/13] update workflow --- .github/workflows/build.yml | 5 ++--- .github/workflows/publish.yml | 2 +- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 2c8fa986b..f3b1315da 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -16,7 +16,7 @@ jobs: fetch-depth: 0 - uses: actions/setup-node@v1 with: - node-version: '16.x' + node-version: '18.x' - name: Install dependencies run: npm ci - name: Lint @@ -28,7 +28,7 @@ jobs: strategy: fail-fast: false matrix: - nodeVersion: [ '16.x' ] + nodeVersion: [ '18.x' ] os: [ macos-latest ] tiSDK: [ latest ] steps: @@ -47,4 +47,3 @@ jobs: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - name: Run tests run: npm test - diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 1ed15caa2..e6ead8aa3 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -15,7 +15,7 @@ jobs: - name: Setup node uses: actions/setup-node@v2 with: - node-version: '16' + node-version: '18' registry-url: 'https://registry.npmjs.org' - name: Install dependencies From 07e54b8a238796e557d5aa38f7297a3174f8f29e Mon Sep 17 00:00:00 2001 From: m1ga Date: Tue, 2 Jul 2024 13:19:14 +0200 Subject: [PATCH 03/13] update workflow --- .github/workflows/build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index f3b1315da..fff1c09dd 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -42,7 +42,7 @@ jobs: run: | npm ci npm i titanium -g - ti sdk install ${{ matrix.tiSDK }} -d + ti sdk install ${{ matrix.tiSDK }} env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - name: Run tests From e268ce49a8c30a4e9a15f87031ea330be83ec5f8 Mon Sep 17 00:00:00 2001 From: m1ga Date: Thu, 5 Sep 2024 10:33:23 +0200 Subject: [PATCH 04/13] get correct ID if multiple are used --- Alloy/tiapp.js | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/Alloy/tiapp.js b/Alloy/tiapp.js index 6af6d53e7..d3f19ad78 100644 --- a/Alloy/tiapp.js +++ b/Alloy/tiapp.js @@ -43,7 +43,19 @@ tiapp.getSdkVersion = function() { tiapp.getBundleId = function() { var elems = doc.documentElement.getElementsByTagName('id'); if (elems && elems.length > 0) { - return U.XML.getNodeText(elems.item(elems.length - 1)); + var bundleId = U.XML.getNodeText(elems.item(elems.length - 1)); + var isForced = false; + for (var i = 0; i < elems.length; i++) { + if (elems.item(i).getAttribute("platform") === "android") { + // platform specific ID + isForced = true; + bundleId = U.XML.getNodeText(elems.item(i)); + } else if (elems.item(i).getAttribute("platform") === "" && !isForced) { + // normal ID - only if no platform specific was set already + bundleId = U.XML.getNodeText(elems.item(i)); + } + } + return bundleId; } }; function getSdkSelectVersion() { From 2e3dbd5544ce0a1eece028cfe43888fdf88c332b Mon Sep 17 00:00:00 2001 From: m1ga Date: Thu, 5 Sep 2024 10:36:26 +0200 Subject: [PATCH 05/13] get correct ID if multiple are used --- Alloy/tiapp.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Alloy/tiapp.js b/Alloy/tiapp.js index d3f19ad78..867db6c41 100644 --- a/Alloy/tiapp.js +++ b/Alloy/tiapp.js @@ -50,7 +50,7 @@ tiapp.getBundleId = function() { // platform specific ID isForced = true; bundleId = U.XML.getNodeText(elems.item(i)); - } else if (elems.item(i).getAttribute("platform") === "" && !isForced) { + } else if (elems.item(i).getAttribute("platform") === '' && !isForced) { // normal ID - only if no platform specific was set already bundleId = U.XML.getNodeText(elems.item(i)); } From 2369cf6c7f9dbb920f8858544be19497d06e7ff1 Mon Sep 17 00:00:00 2001 From: m1ga Date: Thu, 5 Sep 2024 10:38:16 +0200 Subject: [PATCH 06/13] get correct ID if multiple are used --- Alloy/tiapp.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Alloy/tiapp.js b/Alloy/tiapp.js index 867db6c41..603e78b98 100644 --- a/Alloy/tiapp.js +++ b/Alloy/tiapp.js @@ -46,11 +46,11 @@ tiapp.getBundleId = function() { var bundleId = U.XML.getNodeText(elems.item(elems.length - 1)); var isForced = false; for (var i = 0; i < elems.length; i++) { - if (elems.item(i).getAttribute("platform") === "android") { + if (elems.item(i).getAttribute('platform') === 'android') { // platform specific ID isForced = true; bundleId = U.XML.getNodeText(elems.item(i)); - } else if (elems.item(i).getAttribute("platform") === '' && !isForced) { + } else if (elems.item(i).getAttribute('platform') === '' && !isForced) { // normal ID - only if no platform specific was set already bundleId = U.XML.getNodeText(elems.item(i)); } From f25ebd0961e4676be0494a80603797db541fdd93 Mon Sep 17 00:00:00 2001 From: m1ga Date: Fri, 6 Sep 2024 11:45:47 +0200 Subject: [PATCH 07/13] osx fixes --- Alloy/commands/db/index.js | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/Alloy/commands/db/index.js b/Alloy/commands/db/index.js index bae1291ab..7c5b484f1 100644 --- a/Alloy/commands/db/index.js +++ b/Alloy/commands/db/index.js @@ -3,6 +3,8 @@ const { } = require('child_process'); const U = require('../../utils'); const tiapp = require('../../tiapp'); +const fs = require('fs'); +const os = require('os'); module.exports = async function(args, program) { @@ -15,7 +17,11 @@ module.exports = async function(args, program) { case 'get': tiapp.init(); console.log('Downloading _alloy_ database to: ' + tiapp.getBundleId() + '.db'); - execCommand('adb -d shell "run-as ' + tiapp.getBundleId() + ' cat /data/data/' + tiapp.getBundleId() + '/databases/_alloy_" > ' + tiapp.getBundleId() + '.db'); + var adbPath = 'adb'; + if (os.platform() === 'darwin') { + adbPath = '~/Library/Android/sdk/platform-tools/adb'; + } + execCommand(adbPath + ' shell "run-as ' + tiapp.getBundleId() + ' cat /data/data/' + tiapp.getBundleId() + '/databases/_alloy_" > ' + tiapp.getBundleId() + '.db'); break; } }); @@ -27,6 +33,12 @@ module.exports = async function(args, program) { function execCommand(currentCommand) { exec(currentCommand, (error, response) => { - return console.log(response); + if (error) { + console.error(error); + } + if (response) { + console.log(response); + } + return true; }); } From 8d4214f92c6d621b7e3460e1991fed2bba472c1f Mon Sep 17 00:00:00 2001 From: m1ga Date: Tue, 1 Oct 2024 20:51:21 +0200 Subject: [PATCH 08/13] remove workflow --- .github/workflows/build.yml | 7 ++++--- .github/workflows/publish.yml | 2 +- Alloy/commands/db/index.js | 7 ++++++- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index fff1c09dd..2c8fa986b 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -16,7 +16,7 @@ jobs: fetch-depth: 0 - uses: actions/setup-node@v1 with: - node-version: '18.x' + node-version: '16.x' - name: Install dependencies run: npm ci - name: Lint @@ -28,7 +28,7 @@ jobs: strategy: fail-fast: false matrix: - nodeVersion: [ '18.x' ] + nodeVersion: [ '16.x' ] os: [ macos-latest ] tiSDK: [ latest ] steps: @@ -42,8 +42,9 @@ jobs: run: | npm ci npm i titanium -g - ti sdk install ${{ matrix.tiSDK }} + ti sdk install ${{ matrix.tiSDK }} -d env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - name: Run tests run: npm test + diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index e6ead8aa3..1ed15caa2 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -15,7 +15,7 @@ jobs: - name: Setup node uses: actions/setup-node@v2 with: - node-version: '18' + node-version: '16' registry-url: 'https://registry.npmjs.org' - name: Install dependencies diff --git a/Alloy/commands/db/index.js b/Alloy/commands/db/index.js index 7c5b484f1..6d3f22d7c 100644 --- a/Alloy/commands/db/index.js +++ b/Alloy/commands/db/index.js @@ -16,11 +16,16 @@ module.exports = async function(args, program) { switch (command) { case 'get': tiapp.init(); - console.log('Downloading _alloy_ database to: ' + tiapp.getBundleId() + '.db'); var adbPath = 'adb'; if (os.platform() === 'darwin') { adbPath = '~/Library/Android/sdk/platform-tools/adb'; + var testPath = path.join(adbPath); + if (!fs.existsSync(testPath)) { + console.error('adb not found at ' + adbPath); + return; + } } + console.log('Downloading _alloy_ database to: ' + tiapp.getBundleId() + '.db'); execCommand(adbPath + ' shell "run-as ' + tiapp.getBundleId() + ' cat /data/data/' + tiapp.getBundleId() + '/databases/_alloy_" > ' + tiapp.getBundleId() + '.db'); break; } From 9065630fb156239e30085f7d82848546a8298ed4 Mon Sep 17 00:00:00 2001 From: m1ga Date: Sat, 22 Mar 2025 14:22:15 +0100 Subject: [PATCH 09/13] clean up empty error path --- Alloy/commands/db/index.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/Alloy/commands/db/index.js b/Alloy/commands/db/index.js index 6d3f22d7c..e47206fb8 100644 --- a/Alloy/commands/db/index.js +++ b/Alloy/commands/db/index.js @@ -31,9 +31,7 @@ module.exports = async function(args, program) { } }); } - } catch (error) { - // - } + } catch (error) {} }; function execCommand(currentCommand) { From e347c5af4ff90b6da19c0d58590a595bb2bfbd4b Mon Sep 17 00:00:00 2001 From: m1ga Date: Sat, 22 Mar 2025 14:25:40 +0100 Subject: [PATCH 10/13] output error --- Alloy/commands/db/index.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Alloy/commands/db/index.js b/Alloy/commands/db/index.js index e47206fb8..eef1c8ba3 100644 --- a/Alloy/commands/db/index.js +++ b/Alloy/commands/db/index.js @@ -31,7 +31,9 @@ module.exports = async function(args, program) { } }); } - } catch (error) {} + } catch (error) { + console.error('Failed to get database'); + } }; function execCommand(currentCommand) { From cf101d8c7f9e223bffd0c6149854b19876d8b261 Mon Sep 17 00:00:00 2001 From: m1ga Date: Sat, 22 Mar 2025 15:07:50 +0100 Subject: [PATCH 11/13] use ti config to find sdkPath --- Alloy/commands/db/index.js | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/Alloy/commands/db/index.js b/Alloy/commands/db/index.js index eef1c8ba3..2551edb53 100644 --- a/Alloy/commands/db/index.js +++ b/Alloy/commands/db/index.js @@ -1,16 +1,18 @@ const { - exec + exec, + execSync } = require('child_process'); const U = require('../../utils'); const tiapp = require('../../tiapp'); const fs = require('fs'); const os = require('os'); +const path = require('path'); module.exports = async function(args, program) { try { if (args.length === 0) { - execCommand('db'); + U.die('Missing parameter "get"'); } else { args.forEach(command => { switch (command) { @@ -18,11 +20,25 @@ module.exports = async function(args, program) { tiapp.init(); var adbPath = 'adb'; if (os.platform() === 'darwin') { + // default path adbPath = '~/Library/Android/sdk/platform-tools/adb'; - var testPath = path.join(adbPath); + + // try to get android.sdkPath from ti config + const output = execSync('ti config android.sdkPath --json') + const jsonObject = JSON.parse(output); + if (!jsonObject.hasOwnProperty('success')) { + // found string + adbPath = jsonObject; + } + + // check if adb is in that folder + const testPath = path.join(adbPath, "platform-tools/adb"); if (!fs.existsSync(testPath)) { - console.error('adb not found at ' + adbPath); + U.die('adb not found at ' + testPath + '. Please check "ti config android.sdkPath" and point to your SDK folder.'); return; + } else { + // use the new path + adbPath = testPath; } } console.log('Downloading _alloy_ database to: ' + tiapp.getBundleId() + '.db'); @@ -32,7 +48,7 @@ module.exports = async function(args, program) { }); } } catch (error) { - console.error('Failed to get database'); + console.error('Failed to get database: ' + error); } }; From 1629ec124128f5aaa6ac0843c45836e7ad7f5e59 Mon Sep 17 00:00:00 2001 From: m1ga Date: Sat, 22 Mar 2025 15:09:27 +0100 Subject: [PATCH 12/13] lint --- Alloy/commands/db/index.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Alloy/commands/db/index.js b/Alloy/commands/db/index.js index 2551edb53..a35f0be01 100644 --- a/Alloy/commands/db/index.js +++ b/Alloy/commands/db/index.js @@ -24,15 +24,15 @@ module.exports = async function(args, program) { adbPath = '~/Library/Android/sdk/platform-tools/adb'; // try to get android.sdkPath from ti config - const output = execSync('ti config android.sdkPath --json') + const output = execSync('ti config android.sdkPath --json'); const jsonObject = JSON.parse(output); - if (!jsonObject.hasOwnProperty('success')) { + if (!Object.prototype.hasOwnProperty.call(jsonObject, 'success')) { // found string adbPath = jsonObject; } // check if adb is in that folder - const testPath = path.join(adbPath, "platform-tools/adb"); + const testPath = path.join(adbPath, 'platform-tools/adb'); if (!fs.existsSync(testPath)) { U.die('adb not found at ' + testPath + '. Please check "ti config android.sdkPath" and point to your SDK folder.'); return; From db47709394e5b94f64deae5797b249b628cd3712 Mon Sep 17 00:00:00 2001 From: m1ga Date: Sun, 23 Mar 2025 19:06:21 +0100 Subject: [PATCH 13/13] better error messages --- Alloy/commands/db/index.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/Alloy/commands/db/index.js b/Alloy/commands/db/index.js index a35f0be01..97771ab80 100644 --- a/Alloy/commands/db/index.js +++ b/Alloy/commands/db/index.js @@ -9,7 +9,6 @@ const os = require('os'); const path = require('path'); module.exports = async function(args, program) { - try { if (args.length === 0) { U.die('Missing parameter "get"'); @@ -55,7 +54,11 @@ module.exports = async function(args, program) { function execCommand(currentCommand) { exec(currentCommand, (error, response) => { if (error) { - console.error(error); + if (error.message) { + console.error(error.message); + } else { + console.error("Couldn't fetch database"); + } } if (response) { console.log(response);