path.ts 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  1. import { promisified } from './tauri'
  2. import { BaseDirectory } from './fs'
  3. /**
  4. * @name appDir
  5. * @description Returns the path to the suggested directory for your app config files.
  6. * @return {Promise<string>}
  7. */
  8. async function appDir(): Promise<string> {
  9. return await promisified<string>({
  10. cmd: 'resolvePath',
  11. path: '',
  12. directory: BaseDirectory.App
  13. })
  14. }
  15. /**
  16. * @name audioDir
  17. * @description Returns the path to the user's audio directory.
  18. * @return {Promise<string>}
  19. */
  20. async function audioDir(): Promise<string> {
  21. return await promisified<string>({
  22. cmd: 'resolvePath',
  23. path: '',
  24. directory: BaseDirectory.Audio
  25. })
  26. }
  27. /**
  28. * @name cacheDir
  29. * @description Returns the path to the user's cache directory.
  30. * @return {Promise<string>}
  31. */
  32. async function cacheDir(): Promise<string> {
  33. return await promisified<string>({
  34. cmd: 'resolvePath',
  35. path: '',
  36. directory: BaseDirectory.Cache
  37. })
  38. }
  39. /**
  40. * @name configDir
  41. * @description Returns the path to the user's config directory.
  42. * @return {Promise<string>}
  43. */
  44. async function configDir(): Promise<string> {
  45. return await promisified<string>({
  46. cmd: 'resolvePath',
  47. path: '',
  48. directory: BaseDirectory.Config
  49. })
  50. }
  51. /**
  52. * @name dataDir
  53. * @description Returns the path to the user's data directory.
  54. * @return {Promise<string>}
  55. */
  56. async function dataDir(): Promise<string> {
  57. return await promisified<string>({
  58. cmd: 'resolvePath',
  59. path: '',
  60. directory: BaseDirectory.Data
  61. })
  62. }
  63. /**
  64. * @name desktopDir
  65. * @description Returns the path to the user's desktop directory.
  66. * @return {Promise<string>}
  67. */
  68. async function desktopDir(): Promise<string> {
  69. return await promisified<string>({
  70. cmd: 'resolvePath',
  71. path: '',
  72. directory: BaseDirectory.Desktop
  73. })
  74. }
  75. /**
  76. * @name documentDir
  77. * @description Returns the path to the user's document directory.
  78. * @return {Promise<string>}
  79. */
  80. async function documentDir(): Promise<string> {
  81. return await promisified<string>({
  82. cmd: 'resolvePath',
  83. path: '',
  84. directory: BaseDirectory.Document
  85. })
  86. }
  87. /**
  88. * @name downloadDir
  89. * @description Returns the path to the user's download directory.
  90. * @return {Promise<string>}
  91. */
  92. async function downloadDir(): Promise<string> {
  93. return await promisified<string>({
  94. cmd: 'resolvePath',
  95. path: '',
  96. directory: BaseDirectory.Download
  97. })
  98. }
  99. /**
  100. * @name executableDir
  101. * @description Returns the path to the user's executable directory.
  102. * @return {Promise<string>}
  103. */
  104. async function executableDir(): Promise<string> {
  105. return await promisified<string>({
  106. cmd: 'resolvePath',
  107. path: '',
  108. directory: BaseDirectory.Executable
  109. })
  110. }
  111. /**
  112. * @name fontDir
  113. * @description Returns the path to the user's font directory.
  114. * @return {Promise<string>}
  115. */
  116. async function fontDir(): Promise<string> {
  117. return await promisified<string>({
  118. cmd: 'resolvePath',
  119. path: '',
  120. directory: BaseDirectory.Font
  121. })
  122. }
  123. /**
  124. * @name homeDir
  125. * @description Returns the path to the user's home directory.
  126. * @return {Promise<string>}
  127. */
  128. async function homeDir(): Promise<string> {
  129. return await promisified<string>({
  130. cmd: 'resolvePath',
  131. path: '',
  132. directory: BaseDirectory.Home
  133. })
  134. }
  135. /**
  136. * @name localDataDir
  137. * @description Returns the path to the user's local data directory.
  138. * @return {Promise<string>}
  139. */
  140. async function localDataDir(): Promise<string> {
  141. return await promisified<string>({
  142. cmd: 'resolvePath',
  143. path: '',
  144. directory: BaseDirectory.LocalData
  145. })
  146. }
  147. /**
  148. * @name pictureDir
  149. * @description Returns the path to the user's picture directory.
  150. * @return {Promise<string>}
  151. */
  152. async function pictureDir(): Promise<string> {
  153. return await promisified<string>({
  154. cmd: 'resolvePath',
  155. path: '',
  156. directory: BaseDirectory.Picture
  157. })
  158. }
  159. /**
  160. * @name publicDir
  161. * @description Returns the path to the user's public directory.
  162. * @return {Promise<string>}
  163. */
  164. async function publicDir(): Promise<string> {
  165. return await promisified<string>({
  166. cmd: 'resolvePath',
  167. path: '',
  168. directory: BaseDirectory.Public
  169. })
  170. }
  171. /**
  172. * @name resourceDir
  173. * @description Returns the path to the user's resource directory.
  174. * @return {Promise<string>}
  175. */
  176. async function resourceDir(): Promise<string> {
  177. return await promisified<string>({
  178. cmd: 'resolvePath',
  179. path: '',
  180. directory: BaseDirectory.Resource
  181. })
  182. }
  183. /**
  184. * @name runtimeDir
  185. * @descriptionReturns Returns the path to the user's runtime directory.
  186. * @return {Promise<string>}
  187. */
  188. async function runtimeDir(): Promise<string> {
  189. return await promisified<string>({
  190. cmd: 'resolvePath',
  191. path: '',
  192. directory: BaseDirectory.Runtime
  193. })
  194. }
  195. /**
  196. * @name templateDir
  197. * @descriptionReturns Returns the path to the user's template directory.
  198. * @return {Promise<string>}
  199. */
  200. async function templateDir(): Promise<string> {
  201. return await promisified<string>({
  202. cmd: 'resolvePath',
  203. path: '',
  204. directory: BaseDirectory.Template
  205. })
  206. }
  207. /**
  208. * @name videoDir
  209. * @descriptionReturns Returns the path to the user's video dir.
  210. * @return {Promise<string>}
  211. */
  212. async function videoDir(): Promise<string> {
  213. return await promisified<string>({
  214. cmd: 'resolvePath',
  215. path: '',
  216. directory: BaseDirectory.Video
  217. })
  218. }
  219. /**
  220. * @name resolvePath
  221. * @descriptionReturns Resolves the path with the optional base directory.
  222. * @return {Promise<string>}
  223. */
  224. async function resolvePath(
  225. path: string,
  226. directory: BaseDirectory
  227. ): Promise<string> {
  228. return await promisified<string>({
  229. cmd: 'resolvePath',
  230. path,
  231. directory
  232. })
  233. }
  234. export {
  235. appDir,
  236. audioDir,
  237. cacheDir,
  238. configDir,
  239. dataDir,
  240. desktopDir,
  241. documentDir,
  242. downloadDir,
  243. executableDir,
  244. fontDir,
  245. homeDir,
  246. localDataDir,
  247. pictureDir,
  248. publicDir,
  249. resourceDir,
  250. runtimeDir,
  251. templateDir,
  252. videoDir,
  253. resolvePath
  254. }