Skip to content

Instantly share code, notes, and snippets.

@andyholmes
Created October 12, 2018 17:08
Show Gist options
  • Save andyholmes/90c391f4bfd611cd916651ec590f5897 to your computer and use it in GitHub Desktop.
Save andyholmes/90c391f4bfd611cd916651ec590f5897 to your computer and use it in GitHub Desktop.
'use strict';
const Gio = imports.gi.Gio;
const GLib = imports.gi.GLib;
async function mount() {
try {
// This comes from a 'kdeconnect.sftp' packet
let file = Gio.File.new_for_uri('sftp://192.168.1.68:1748//storage/emulated/0');
let mount = new Gio.MountOperation({
// This is always 'kdeconnect'
username: 'kdeconnect',
// This comes from a 'kdeconnect.sftp' packet
password: '0DLBswxkjjY4bTxpNUvNXGB1X3c9',
// Save password for session and accept new connections
password_save: Gio.PasswordSave.FOR_SESSION,
choice: 0
});
// We already know the host, so just accept
mount.connect('ask-question', (op, message, choices) => {
op.reply(Gio.MountOperationResult.HANDLED);
});
// We set the password, so just accept
mount.connect('ask-password', (op, message, user, domain, flags) => {
op.reply(Gio.MountOperationResult.HANDLED);
});
// This is the actual call to mount the device
await new Promise((resolve, reject) => {
file.mount_enclosing_volume(0, mount, null, (file, res) => {
try {
file.mount_enclosing_volume_finish(res);
} catch (e) {
logError(e);
}
});
});
} catch (e) {
logError(e);
}
}
mount();
let loop = GLib.MainLoop.new(null, false);
loop.run();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment