Skip to content

Commit

Permalink
feat(tauri-app): restart kubo on reconnect | fix: concurrency issue f…
Browse files Browse the repository at this point in the history
…ixed on start_ipfs
  • Loading branch information
Andrejs authored and Andrejs committed Nov 23, 2024
1 parent d39f95c commit b2be0e7
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 8 deletions.
7 changes: 6 additions & 1 deletion src-tauri/src/ipfs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,14 +80,19 @@ pub fn start_ipfs() -> Result<(), IpfsError> {
.map_err(|e| IpfsError::Other(e.to_string()))?;

if is_running.status.success() {
return Err(IpfsError::AlreadyRunning);
println!("IPFS is already running.");
return Ok(()); // If it's already running, don't try to start it again
}

// Start the IPFS daemon
Command::new(&ipfs_binary)
.arg("daemon")
.spawn()
.map_err(|e| IpfsError::Other(e.to_string()))?;
println!("IPFS daemon started");

// Give IPFS a moment to start up properly
std::thread::sleep(std::time::Duration::from_secs(2));

// Configure IPFS to allow all origins
let config_output1 = Command::new(&ipfs_binary)
Expand Down
2 changes: 1 addition & 1 deletion src/components/btnGrd/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const playAudioClick = () => {
// };

export interface Props extends Partial<HTMLButtonElement> {
disabled: boolean;
disabled?: boolean;
text?: string | JSX.Element;
img?: $TsFixMe;
pending?: boolean;
Expand Down
24 changes: 18 additions & 6 deletions src/features/ipfs/ipfsSettings/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { AdviserColors } from 'src/features/adviser/Adviser/Adviser';
import { useAdviser } from 'src/features/adviser/context';
import { getIpfsOpts } from 'src/services/ipfs/config';
import { IPFSNodes } from 'src/services/ipfs/types';
import { invoke } from '@tauri-apps/api/tauri';
import BtnPassport from '../../../containers/portal/pasport/btnPasport';
import Drive from '../Drive';
import ErrorIpfsSettings from './ErrorIpfsSettings';
Expand Down Expand Up @@ -46,7 +47,7 @@ function IpfsSettings() {

useEffect(() => {
let text;
let status: AdviserColors = undefined;
let status: AdviserColors;
if (!isIpfsInitialized) {
text = 'trying to connect to ipfs...';
status = 'yellow';
Expand Down Expand Up @@ -75,11 +76,22 @@ function IpfsSettings() {
updateUserGatewayUrl(valueInputGateway);
}, [valueInputGateway]);

const onClickReConnect = () => {
ipfsApi
?.stop()
.then(() => ipfsApi?.start(getIpfsOpts()))
.then();
const onClickReConnect = async () => {
if (process.env.IS_TAURI) {
try {
console.log('Restarting IPFS');

await invoke('stop_ipfs');
await invoke('start_ipfs');

console.log('IPFS restarted');
} catch (error) {
console.error('Error restarting IPFS', error);
}
}

await ipfsApi?.stop().catch(console.error);
await ipfsApi?.start(getIpfsOpts()).catch(console.error);
};

const stateProps = {
Expand Down

0 comments on commit b2be0e7

Please sign in to comment.