Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature Request: use default directory if not specified #68

Open
namespaceYcZ opened this issue May 6, 2024 · 4 comments
Open

Feature Request: use default directory if not specified #68

namespaceYcZ opened this issue May 6, 2024 · 4 comments
Labels

Comments

@namespaceYcZ
Copy link

namespaceYcZ commented May 6, 2024

Now ATAC (version 0.15.1) must be given a working directory on startup.
image

IMHO, a tui application can use the default directory specified by the OS, i.e:

OS config directory cache directory
Linux /home/alice/.config/barapp /home/alice/.cache/barapp
Windows C:\Users\Alice\AppData\Roaming\Foo Corp\Bar App\config C:\Users\Alice\AppData\Local\Foo Corp\Bar App\cache
MacOS /Users/Alice/Library/Application Support/com.Foo-Corp.Bar-App /Users/Alice/Library/Caches/com.Foo-Corp.Bar-App

(Suppose the user name is Alice, the organization name is Foo Corp and the application name is Bar App).

All this can be easily handled by the directory crate:

[dependencies]
directories = "5"
// these are just examples, there must be some other much more better options
// and if you want the `ORGANIZATION` be present on Linux, some thing like `#[cfg(target_os = "linux")]` can be used
pub const APP_NAME: &str = "ATAC";
pub const QUALIFIER: &str = "fr";
pub const ORGANIZATION: &str = "Julien";

let project_dir = directories::ProjectDirs::from(QUALIFIER, ORGANIZATION, APP_NAME).unwrap();
let config_dir = project_dir.config_dir();
let cache_dir = project_dir.cache_dir();
let mut log_dir = cache_dir.to_owned();
log_dir.push("logs");
@Julien-cpsn
Copy link
Owner

Julien-cpsn commented May 6, 2024

Hello @namespaceYcZ

Yes this a thing that is planned for later, a dedicated directory inside the system would be great. It is not implemeted yet because I don't know how make it cross-platform. But your solution seems good to me, I'll look into it further.

Have you tried using the ATAC_MAIN_DIR env variable before the features comes out?

Have a great day

PS: do you have more knowledge on how to implement those things? I have some questions

@namespaceYcZ
Copy link
Author

Hello @namespaceYcZ

Yes this a thing that is planned for later, a dedicated directory inside the system would be great. It is not implemeted yet because I don't know how make it cross-platform. But your solution seems good to me, I'll look into it further.

Have you tried using the ATAC_MAIN_DIR env variable before the features comes out?

Have a great day

PS: do you have more knowledge on how to implement those things? I have some questions

I tried. Both these two ways work fine for me:
image

Thank you for your nice work! I have been longing for a tui Postman-like application for a long time.

What kind of knowledge do you need? I'm very glad to help but I lack experience and necessary knowledge.
I saw some links on the document page of the directories crate which might help you.

@Julien-cpsn
Copy link
Owner

What kind of knowledge do you need? I'm very glad to help but I lack experience and necessary knowledge. I saw some links on the document page of the directories crate which might help you.

I do not understand how the directory gets created, does I need to always try to create the directory when using the app ? Or does it needs something specific when installing?

Will it work with the ATAC_MAIN_DIR variable or do I have to change the way it works?

Thanks in advance

@namespaceYcZ
Copy link
Author

What kind of knowledge do you need? I'm very glad to help but I lack experience and necessary knowledge. I saw some links on the document page of the directories crate which might help you.

I do not understand how the directory gets created, does I need to always try to create the directory when using the app ? Or does it needs something specific when installing?

Will it work with the ATAC_MAIN_DIR variable or do I have to change the way it works?

Thanks in advance

image
image

I think the directories crate doesn't automatically create the project directory for us. So I suggest that ATAC create it if the directory argument was not provided, the ATAC_MAIN_DIR env variable was not provided and the project directory was not found.

I draw a flow chart to make it clear:
未命名文件

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants