Skip to content

Commit

Permalink
feat: download _alloy_ db
Browse files Browse the repository at this point in the history
  • Loading branch information
m1ga committed Jul 2, 2024
1 parent be399c8 commit ba8fbc5
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 0 deletions.
4 changes: 4 additions & 0 deletions Alloy/alloy.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ program.command('purgetss')
.option('--modules', 'Copy or generate the corresponding CommonJS module into `./app/lib/` folder.')
.option('--vendor <arguments>', '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 });
Expand Down
32 changes: 32 additions & 0 deletions Alloy/commands/db/index.js
Original file line number Diff line number Diff line change
@@ -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);
});
}
6 changes: 6 additions & 0 deletions Alloy/tiapp.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down

0 comments on commit ba8fbc5

Please sign in to comment.