Skip to content

Commit

Permalink
fix: setting view broken after 2024.11.34 release
Browse files Browse the repository at this point in the history
  • Loading branch information
hverlin committed Nov 29, 2024
1 parent a046e15 commit 80a49b3
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 26 deletions.
71 changes: 46 additions & 25 deletions src/miseService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,30 @@ const TRACKED_CONFIG_DIR = path.join(STATE_DIR, "tracked-configs");

const MIN_MISE_VERSION = [2024, 11, 4] as const;

function compareVersions(
a: readonly [number, number, number],
b: readonly [number, number, number],
) {
for (let i = 0; i < a.length; i++) {
// @ts-ignore
if (a[i] > b[i]) {
return 1;
}
// @ts-ignore
if (a[i] < b[i]) {
return -1;
}
}
return 0;
}

function isVersionGreaterOrEqualThan(
version: readonly [number, number, number],
target: readonly [number, number, number],
) {
return compareVersions(version, target) >= 0;
}

function ensureMiseCommand(
miseCommand: string | undefined,
): asserts miseCommand {
Expand Down Expand Up @@ -504,6 +528,19 @@ export class MiseService {
return stdout.trim();
}

async getParsedMiseVersion() {
const version = await this.getVersion();
const match = /(\d+)\.(\d+)\.(\d+)/.exec(version);
if (!match) {
return undefined;
}

const [, year, minor, patch] = match.map((n) =>
n ? Number.parseInt(n, 10) : 0,
);
return [year, minor, patch] as [number, number, number];
}

async canSelfUpdate() {
if (!this.getMiseBinaryPath()) {
return false;
Expand All @@ -522,34 +559,12 @@ export class MiseService {
return false;
}

const version = await this.getVersion();
const match = /(\d+)\.(\d+)\.(\d+)/.exec(version);
if (!match) {
return false;
}

const [, year, month, day] = match.map((n) =>
n ? Number.parseInt(n, 10) : undefined,
);
if (year === undefined || month === undefined || day === undefined) {
const version = await this.getParsedMiseVersion();
if (!version) {
return false;
}

if (year > MIN_MISE_VERSION[0]) {
return true;
}
if (year < MIN_MISE_VERSION[0]) {
return false;
}

if (month > MIN_MISE_VERSION[1]) {
return true;
}
if (month < MIN_MISE_VERSION[1]) {
return false;
}

return day >= MIN_MISE_VERSION[2];
return isVersionGreaterOrEqualThan(version, MIN_MISE_VERSION);
}

async checkNewMiseVersion() {
Expand Down Expand Up @@ -677,6 +692,12 @@ export class MiseService {
return [];
}

const version = await this.getParsedMiseVersion();
if (version && isVersionGreaterOrEqualThan(version, [2024, 11, 34])) {
const { stdout } = await this.execMiseCommand("settings --all --json");
return JSON.parse(stdout);
}

const { stdout } = await this.execMiseCommand("settings");
return parse(stdout);
}
Expand Down
4 changes: 3 additions & 1 deletion src/webviews/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
import { ErrorBoundary } from "react-error-boundary";
import { App } from "./App";

const queryClient = new QueryClient();
const queryClient = new QueryClient({
defaultOptions: { queries: { retry: 1 } },
});

// @ts-ignore
function Fallback({ error, resetErrorBoundary }) {
Expand Down

0 comments on commit 80a49b3

Please sign in to comment.