Skip to content

Commit

Permalink
always rescan media if someone pushes a file
Browse files Browse the repository at this point in the history
  • Loading branch information
jlipps committed Feb 16, 2018
1 parent 45c5cd6 commit c119cad
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions lib/commands/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ const dragStepsPerSec = 40;
const CONTAINER_PATH_MARKER = '@';
// https://regex101.com/r/PLdB0G/2
const CONTAINER_PATH_PATTERN = new RegExp(`^${CONTAINER_PATH_MARKER}([^/]+)/(.+)`);
const ANDROID_SDCARD_PATH_RE = new RegExp('^/mnt/sdcard/');
const ANDROID_MEDIA_RESCAN_INTENT = 'android.intent.action.MEDIA_SCANNER_SCAN_FILE';

let commands = {}, helpers = {}, extensions = {};
Expand Down Expand Up @@ -232,11 +231,14 @@ commands.pushFile = async function (remotePath, base64Data) {
// 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 (ANDROID_SDCARD_PATH_RE.test(remotePath)) {
log.info("After pushing media file, broadcasting media scan intent");
// if we have pushed a file, it might be a media file, so ensure that
// apps know about it
log.info("After pushing media file, broadcasting media scan intent");
try {
await this.adb.shell(['am', 'broadcast', '-a',
ANDROID_MEDIA_RESCAN_INTENT, '-d', `file://${remotePath}`]);
} catch (e) {
log.warn(`Got error broadcasting media scan intent: ${e.message}; ignoring`);
}
}
} finally {
Expand Down

0 comments on commit c119cad

Please sign in to comment.