import { autoUpdater } from "electron-updater";
import { setReleaseChannel } from "../ipc/ipcMainHandler.user";

let continuousUpdatesTriggered = false;

async function checkForAppUpdatesContinuously(): Promise<void> {
  if (!continuousUpdatesTriggered) {
    continuousUpdatesTriggered = true;
    checkForAppUpdates();
    setInterval(
      () => {
        checkForAppUpdates();
      },
      1000 * 60 * 30,
    );
  }
}
async function checkForAppUpdates(): Promise<void> {
  await setReleaseChannel();
  autoUpdater.checkForUpdates();
}

export { checkForAppUpdates, checkForAppUpdatesContinuously };
