From 954787ee2e575249b43445c9f67c4eca7b39b469 Mon Sep 17 00:00:00 2001 From: Lucas Nogueira Date: Wed, 10 May 2023 19:05:11 -0300 Subject: [PATCH] format --- plugins/updater/guest-js/index.ts | 60 ++++++++++--------- plugins/updater/package.json | 2 +- .../updater/tests/app-updater/tauri.conf.json | 6 +- 3 files changed, 35 insertions(+), 33 deletions(-) diff --git a/plugins/updater/guest-js/index.ts b/plugins/updater/guest-js/index.ts index 4cfec3a1..6c2363c8 100644 --- a/plugins/updater/guest-js/index.ts +++ b/plugins/updater/guest-js/index.ts @@ -1,41 +1,41 @@ -import { invoke, transformCallback } from '@tauri-apps/api/tauri' +import { invoke, transformCallback } from "@tauri-apps/api/tauri"; interface CheckOptions { /** * Request headers */ - headers?: Record + headers?: Record; /** * Timeout in seconds */ - timeout?: number + timeout?: number; /** * Target identifier for the running application. This is sent to the backend. */ - target?: string + target?: string; } interface UpdateResponse { - available: boolean - currentVersion: string - latestVersion: string - date?: string - body?: string + available: boolean; + currentVersion: string; + latestVersion: string; + date?: string; + body?: string; } // TODO: use channel from @tauri-apps/api on v2 class Channel { - id: number + id: number; // @ts-expect-error field used by the IPC serializer - private readonly __TAURI_CHANNEL_MARKER__ = true + private readonly __TAURI_CHANNEL_MARKER__ = true; #onmessage: (response: T) => void = () => { // no-op - } + }; constructor() { this.id = transformCallback((response: T) => { - this.#onmessage(response) - }) + this.#onmessage(response); + }); } set onmessage(handler: (response: T) => void) { @@ -43,38 +43,42 @@ class Channel { } get onmessage(): (response: T) => void { - return this.#onmessage + return this.#onmessage; } toJSON(): string { - return `__CHANNEL__:${this.id}` + return `__CHANNEL__:${this.id}`; } } type DownloadEvent = - { event: 'Started', data: { contentLength?: number } } | - { event: 'Progress', data: { chunkLength: number } } | - { event: 'Finished' } + | { event: "Started"; data: { contentLength?: number } } + | { event: "Progress"; data: { chunkLength: number } } + | { event: "Finished" }; class Update { - response: UpdateResponse + response: UpdateResponse; constructor(response: UpdateResponse) { - this.response = response + this.response = response; } - async downloadAndInstall(onEvent?: (progress: DownloadEvent) => void): Promise { - const channel = new Channel() + async downloadAndInstall( + onEvent?: (progress: DownloadEvent) => void + ): Promise { + const channel = new Channel(); if (onEvent != null) { - channel.onmessage = onEvent + channel.onmessage = onEvent; } - return invoke('plugin:updater|download_and_install', { onEvent: channel }) + return invoke("plugin:updater|download_and_install", { onEvent: channel }); } } async function check(options?: CheckOptions): Promise { - return invoke('plugin:updater|check', { ...options }).then(response => new Update(response)) + return invoke("plugin:updater|check", { ...options }).then( + (response) => new Update(response) + ); } -export type { CheckOptions, UpdateResponse, DownloadEvent } -export { check, Update } +export type { CheckOptions, UpdateResponse, DownloadEvent }; +export { check, Update }; diff --git a/plugins/updater/package.json b/plugins/updater/package.json index 191682e6..5f907a64 100644 --- a/plugins/updater/package.json +++ b/plugins/updater/package.json @@ -29,4 +29,4 @@ "dependencies": { "@tauri-apps/api": "^1.2.0" } -} \ No newline at end of file +} diff --git a/plugins/updater/tests/app-updater/tauri.conf.json b/plugins/updater/tests/app-updater/tauri.conf.json index dc099aaf..eac17193 100644 --- a/plugins/updater/tests/app-updater/tauri.conf.json +++ b/plugins/updater/tests/app-updater/tauri.conf.json @@ -29,12 +29,10 @@ "updater": { "active": true, "pubkey": "dW50cnVzdGVkIGNvbW1lbnQ6IG1pbmlzaWduIHB1YmxpYyBrZXk6IDE5QzMxNjYwNTM5OEUwNTgKUldSWTRKaFRZQmJER1h4d1ZMYVA3dnluSjdpN2RmMldJR09hUFFlZDY0SlFqckkvRUJhZDJVZXAK", - "endpoints": [ - "http://localhost:3007" - ], + "endpoints": ["http://localhost:3007"], "windows": { "installMode": "quiet" } } } -} \ No newline at end of file +}