aboutsummaryrefslogtreecommitdiffstats
path: root/desktop/assistant/Assistant.qml
diff options
context:
space:
mode:
Diffstat (limited to 'desktop/assistant/Assistant.qml')
-rw-r--r--desktop/assistant/Assistant.qml32
1 files changed, 31 insertions, 1 deletions
diff --git a/desktop/assistant/Assistant.qml b/desktop/assistant/Assistant.qml
index 977b4dd..0139ef9 100644
--- a/desktop/assistant/Assistant.qml
+++ b/desktop/assistant/Assistant.qml
@@ -105,10 +105,40 @@ Scope {
root.staged = files;
root.historyOpen = root.pickerOpen = false;
root.open = true;
+ root.refine();
}
function stage(path) {
- if (!root.staged.some(f => f.path === path)) root.staged = root.staged.concat([Files.file(path)]);
+ if (root.staged.some(f => f.path === path)) return;
+ root.staged = root.staged.concat([Files.file(path)]);
+ root.refine();
+ }
+
+ // A file whose name says nothing (a script with no suffix) is "other"
+ // until file(1) has read it. One run for all of them; the daemon makes
+ // its own call on the content when the question is sent.
+ function refine() {
+ const unknown = root.staged.filter(f => f.kind === "other").map(f => f.path);
+ if (!unknown.length) return;
+ sniff.paths = unknown;
+ sniff.running = false; // a running Process ignores running = true
+ sniff.running = true;
+ }
+
+ Process {
+ id: sniff
+ property var paths: []
+ command: ["file", "-b", "--mime-type", "--"].concat(paths)
+ stdout: StdioCollector {
+ onStreamFinished: {
+ const mimes = text.trim().split("\n");
+ root.staged = root.staged.map(f => {
+ const i = sniff.paths.indexOf(f.path);
+ return i < 0 || f.kind !== "other" ? f
+ : Object.assign({}, f, { kind: Files.fromMime(mimes[i] ?? "") });
+ });
+ }
+ }
}
function unstage(i) {
const s = root.staged.slice();