From 55469631601824677b1f72ebc583424de8cf2dd4 Mon Sep 17 00:00:00 2001 From: Lily Anne Hall Date: Thu, 26 Dec 2024 13:51:26 -0800 Subject: [PATCH] finish about info gui - start on fuse integration --- bin/fuse.js | 32 ++++++++++++++++++++++++-------- bin/tray.js | 47 ++++++++++++++++++++++++++++++++++++++++++----- 2 files changed, 66 insertions(+), 13 deletions(-) diff --git a/bin/fuse.js b/bin/fuse.js index 49d6385..25c8481 100644 --- a/bin/fuse.js +++ b/bin/fuse.js @@ -1,6 +1,8 @@ 'use strict'; const Fuse = require('fuse-native'); +const { execSync } = require('node:child_process'); +const path = require('node:path'); function _init(mnt) { return new Promise(async (resolve, reject) => { @@ -10,8 +12,8 @@ function _init(mnt) { return cb(Fuse.ENOENT) }, getattr: function (path, cb) { - if (path === '/') return cb(null, stat({ mode: 'dir', size: 4096 })) - if (path === '/test') return cb(null, stat({ mode: 'file', size: 11 })) + if (path === '/') return cb(null, { mode: 'dir', size: 4096 }) + if (path === '/test') return cb(null, { mode: 'file', size: 11 }) return cb(Fuse.ENOENT) }, open: function (path, flags, cb) { @@ -28,16 +30,30 @@ function _init(mnt) { } }; - // TODO Fuse.isConfigured? pkexec - - const fuse = new Fuse(mnt, ops, { debug: true }); + const fuseconfigpath = path.join(__dirname, '../node_modules/.bin/fuse-native'); - fuse.mount(function(err) { + Fuse.isConfigured((err, isConfigured) => { if (err) { return reject(err); } - resolve(); - }) + + if (!isConfigured) { + try { + execSync(`pkexec ${fuseconfigpath} configure`); + } catch (err) { + return reject(err); + } + } + + const fuse = new Fuse(mnt, ops, { debug: true }); + + fuse.mount(function(err) { + if (err) { + return reject(err); + } + resolve(); + }); + }) }); } diff --git a/bin/tray.js b/bin/tray.js index ecc4258..25a275b 100644 --- a/bin/tray.js +++ b/bin/tray.js @@ -5,6 +5,8 @@ const { spawn, fork } = require('node:child_process'); const path = require('node:path'); const Dialog = require('../lib/zenity'); const fs = require('node:fs'); +const fuse = require('./fuse.js'); +const mkdirp = require('mkdirp'); const shoesTitle = '🝰 dusk / SHOES ' const duskTitle = '🝰 dusk' @@ -78,7 +80,7 @@ function _init(rpc, program, config, exitGracefully) { items: [ NET_STATUS_CONNECTING.item, { - title: '🔍 Show network info', + title: 'ℹ️ Show about info', enabled: true, checked: false }, @@ -124,13 +126,14 @@ function _init(rpc, program, config, exitGracefully) { case 0: // Status indicator break; case 1: // Show network info - showNetworkInfo(action); + showAboutInfo(action); break; case 2: // Link peer device manageDeviceLinks(action); break; case 3: // Mount virtual folders toggleMountVirtualFolders(action); + break; case 4: // Encryption tools dialogs encryptionUtilities(action); break; @@ -151,8 +154,31 @@ function _init(rpc, program, config, exitGracefully) { } }); - function showNetworkInfo(action) { + function showAboutInfo(action) { + rpc.invoke('getinfo', [], (err, info) => { + if (err) { + Dialog.info(err, 'Sorry', 'error'); + } else { + _showInfo(info); + } + }); + + function _showInfo(info) { + const dialogOptions = { + width: 300, + }; + const dialogTitle = `${duskTitle}`; + const version = `${info.versions.software}:${info.versions.protocol}` + + const dialogText = `Version: ${version} +Peers: ${info.peers.length} + +anti-©opyright, 2024 tactical chihuahua +licensed under the agpl 3 +`; + Dialog.info(dialogText, dialogTitle, 'info', dialogOptions); + } } function manageDeviceLinks(actions) { @@ -181,8 +207,14 @@ function _init(rpc, program, config, exitGracefully) { } } - function toggleMountVirtualFolders(action) { - + async function toggleMountVirtualFolders(action) { + try { + mkdirp.sync('/tmp/dusk.vfs'); + await fuse('/tmp/dusk.vfs'); + } catch (e) { + return Dialog.info(e, 'Sorry', 'error'); + } + Dialog.notify('Virtual filesystem mounted.\n/tmp/dusk.vfs'); } function encryptionUtilities(action) { @@ -273,6 +305,11 @@ function _init(rpc, program, config, exitGracefully) { printColumn: 'ALL' } ); + + if (!newConfig) { + return; + } + let writeOut = ''; let splitConfig = newConfig.split('|'); if (splitConfig.length >= 2) {