Skip to content

Commit

Permalink
fix: 🐛 Fix file manager on new android versions & show no files notice
Browse files Browse the repository at this point in the history
  • Loading branch information
Frontesque committed Jul 3, 2022
1 parent 6bba987 commit bbfba90
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 32 deletions.
73 changes: 46 additions & 27 deletions src/renderer/pages/tools/files.vue
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,13 @@
<v-progress-circular indeterminate color="primary" size="50" class="loading" v-if="loading" />
<!-- End Loading Wheel -->

<!-- Package Selector -->
<!-- Empty Notice -->
<div class="loading" v-if="loading == false && files.length == 0">
No files or directories
</div>
<!-- End Empty Notice -->

<!-- File Selector -->
<v-list-item-group v-model="selected" color="primary" style="margin-top: 12em;">
<v-list-item v-for="(item, i) in files" :key="i">

Expand All @@ -39,7 +45,7 @@

</v-list-item>
</v-list-item-group>
<!-- End Package Selector -->
<!-- End File Selector -->


</div>
Expand All @@ -65,16 +71,23 @@
export default {
data() {
return {
path: "/",
path: "/sdcard/",
files: new Array(),
selected: null,
loading: true,
actions: [
{
name: "Download",
icon: "mdi-download",
name: "Back",
icon: "mdi-arrow-up",
color: "primary",
action: this.back,
requireSelected: false,
},
{
name: "Transfer",
icon: "mdi-download",
color: "green",
action: this.enable,
},
{
Expand All @@ -83,13 +96,6 @@ export default {
color: "red",
action: this.uninstall,
}
],
icons: [
{ package: "com.android", icon:"mdi-android" },
{ package: "com.google", icon:"mdi-google" },
{ package: "theme", icon:"mdi-brush-variant" },
{ package: "font", icon:"mdi-format-font" },
]
}
},
Expand All @@ -100,9 +106,9 @@ export default {
watch: {
selected() {
if (!this.selected) return;
const sel = this.files[this.selected];
if (!sel) return;
if (sel.type == "directory") {
this.selected = null;
this.path += sel.name;
Expand All @@ -116,25 +122,38 @@ export default {
this.loading = true;
this.files = new Array();
const dir = await this.$fm.getDir(this.path);
for (const i in dir.directories) {
this.files.push({
name: dir.directories[i],
icon: "mdi-folder",
type: "directory"
})
const dir = await this.$fm.getDir(this.path).catch(err => console.log(err));
if (dir.directories) {
for (const i in dir.directories) {
const name = dir.directories[i];
if (name == "" || name == "*/: No such file or directory") continue;
this.files.push({
name: name,
icon: "mdi-folder",
type: "directory"
})
}
}
for (const i in dir.files) {
this.files.push({
name: dir.files[i],
icon: "mdi-file",
type: "file"
})
if (dir.files) {
for (const i in dir.files) {
const name = dir.files[i]
if (name == "" || name == "*.*: No such file or directory") continue;
this.files.push({
name: name,
icon: "mdi-file",
type: "file"
})
}
}
this.loading = false;
},
back() {
this.path = this.path.slice(0, this.path.slice(0, -1).lastIndexOf('/')) + "/";
this.rebuild();
},
async enable() {
const app = this.apps[this.selected];
const output = await this.$execute(`adb shell pm enable ${app.name}`)
Expand Down
11 changes: 6 additions & 5 deletions src/renderer/plugins/fileManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,19 @@ For SCRCPY+ & ADB compatable devices
This code uses file browsing via the `ls` command
*/

import { Dir } from 'original-fs';

async function shell(cmd) {
return require('./modules/execute')(`adb shell "${cmd}"`);
}

module = {
async getDir(dir="/") {
const files = await shell(`cd ${dir} && ls -d *.*`);
const directories = await shell(`cd ${dir} && ls -d */`);
let files = await shell(`cd ${dir} && ls -d *.*`).catch(err => console.log(err));
let directories = await shell(`cd ${dir} && ls -d */`).catch(err => console.log(err));

if (files) files = files.replace(/\r/g,"").split('\n');
if (directories) directories = directories.replace(/\r/g,"").split('\n');

return { files: files.split('\n'), directories: directories.split('\n') }
return { files: files || [], directories: directories || [] }
}
}

Expand Down

0 comments on commit bbfba90

Please sign in to comment.