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