#Tauri api to get the "Program Files" path?

52 messages ยท Page 1 of 1 (latest)

reef void
#

I looked all over the path module, I can most likely just resolve it, but I would prefer to use some tauri api to find the "Program Files" path in windows. Not sure what is the equiv in other systems, but there are rough translations I guess.. Or maybe it's windows only ๐Ÿคทโ€โ™‚๏ธ

charred echo
#

Why do you want that folder? Because in 99.9% of cases when people want that folder it's because they're doing something wrong

reef void
# charred echo Why do you want that folder? Because in 99.9% of cases when people want that fol...

Hahahah thats fair! I work at a startup where we need to mimic some behavior of a specific microsoft product. After reverse engineering that product, we found that to do a certain thing (which is also the main feature, so theres no "should we" when mirroring the behavior) that product reaches its grubby hands into the Program Files to execute a specific exe if it exists. This odd and invasive behavior happens in a few other cases. Like reaching into the AppData Local of a different application

#

so blame the man himself, I'm just doing what they do

charred echo
#

Well getting the path to C:\Program Files is easy. I just did it right there x)
You can just hard code that path because that folder should always be in that place. So something like let program_dir = Path::from("C:/Program Files")

#

There may be 12 people out there with a computer that doesn't have it on C:. Don't worry about them

reef void
#

Hmmm I had a feeling that would be the case

#

the path is not hard to "guess", I was worried about Program Files vs Program Files (x86)
or whatever the number should be

#

also our users might be some of those 12 since they might run it from a hosted machine with exotic mounting (thanks azure)

#

But that'll be their problem, I guess

charred echo
#

Like it's not just a matter of having a weird drives setup, it's a matter of changing fairly intimite stuff about the system to make it accept anything other than C

#

Not sure what is the equiv in other systems
And yes, other systems have similar paths you can get, like /Applications on Mac or /usr/bin on Linux, but it's not quite as simple on those systems to say it's a 1-1 mapping with Program Files

charred echo
#

They can have apps elsewhere for other reasons though

#

Like in AppData

reef void
#

Thanks for the info, it gives me much more confidence "hard-coding" the path in

#

Much appreciated

#

@charred echo
oh, I am using it on the ts side. how can I resolve C:? just like that?

resolve("C:", "Program Files", "Password Manager", "raw-passwords.csv")

?

charred echo
reef void
#

Legitimate, it does fit better on the rust side.

charred echo
#

I am one of the mad lads that advocate the idea that when you make a Tauri app you should develop it as if it had been a Rust CLI application, you're just using the provided webview for input/output, all logic actually resides in the Rust end ๐Ÿ™‚

reef void
#

Thats how it started, but I was too slow to justify it...
Messing with channels, async, arc, mutex, moving, cloning, and all of that with errors that are still hard for me to read and in a style I'm still not acustomed to

#

Everything I did in 3-4 weeks in rust I ported in a single day to the ts side. (I still have bindings to the rust layer, but lets say that the "business logic" is in typescript)

#

thankfully I have effect-ts

#

This is on me, not on rust.
Though I would say that rust is more C++ than C#

#

if you get what I mean

charred echo
#

I would say Rust is more TS than anything honestly after having used it a while ๐Ÿ˜…

#

Or at least I recognize myself most in TS when I use it

#

Which is probably also part of why I like the Rust first approach, because in most cases I feel like I'm developing mostly the same code as I would in TS, just that if I do it in TS the result is worse

reef void
#

ts would never make me wrangle pointers and moving references ๐Ÿ‘น

#

yes yes multi thread concurrency and so on. It makes total sense

#

but it's more ritual than anything

charred echo
#

Rust doesn't make you do that either, well, mostly, once you figure out the ownership system

reef void
#

I did get the hang of it as time went on, but things like spinning a server on demand that dies in 90s or when it gets a specific request or manually or if someone tries to spin a new one was a nightmare

#

Since the server can only shut down by resolving some callback value, the obvious solution is a channel. I'll skip to the end to not bore you too much, I needed an Arc<Mutex<Option<Sender>>> to be able to move it around the place safely

#

Don't get me wrong, it makes perfect sense, but it was so tedious to get there ๐Ÿ˜ข

charred echo
#

Yea it's totally fair that stuff like that is needed here and there. In most cases in Tauri you can skip the arc if you instead store it in a State, but yea. It takes a while for all of these sort of things to feel natural for sure

reef void
reef void
#

Yes, what should I invoke?

charred echo
#
import { Command } from '@tauri-apps/api/shell';
const command = new Command('node');
command.on('close', data => {
  console.log(`command finished with code ${data.code} and signal ${data.signal}`)
});
command.on('error', error => console.error(`command error: "${error}"`));
command.stdout.on('data', line => console.log(`command stdout: "${line}"`));
command.stderr.on('data', line => console.log(`command stderr: "${line}"`));

const child = await command.spawn();
console.log('pid:', child.pid);
reef void
#

Command("C:/Program Files/Bank App/transferFunds.exe", ["to", "me"])?

charred echo
#

Yep

reef void
#

Cool and neat

#

can I use $LOCALDATA aliases?

charred echo
#
import { resolve, appDataDir } from '@tauri-apps/api/path';
const appDataDirPath = await appDataDir();
const path = await resolve(appDataDirPath, '..', 'users', 'tauri', 'avatar.png');

You can use stuff like this when you resolve the path
I don't believe you can use it in the command
You should be able to use OS level variables though

reef void
#

since commands are required to be specified by a scope

#

also not clear if I can use forward slashes instead of backslashes when defining the scopes, though I just persume that it's fine

charred echo
#

Test it and see. Should be fine