Skip to content

Commit

Permalink
if we are pushing a media file, broadcast the rescan intent
Browse files Browse the repository at this point in the history
  • Loading branch information
jlipps committed Jan 23, 2018
1 parent 8d0e837 commit 2721500
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions lib/commands/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ const dragStepsPerSec = 40;
const CONTAINER_PATH_MARKER = '@';
// https://regex101.com/r/PLdB0G/2
const CONTAINER_PATH_PATTERN = new RegExp(`^${CONTAINER_PATH_MARKER}([^/]+)/(.+)`);
const ANDROID_PICTURE_PATH = '/mnt/sdcard/Pictures';
const ANDROID_MEDIA_RESCAN_INTENT = 'android.intent.action.MEDIA_SCANNER_SCAN_FILE';

let commands = {}, helpers = {}, extensions = {};

Expand Down Expand Up @@ -229,6 +231,13 @@ commands.pushFile = async function (remotePath, base64Data) {
} else {
// adb push creates folders and overwrites existing files.
await this.adb.push(localFile, remotePath);

// if we have a media file, broadcast media scan intent
if (remotePath.indexOf(ANDROID_PICTURE_PATH) === 0) {
log.info("After pushing media file, broadcasting media scan intent");
await this.adb.shell(['am', 'broadcast', '-a',
ANDROID_MEDIA_RESCAN_INTENT, '-d', `file://${remotePath}`]);
}
}
} finally {
if (await fs.exists(localFile)) {
Expand Down

0 comments on commit 2721500

Please sign in to comment.