-
-
Notifications
You must be signed in to change notification settings - Fork 4k
feat: Port path api to js #1006
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
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| --- | ||
| "tauri.js": minor | ||
| "tauri": minor | ||
| --- | ||
|
|
||
| Adds a path resolution API (e.g. getting the download directory or resolving a path to the home directory). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,274 @@ | ||
| import { promisified } from './tauri' | ||
| import { BaseDirectory } from './fs' | ||
|
|
||
| /** | ||
| * @name appDir | ||
| * @description Returns the path to the suggested directory for your app config files. | ||
| * @return {Promise<string>} | ||
| */ | ||
| async function appDir(): Promise<string> { | ||
| return await promisified<string>({ | ||
| cmd: 'resolvePath', | ||
| path: '.', | ||
| directory: BaseDirectory.App | ||
| }) | ||
| } | ||
|
|
||
| /** | ||
| * @name audioDir | ||
| * @description Returns the path to the user's audio directory. | ||
| * @return {Promise<string>} | ||
| */ | ||
| async function audioDir(): Promise<string> { | ||
| return await promisified<string>({ | ||
| cmd: 'resolvePath', | ||
| path: '.', | ||
| directory: BaseDirectory.Audio | ||
| }) | ||
| } | ||
|
|
||
| /** | ||
| * @name cacheDir | ||
| * @description Returns the path to the user's cache directory. | ||
| * @return {Promise<string>} | ||
| */ | ||
| async function cacheDir(): Promise<string> { | ||
| return await promisified<string>({ | ||
| cmd: 'resolvePath', | ||
| path: '.', | ||
| directory: BaseDirectory.Cache | ||
| }) | ||
| } | ||
|
|
||
| /** | ||
| * @name configDir | ||
| * @description Returns the path to the user's config directory. | ||
| * @return {Promise<string>} | ||
| */ | ||
| async function configDir(): Promise<string> { | ||
| return await promisified<string>({ | ||
| cmd: 'resolvePath', | ||
| path: '.', | ||
| directory: BaseDirectory.Config | ||
| }) | ||
| } | ||
|
|
||
| /** | ||
| * @name dataDir | ||
| * @description Returns the path to the user's data directory. | ||
| * @return {Promise<string>} | ||
| */ | ||
| async function dataDir(): Promise<string> { | ||
| return await promisified<string>({ | ||
| cmd: 'resolvePath', | ||
| path: '.', | ||
| directory: BaseDirectory.Data | ||
| }) | ||
| } | ||
|
|
||
| /** | ||
| * @name desktopDir | ||
| * @description Returns the path to the user's desktop directory. | ||
| * @return {Promise<string>} | ||
| */ | ||
| async function desktopDir(): Promise<string> { | ||
| return await promisified<string>({ | ||
| cmd: 'resolvePath', | ||
| path: '.', | ||
| directory: BaseDirectory.Desktop | ||
| }) | ||
| } | ||
|
|
||
| /** | ||
| * @name documentDir | ||
| * @description Returns the path to the user's document directory. | ||
| * @return {Promise<string>} | ||
| */ | ||
| async function documentDir(): Promise<string> { | ||
| return await promisified<string>({ | ||
| cmd: 'resolvePath', | ||
| path: '.', | ||
| directory: BaseDirectory.Document | ||
| }) | ||
| } | ||
|
|
||
| /** | ||
| * @name downloadDir | ||
| * @description Returns the path to the user's download directory. | ||
| * @return {Promise<string>} | ||
| */ | ||
| async function downloadDir(): Promise<string> { | ||
| return await promisified<string>({ | ||
| cmd: 'resolvePath', | ||
| path: '.', | ||
| directory: BaseDirectory.Download | ||
| }) | ||
| } | ||
|
|
||
| /** | ||
| * @name executableDir | ||
| * @description Returns the path to the user's executable directory. | ||
| * @return {Promise<string>} | ||
| */ | ||
| async function executableDir(): Promise<string> { | ||
| return await promisified<string>({ | ||
| cmd: 'resolvePath', | ||
| path: '.', | ||
| directory: BaseDirectory.Executable | ||
| }) | ||
| } | ||
|
|
||
| /** | ||
| * @name fontDir | ||
| * @description Returns the path to the user's font directory. | ||
| * @return {Promise<string>} | ||
| */ | ||
| async function fontDir(): Promise<string> { | ||
| return await promisified<string>({ | ||
| cmd: 'resolvePath', | ||
| path: '.', | ||
| directory: BaseDirectory.Font | ||
| }) | ||
| } | ||
|
|
||
| /** | ||
| * @name homeDir | ||
| * @description Returns the path to the user's home directory. | ||
| * @return {Promise<string>} | ||
| */ | ||
| async function homeDir(): Promise<string> { | ||
| return await promisified<string>({ | ||
| cmd: 'resolvePath', | ||
| path: '.', | ||
| directory: BaseDirectory.Home | ||
| }) | ||
| } | ||
|
|
||
| /** | ||
| * @name localDataDir | ||
| * @description Returns the path to the user's local data directory. | ||
| * @return {Promise<string>} | ||
| */ | ||
| async function localDataDir(): Promise<string> { | ||
| return await promisified<string>({ | ||
| cmd: 'resolvePath', | ||
| path: '.', | ||
| directory: BaseDirectory.LocalData | ||
| }) | ||
| } | ||
|
|
||
| /** | ||
| * @name pictureDir | ||
| * @description Returns the path to the user's picture directory. | ||
| * @return {Promise<string>} | ||
| */ | ||
| async function pictureDir(): Promise<string> { | ||
| return await promisified<string>({ | ||
| cmd: 'resolvePath', | ||
| path: '.', | ||
| directory: BaseDirectory.Picture | ||
| }) | ||
| } | ||
|
|
||
| /** | ||
| * @name publicDir | ||
| * @description Returns the path to the user's public directory. | ||
| * @return {Promise<string>} | ||
| */ | ||
| async function publicDir(): Promise<string> { | ||
| return await promisified<string>({ | ||
| cmd: 'resolvePath', | ||
| path: '.', | ||
| directory: BaseDirectory.Public | ||
| }) | ||
| } | ||
|
|
||
| /** | ||
| * @name resourceDir | ||
| * @description Returns the path to the user's resource directory. | ||
| * @return {Promise<string>} | ||
| */ | ||
| async function resourceDir(): Promise<string> { | ||
| return await promisified<string>({ | ||
| cmd: 'resolvePath', | ||
| path: '.', | ||
| directory: BaseDirectory.Resource | ||
| }) | ||
| } | ||
|
|
||
| /** | ||
| * @name runtimeDir | ||
| * @descriptionReturns Returns the path to the user's runtime directory. | ||
| * @return {Promise<string>} | ||
| */ | ||
| async function runtimeDir(): Promise<string> { | ||
| return await promisified<string>({ | ||
| cmd: 'resolvePath', | ||
| path: '.', | ||
| directory: BaseDirectory.Runtime | ||
| }) | ||
| } | ||
|
|
||
| /** | ||
| * @name templateDir | ||
| * @descriptionReturns Returns the path to the user's template directory. | ||
| * @return {Promise<string>} | ||
| */ | ||
| async function templateDir(): Promise<string> { | ||
| return await promisified<string>({ | ||
| cmd: 'resolvePath', | ||
| path: '.', | ||
| directory: BaseDirectory.Template | ||
| }) | ||
| } | ||
|
|
||
| /** | ||
| * @name videoDir | ||
| * @descriptionReturns Returns the path to the user's video dir. | ||
| * @return {Promise<string>} | ||
| */ | ||
| async function videoDir(): Promise<string> { | ||
| return await promisified<string>({ | ||
| cmd: 'resolvePath', | ||
| path: '.', | ||
| directory: BaseDirectory.Video | ||
| }) | ||
| } | ||
|
|
||
| /** | ||
| * @name resolvePath | ||
| * @descriptionReturns Resolves the path with the optional base directory. | ||
| * @return {Promise<string>} | ||
| */ | ||
| async function resolvePath( | ||
| path: string, | ||
| directory: BaseDirectory | ||
| ): Promise<string> { | ||
| return await promisified<string>({ | ||
| cmd: 'resolvePath', | ||
| path, | ||
| directory | ||
| }) | ||
| } | ||
|
|
||
| export { | ||
| appDir, | ||
| audioDir, | ||
| cacheDir, | ||
| configDir, | ||
| dataDir, | ||
| desktopDir, | ||
| documentDir, | ||
| downloadDir, | ||
| executableDir, | ||
| fontDir, | ||
| homeDir, | ||
| localDataDir, | ||
| pictureDir, | ||
| publicDir, | ||
| resourceDir, | ||
| runtimeDir, | ||
| templateDir, | ||
| videoDir, | ||
| resolvePath | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| #![cfg(path_api)] | ||
| use tauri_api::path; | ||
| use tauri_api::path::BaseDirectory; | ||
| use webview_official::Webview; | ||
|
|
||
| pub fn resolve_path( | ||
| webview: &mut Webview<'_>, | ||
| path: String, | ||
| directory: Option<BaseDirectory>, | ||
| callback: String, | ||
| error: String, | ||
| ) { | ||
| crate::execute_promise( | ||
| webview, | ||
| move || path::resolve_path(path, directory), | ||
| callback, | ||
| error, | ||
| ) | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@lucasfernog this will add a "dot" to the end of the path, I believe an empty string is better.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One more thing, if a base directory doesn't exist, the user will get an error like this
Path Error:unable to determine base dir path. In my opinion this will confuse the user as he doesn't know the underlying api is just resolving a path using a base dir, instead it would be better to just return null like tauri's Path api in rust.