From bbfba905d5fd803b071f5454d0242d959910be0a Mon Sep 17 00:00:00 2001 From: Kenny <27463495+Frontesque@users.noreply.github.com> Date: Sun, 3 Jul 2022 14:47:55 -0400 Subject: [PATCH] fix: :bug: Fix file manager on new android versions & show no files notice --- src/renderer/pages/tools/files.vue | 73 ++++++++++++++++++----------- src/renderer/plugins/fileManager.js | 11 +++-- 2 files changed, 52 insertions(+), 32 deletions(-) diff --git a/src/renderer/pages/tools/files.vue b/src/renderer/pages/tools/files.vue index 98e2272..89701c0 100644 --- a/src/renderer/pages/tools/files.vue +++ b/src/renderer/pages/tools/files.vue @@ -20,7 +20,13 @@ - + +
+ No files or directories +
+ + + @@ -39,7 +45,7 @@ - + @@ -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, }, { @@ -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" }, ] } }, @@ -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; @@ -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}`) diff --git a/src/renderer/plugins/fileManager.js b/src/renderer/plugins/fileManager.js index d20d769..706be6d 100644 --- a/src/renderer/plugins/fileManager.js +++ b/src/renderer/plugins/fileManager.js @@ -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 || [] } } }