tauri-docs icon indicating copy to clipboard operation
tauri-docs copied to clipboard

[request] Sidecar docs – example does not work in rust.

Open gtokman opened this issue 10 months ago • 4 comments

Question you want answered

Update the side car docs with a recent example.

Where did you look for an answer?

Image

Page URL

https://tauri.app/learn/sidecar-nodejs/

Additional context

No response

Are you willing to work on this yourself?

  • [ ] I want to work on this myself

gtokman avatar Jan 27 '25 14:01 gtokman

Also it would help to elaborate how where to add this:

import { execSync } from 'child_process';
import fs from 'fs';

const ext = process.platform === 'win32' ? '.exe' : '';

const rustInfo = execSync('rustc -vV');
const targetTriple = /host: (\S+)/g.exec(rustInfo)[1];
if (!targetTriple) {
  console.error('Failed to determine platform target triple');
}
fs.renameSync(
  `app${ext}`,
  `../src-tauri/binaries/app-${targetTriple}${ext}`
);

I'm assuming it's the package that I created.

gtokman avatar Jan 27 '25 14:01 gtokman

Trying the JS example, I get this error.

const message = "Tauri";

const command = Command.sidecar("binaries/app", ["ping", message]);
const output = await command.execute();
const response = output.stdout;

console.log(response);

Image

gtokman avatar Jan 27 '25 15:01 gtokman

no method named shell found for struct AppHandle

The example is omitting the imports (either by accident or intentionally). The Quick Fix suggestions in your screenshot should have worked. It should add use tauri_plugin_shell::ShellExt;

Also it would help to elaborate how where to add this:

It's a standalone javascript file (name doesn't matter), that you'd execute with node thatfile.js

Trying the JS example, I get this error.

Like the note at the top of the page says, the guide assumes you followed the shell guide. Here you're missing the rust changes https://tauri.app/plugin/shell/#setup (manual tab)


Not disagreeing btw, the guide needs improvements.

FabianLars avatar Jan 27 '25 18:01 FabianLars

thanks @FabianLars, I got it working. Let me see if I can make a PR.

gtokman avatar Jan 27 '25 19:01 gtokman