Skip to content

Commit

Permalink
Fix auto-update
Browse files Browse the repository at this point in the history
  • Loading branch information
abrenneke committed Mar 3, 2024
1 parent e3d6a1f commit 1dd5ec0
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
11 changes: 7 additions & 4 deletions packages/app/src/components/SettingsModal.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { type FC, useState } from 'react';
import { atom, useRecoilState, useRecoilValue } from 'recoil';
import {
checkForUpdatesState,
defaultExecutorState,
executorOptions,
previousDataPerNodeToKeepState,
Expand Down Expand Up @@ -473,7 +474,9 @@ export const PluginsSettingsPage: FC = () => {
};

export const UpdatesSettingsPage: FC = () => {
const checkForUpdates = useCheckForUpdate({ notifyNoUpdates: true, force: true });
const checkForUpdatesNow = useCheckForUpdate({ notifyNoUpdates: true, force: true });
const [checkForUpdates, setCheckForUpdates] = useRecoilState(checkForUpdatesState);

const [currentVersion, setCurrentVersion] = useState('');

useAsyncEffect(async () => {
Expand All @@ -496,9 +499,9 @@ export const UpdatesSettingsPage: FC = () => {
<div className="toggle-field">
<Toggle
id="check-for-updates"
isChecked={true}
isChecked={checkForUpdates}
onChange={(e) => {
// TODO
setCheckForUpdates(e.target.checked);
}}
/>
</div>
Expand All @@ -509,7 +512,7 @@ export const UpdatesSettingsPage: FC = () => {
<Field name="check-for-updates-now">
{() => (
<>
<Button appearance="primary" onClick={() => checkForUpdates()}>
<Button appearance="primary" onClick={() => checkForUpdatesNow()}>
Check for updates now
</Button>
</>
Expand Down
5 changes: 3 additions & 2 deletions packages/app/src/hooks/useCheckForUpdate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import { useRecoilState, useRecoilValue, useSetRecoilState } from 'recoil';
import { checkForUpdatesState, skippedMaxVersionState, updateModalOpenState } from '../state/settings';
import { gt, lt, lte } from 'semver';
import { getVersion } from '@tauri-apps/api/app';
import { isRunningInBrowser } from 'openai/core.mjs';

const toastStyle = css`
display: flex;
Expand Down Expand Up @@ -50,13 +49,15 @@ export function useCheckForUpdate({
const [skippedMaxVersion, setSkippedMaxVersion] = useRecoilState(skippedMaxVersionState);

return async () => {
if (!checkForUpdates || isRunningInBrowser()) {
if (!checkForUpdates || !isInTauri()) {
console.log('Skipping update check');
return;
}

const { shouldUpdate, manifest } = await checkUpdate();

if (!manifest) {
console.log('No manifest found');
return;
}

Expand Down

0 comments on commit 1dd5ec0

Please sign in to comment.