Skip to content

Commit

Permalink
Merge pull request #189 from pkova/master
Browse files Browse the repository at this point in the history
landscape: complain if vere is out of date
  • Loading branch information
arthyn authored Jun 8, 2023
2 parents edd8d90 + fe628d8 commit fdf7636
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 2 deletions.
6 changes: 5 additions & 1 deletion ui/src/nav/Nav.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import { NotificationsLink } from './notifications/NotificationsLink';
import { Search } from './Search';
import { SystemPreferences } from '../preferences/SystemPreferences';
import { useSystemUpdate } from '../logic/useSystemUpdate';
import useVereState from '../state/vere';
import { Bullet } from '../components/icons/Bullet';
import { Cross } from '../components/icons/Cross';
import MagnifyingGlass16Icon from '../components/icons/MagnifyingGlass16Icon';
Expand Down Expand Up @@ -138,9 +139,12 @@ export const Nav: FunctionComponent<NavProps> = ({ menu }) => {
const dialogNavRef = useRef<HTMLDivElement>(null);
const { disableWayfinding } = useCalm();
const { systemBlocked } = useSystemUpdate();
const { isLatest, loaded } = useVereState();
const [dialogContentOpen, setDialogContentOpen] = useState(false);
const select = useAppSearchStore((state) => state.select);

const runtimeOutOfDate = (loaded && !(isLatest));

const menuState = menu || 'closed';
const isOpen =
menuState !== 'upgrading' && menuState !== 'closed' && menuState !== 'app';
Expand Down Expand Up @@ -188,7 +192,7 @@ export const Nav: FunctionComponent<NavProps> = ({ menu }) => {
containerRef={dialogContentOpen ? dialogNavRef : navRef}
className="flex w-full items-center space-x-2 sm:justify-center"
>
<SystemPrefsLink menuState={menuState} systemBlocked={systemBlocked} />
<SystemPrefsLink menuState={menuState} systemBlocked={systemBlocked || runtimeOutOfDate} />
<NotificationsLink
navOpen={isOpen}
notificationsOpen={menu === 'notifications'}
Expand Down
22 changes: 21 additions & 1 deletion ui/src/preferences/about-system/AboutSystem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import * as Dialog from '@radix-ui/react-dialog';
import { FullTlon16Icon } from '../../components/icons/FullTlon16Icon';
import { useSystemUpdate } from '../../logic/useSystemUpdate';
import { usePike, useLag } from '../../state/kiln';
import useVereState from '../../state/vere';
import { disableDefault, pluralize } from '@/logic/utils';
import { UpdatePreferences } from './UpdatePreferences';

Expand All @@ -28,6 +29,11 @@ export const AboutSystem = () => {
const hash = basePike && getHash(basePike);
const lag = useLag();

const vere = useVereState.getState();
const {isLatest, vereVersion, latestVereVersion, loaded} = vere;

const runtimeUpToDate = (!loaded || isLatest)

return (
<>
<div className="inner-section relative mb-4 space-y-8">
Expand All @@ -51,6 +57,7 @@ export const AboutSystem = () => {
<p className="text-orange-500">
System update failed because your runtime was out of date.
</p>
<p>Your runtime version is {vereVersion}, the latest runtime version is {latestVereVersion}.</p>
<p>Update your runtime or contact your hosting provider.</p>
<p>Once your runtime is up to date, click retry below.</p>
<Button variant="caution" onClick={freezeApps}>
Expand Down Expand Up @@ -138,7 +145,20 @@ export const AboutSystem = () => {
)}
</>
) : (
<p>Your urbit is up to date.</p>
<>
{runtimeUpToDate ?
<>
<p>Urbit Runtime Version {vereVersion}</p>
<p>Your urbit is up to date.</p>
</> :
<>
<p className="text-orange-500">Your runtime version is {vereVersion}, the latest runtime version is {latestVereVersion}.</p>
<p className="text-orange-500">
<a className="text-blue-500 font-bold" href="https://operators.urbit.org/manual/os/updates#runtime-updates">Update your runtime </a>
or contact your hosting provider.</p>
</>
}
</>
)}
</div>
</div>
Expand Down
53 changes: 53 additions & 0 deletions ui/src/state/vere.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import api from '@/api';
import create, { SetState } from 'zustand';
import produce from 'immer';

interface Vere {
cur: VereState;
next?: VereState;
set: SetState<Vere>;
loaded: boolean;
isLatest: boolean;
vereVersion: string;
latestVereVersion: string;
}

interface VereState {
rev: string;
non?: string;
zuse?: number;
arvo?: number;
lull?: number;
hoon?: number;
nock?: number;
}

const useVereState = create<Vere>((set, get) => ({
loaded: false,
set
}))

const fetchRuntimeVersion = () => {
api.thread({
inputMark: 'noun',
outputMark: 'vere-update',
desk: 'base',
threadName: 'runtime-version',
body: '',
}).then((data: Vere) => {
useVereState.setState((state) => {
const vereVersion = data.cur.rev.split('/vere/~.')[1];
const isLatest = data.next === undefined;
const latestVereVersion = !isLatest ? data.next.rev.split('/vere/~.')[1] : vereVersion
return Object.assign(data, {loaded: true, isLatest, vereVersion, latestVereVersion});
})
});
}

fetchRuntimeVersion()

setInterval(fetchRuntimeVersion, 1800000)

export default useVereState;;

// window.vere = useVereState.getState;

0 comments on commit fdf7636

Please sign in to comment.