Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion apps/web/src/common/desktop-bridge/index.desktop.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import { AppEventManager, AppEvents } from "../app-events";
import { TaskScheduler } from "../../utils/task-scheduler";
import { checkForUpdate } from "../../utils/updater";
import { showToast } from "../../utils/toast";
import { store as settingStore } from "../../stores/setting-store";

export const desktop = createTRPCProxyClient<AppRouter>({
links: [ipcLink()]
Expand Down Expand Up @@ -64,7 +65,7 @@ function attachListeners() {
);

TaskScheduler.register("updateCheck", "0 0 */12 * * * *", () => {
checkForUpdate();
checkForUpdate(settingStore.get().autoUpdates);
});
}

Expand Down
12 changes: 9 additions & 3 deletions apps/web/src/hooks/use-auto-updater.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

import { useEffect } from "react";

import { checkForUpdate } from "../utils/updater";
import { AppEventManager, AppEvents } from "../common/app-events";
import BaseStore from "../stores";
import createStore from "../common/store";
import { useStore as useSettingStore } from "../stores/setting-store";

type CompletedUpdateStatus = { type: "completed"; version: string };
type DownloadingUpdateStatus = { type: "downloading"; progress: number };
Expand Down Expand Up @@ -103,15 +103,21 @@ export function useAutoUpdater() {
updateDownloadProgress
);

checkingForUpdate();
checkForUpdate().catch(console.error);
const settingStoreUnsub = useSettingStore.subscribe(
(s) => s.autoUpdates,
(autoUpdates) => {
checkingForUpdate();
checkForUpdate(autoUpdates).catch(console.error);
}
);

return () => {
checkingForUpdateEvent.unsubscribe();
updateAvailableEvent.unsubscribe();
updateNotAvailableEvent.unsubscribe();
updateCompletedEvent.unsubscribe();
updateProgressEvent.unsubscribe();
settingStoreUnsub();
};
}, []);

Expand Down
2 changes: 1 addition & 1 deletion apps/web/src/stores/setting-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ class SettingStore extends BaseStore<SettingStore> {
ImageCompressionOptions.ASK_EVERY_TIME
);
desktopIntegrationSettings?: DesktopIntegration;
autoUpdates = true;
autoUpdates = false;
isFlatpak = false;
isSnap = false;
proxyRules?: string;
Expand Down
9 changes: 6 additions & 3 deletions apps/web/src/utils/updater.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,12 @@ import { AppEventManager, AppEvents } from "../common/app-events";
import { desktop } from "../common/desktop-bridge";
import { appVersion, getServiceWorkerVersion } from "./version";

export async function checkForUpdate() {
if (IS_DESKTOP_APP) await desktop?.updater.check.query().catch(console.error);
else {
export async function checkForUpdate(checkOnDesktop = true) {
if (IS_DESKTOP_APP && checkOnDesktop) {
await desktop?.updater.check.query().catch(console.error);
}

if (!IS_DESKTOP_APP) {
AppEventManager.publish(AppEvents.checkingForUpdate);

const registrations =
Expand Down
Loading