Skip to content

Commit

Permalink
fix(gui): Button to open data directory (#256)
Browse files Browse the repository at this point in the history
  • Loading branch information
binarybaron authored Jan 22, 2025
1 parent 9e27c65 commit c9d3536
Show file tree
Hide file tree
Showing 11 changed files with 187 additions and 24 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Docs: Added a dedicated page for makers.
- Docs: Improved the refund and punish page.
- ASB: Fixed an issue where the ASB would silently fail if the publication of the Monero refund transaction failed.
- GUI: Add a button to open the data directory for troubleshooting purposes.

## [1.0.0-rc.12] - 2025-01-14

Expand Down
144 changes: 136 additions & 8 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src-gui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"@tauri-apps/api": "^2.0.0",
"@tauri-apps/plugin-cli": "^2.0.0",
"@tauri-apps/plugin-clipboard-manager": "^2.0.0",
"@tauri-apps/plugin-opener": "^2.2.5",
"@tauri-apps/plugin-process": "^2.0.0",
"@tauri-apps/plugin-shell": "^2.0.0",
"@tauri-apps/plugin-store": "^2.0.0",
Expand Down
12 changes: 7 additions & 5 deletions src-gui/src/renderer/components/pages/help/DaemonControlBox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ import PromiseInvokeButton from "renderer/components/PromiseInvokeButton";
import { useAppSelector } from "store/hooks";
import InfoBox from "../../modal/swap/InfoBox";
import CliLogsBox from "../../other/RenderedCliLog";
import { initializeContext } from "renderer/rpc";
import { getDataDir, initializeContext } from "renderer/rpc";
import { relaunch } from "@tauri-apps/plugin-process";
import RotateLeftIcon from "@material-ui/icons/RotateLeft";
import { revealItemInDir } from "@tauri-apps/plugin-opener";

const useStyles = makeStyles((theme) => ({
actionsOuter: {
Expand Down Expand Up @@ -66,11 +67,12 @@ export default function DaemonControlBox() {
<PromiseInvokeButton
endIcon={<FolderOpenIcon />}
isIconButton
requiresContext={false}
size="small"
tooltipTitle="Open the data directory of the Swap Daemon in your file explorer"
onInvoke={() => {
// TODO: Implement this
throw new Error("Not implemented");
tooltipTitle="Open the data directory in your file explorer"
onInvoke={async () => {
const dataDir = await getDataDir();
await revealItemInDir(dataDir);
}}
/>
</Box>
Expand Down
8 changes: 8 additions & 0 deletions src-gui/src/renderer/rpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import {
CheckElectrumNodeResponse,
GetMoneroAddressesResponse,
TauriBackgroundRefundEvent,
GetDataDirArgs,
} from "models/tauriModel";
import {
contextStatusEventReceived,
Expand Down Expand Up @@ -277,3 +278,10 @@ export async function updateAllNodeStatuses() {
export async function getMoneroAddresses(): Promise<GetMoneroAddressesResponse> {
return await invokeNoArgs<GetMoneroAddressesResponse>("get_monero_addresses");
}

export async function getDataDir(): Promise<string> {
const testnet = isTestnet();
return await invoke<GetDataDirArgs, string>("get_data_dir", {
is_testnet: testnet,
});
}
7 changes: 7 additions & 0 deletions src-gui/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -792,6 +792,13 @@
dependencies:
"@tauri-apps/api" "^2.0.0"

"@tauri-apps/plugin-opener@^2.2.5":
version "2.2.5"
resolved "https://registry.yarnpkg.com/@tauri-apps/plugin-opener/-/plugin-opener-2.2.5.tgz#928b917d28d3e8b5bafb90f5f91fb0ed20c27fd4"
integrity sha512-hHsJ9RPWpZvZEPVFaL+d25gABMUMOf/A6ESXnvf/ii9guTukj58WXsAE/SOysXRIhej7kseRCxnOnIMpSCdUsQ==
dependencies:
"@tauri-apps/api" "^2.0.0"

"@tauri-apps/plugin-process@^2.0.0":
version "2.0.0"
resolved "https://registry.yarnpkg.com/@tauri-apps/plugin-process/-/plugin-process-2.0.0.tgz#002fd73f0d7b1ae2a5aacf442aa657e83dc2960b"
Expand Down
1 change: 1 addition & 0 deletions src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ swap = { path = "../swap", features = [ "tauri" ] }
sysinfo = "=0.32.1"
tauri = { version = "^2.0.0", features = [ "config-json5" ] }
tauri-plugin-clipboard-manager = "^2.0.0"
tauri-plugin-opener = "2.2.5"
tauri-plugin-process = "^2.0.0"
tauri-plugin-shell = "^2.0.0"
tauri-plugin-store = "^2.0.0"
Expand Down
3 changes: 2 additions & 1 deletion src-tauri/capabilities/default.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"process:default",
"cli:allow-cli-matches",
"updater:default",
"process:allow-restart"
"process:allow-restart",
"opener:default"
]
}
26 changes: 17 additions & 9 deletions src-tauri/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,9 @@ use std::result::Result;
use std::sync::Arc;
use swap::cli::{
api::{
request::{
BalanceArgs, BuyXmrArgs, CancelAndRefundArgs, CheckElectrumNodeArgs,
CheckElectrumNodeResponse, CheckMoneroNodeArgs, CheckMoneroNodeResponse,
ExportBitcoinWalletArgs, GetHistoryArgs, GetLogsArgs, GetMoneroAddressesArgs,
GetSwapInfoArgs, GetSwapInfosAllArgs, ListSellersArgs, MoneroRecoveryArgs,
ResumeSwapArgs, SuspendCurrentSwapArgs, WithdrawBtcArgs,
},
tauri_bindings::{TauriContextStatusEvent, TauriEmitter, TauriHandle, TauriSettings},
Context, ContextBuilder,
data, request::{
BalanceArgs, BuyXmrArgs, CancelAndRefundArgs, CheckElectrumNodeArgs, CheckElectrumNodeResponse, CheckMoneroNodeArgs, CheckMoneroNodeResponse, ExportBitcoinWalletArgs, GetDataDirArgs, GetHistoryArgs, GetLogsArgs, GetMoneroAddressesArgs, GetSwapInfoArgs, GetSwapInfosAllArgs, ListSellersArgs, MoneroRecoveryArgs, ResumeSwapArgs, SuspendCurrentSwapArgs, WithdrawBtcArgs
}, tauri_bindings::{TauriContextStatusEvent, TauriEmitter, TauriHandle, TauriSettings}, Context, ContextBuilder
},
command::{Bitcoin, Monero},
};
Expand Down Expand Up @@ -162,6 +156,7 @@ pub fn run() {
.plugin(tauri_plugin_store::Builder::new().build())
.plugin(tauri_plugin_clipboard_manager::init())
.plugin(tauri_plugin_shell::init())
.plugin(tauri_plugin_opener::init())
.invoke_handler(tauri::generate_handler![
get_balance,
get_monero_addresses,
Expand All @@ -181,6 +176,7 @@ pub fn run() {
check_monero_node,
check_electrum_node,
get_wallet_descriptor,
get_data_dir
])
.setup(setup)
.build(tauri::generate_context!())
Expand Down Expand Up @@ -221,6 +217,7 @@ tauri_command!(monero_recovery, MoneroRecoveryArgs);
tauri_command!(get_logs, GetLogsArgs);
tauri_command!(list_sellers, ListSellersArgs);
tauri_command!(cancel_and_refund, CancelAndRefundArgs);

// These commands require no arguments
tauri_command!(get_wallet_descriptor, ExportBitcoinWalletArgs, no_args);
tauri_command!(suspend_current_swap, SuspendCurrentSwapArgs, no_args);
Expand Down Expand Up @@ -252,6 +249,17 @@ async fn check_electrum_node(
args.request().await.to_string_result()
}

// Returns the data directory
// This is independent of the context to ensure the user can open the directory even if the context cannot
// be initialized (for troubleshooting purposes)
#[tauri::command]
async fn get_data_dir(
args: GetDataDirArgs,
_: tauri::State<'_, RwLock<State>>,
) -> Result<String, String> {
Ok(data::data_dir_from(None, args.is_testnet).to_string_result()?.to_string_lossy().to_string())
}

/// Tauri command to initialize the Context
#[tauri::command]
async fn initialize_context(
Expand Down
2 changes: 1 addition & 1 deletion swap/src/cli/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -577,7 +577,7 @@ async fn init_monero_wallet(
Ok((monero_wallet, monero_wallet_rpc_process))
}

mod data {
pub mod data {
use super::*;

pub fn data_dir_from(arg_dir: Option<PathBuf>, testnet: bool) -> Result<PathBuf> {
Expand Down
6 changes: 6 additions & 0 deletions swap/src/cli/api/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1308,6 +1308,12 @@ pub struct CheckMoneroNodeResponse {
pub available: bool,
}

#[typeshare]
#[derive(Deserialize, Serialize)]
pub struct GetDataDirArgs {
pub is_testnet: bool,
}

#[derive(Error, Debug)]
#[error("this is not one of the known monero networks")]
struct UnknownMoneroNetwork(String);
Expand Down

0 comments on commit c9d3536

Please sign in to comment.