updater.d.ts 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. import { type UnlistenFn } from './helpers/event';
  2. /**
  3. * @since 1.0.0
  4. */
  5. type UpdateStatus = 'PENDING' | 'ERROR' | 'DONE' | 'UPTODATE';
  6. /**
  7. * @since 1.0.0
  8. */
  9. interface UpdateStatusResult {
  10. error?: string;
  11. status: UpdateStatus;
  12. }
  13. /**
  14. * @since 1.0.0
  15. */
  16. interface UpdateManifest {
  17. version: string;
  18. date: string;
  19. body: string;
  20. }
  21. /**
  22. * @since 1.0.0
  23. */
  24. interface UpdateResult {
  25. manifest?: UpdateManifest;
  26. shouldUpdate: boolean;
  27. }
  28. /**
  29. * Listen to an updater event.
  30. * @example
  31. * ```typescript
  32. * import { onUpdaterEvent } from "@tauri-apps/api/updater";
  33. * const unlisten = await onUpdaterEvent(({ error, status }) => {
  34. * console.log('Updater event', error, status);
  35. * });
  36. *
  37. * // you need to call unlisten if your handler goes out of scope e.g. the component is unmounted
  38. * unlisten();
  39. * ```
  40. *
  41. * @returns A promise resolving to a function to unlisten to the event.
  42. * Note that removing the listener is required if your listener goes out of scope e.g. the component is unmounted.
  43. *
  44. * @since 1.0.2
  45. */
  46. declare function onUpdaterEvent(handler: (status: UpdateStatusResult) => void): Promise<UnlistenFn>;
  47. /**
  48. * Install the update if there's one available.
  49. * @example
  50. * ```typescript
  51. * import { checkUpdate, installUpdate } from '@tauri-apps/api/updater';
  52. * const update = await checkUpdate();
  53. * if (update.shouldUpdate) {
  54. * console.log(`Installing update ${update.manifest?.version}, ${update.manifest?.date}, ${update.manifest.body}`);
  55. * await installUpdate();
  56. * }
  57. * ```
  58. *
  59. * @return A promise indicating the success or failure of the operation.
  60. *
  61. * @since 1.0.0
  62. */
  63. declare function installUpdate(): Promise<void>;
  64. /**
  65. * Checks if an update is available.
  66. * @example
  67. * ```typescript
  68. * import { checkUpdate } from '@tauri-apps/api/updater';
  69. * const update = await checkUpdate();
  70. * // now run installUpdate() if needed
  71. * ```
  72. *
  73. * @return Promise resolving to the update status.
  74. *
  75. * @since 1.0.0
  76. */
  77. declare function checkUpdate(): Promise<UpdateResult>;
  78. export type { UpdateStatus, UpdateStatusResult, UpdateManifest, UpdateResult };
  79. export { onUpdaterEvent, installUpdate, checkUpdate };