Skip to content

Commit

Permalink
Release 3.0.6 (#511)
Browse files Browse the repository at this point in the history
  • Loading branch information
macjuul authored Oct 9, 2024
1 parent 224ab6c commit 6a308ae
Show file tree
Hide file tree
Showing 8 changed files with 258 additions and 152 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "surrealist",
"private": true,
"version": "3.0.5",
"version": "3.0.6",
"surreal": "2.0.0",
"type": "module",
"authors": [
Expand Down
70 changes: 29 additions & 41 deletions src/adapter/desktop.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,13 @@ import { basename } from "@tauri-apps/api/path";
import { getCurrentWebview } from "@tauri-apps/api/webview";
import { getCurrentWindow } from "@tauri-apps/api/window";
import { open, save } from "@tauri-apps/plugin-dialog";
import {
readFile,
readTextFile,
writeFile,
writeTextFile,
} from "@tauri-apps/plugin-fs";
import { readFile, readTextFile, writeFile, writeTextFile } from "@tauri-apps/plugin-fs";
import { fetch } from "@tauri-apps/plugin-http";
import { attachConsole, info, trace, warn } from "@tauri-apps/plugin-log";
import { arch, type } from "@tauri-apps/plugin-os";
import { open as openURL } from "@tauri-apps/plugin-shell";
import { check } from "@tauri-apps/plugin-updater";
import { compareVersions } from "compare-versions";
import { VIEW_MODES } from "~/constants";
import { useConfigStore } from "~/stores/config";
import { useDatabaseStore } from "~/stores/database";
Expand All @@ -26,11 +22,7 @@ import { featureFlags } from "~/util/feature-flags";
import { showError, showInfo } from "~/util/helpers";
import { handleIntentRequest } from "~/util/intents";
import { adapter } from ".";
import type {
OpenedBinaryFile,
OpenedTextFile,
SurrealistAdapter,
} from "./base";
import type { OpenedBinaryFile, OpenedTextFile, SurrealistAdapter } from "./base";

const WAIT_DURATION = 1000;

Expand Down Expand Up @@ -66,8 +58,7 @@ export class DesktopAdapter implements SurrealistAdapter {
#system: string = type();

public constructor() {
this.hasTitlebar =
this.#system === "windows" || this.#system === "linux";
this.hasTitlebar = this.#system === "windows" || this.#system === "linux";

this.initDatabaseEvents();

Expand Down Expand Up @@ -155,17 +146,10 @@ export class DesktopAdapter implements SurrealistAdapter {
config: JSON.stringify(config),
});
}

public async startDatabase() {
const {
username,
password,
port,
driver,
storage,
executable,
logLevel,
} = useConfigStore.getState().settings.serving;
const { username, password, port, driver, storage, executable, logLevel } =
useConfigStore.getState().settings.serving;

const legacyCompat = featureFlags.get("legacy_serve");

Expand Down Expand Up @@ -210,10 +194,7 @@ export class DesktopAdapter implements SurrealistAdapter {
if (typeof result === "string") {
await writeTextFile(filePath, result);
} else {
await writeFile(
filePath,
new Uint8Array(await result.arrayBuffer()),
);
await writeFile(filePath, new Uint8Array(await result.arrayBuffer()));
}

return true;
Expand Down Expand Up @@ -283,27 +264,36 @@ export class DesktopAdapter implements SurrealistAdapter {
trace(`${label}: ${message}`);
}

public fetch(
url: string,
options?: RequestInit | undefined,
): Promise<Response> {
public fetch(url: string, options?: RequestInit | undefined): Promise<Response> {
return fetch(url, options);
}

public async checkForUpdates(force?: boolean) {
const { lastPromptedVersion, setLastPromptedVersion } =
useConfigStore.getState();
const { lastPromptedVersion, setLastPromptedVersion } = useConfigStore.getState();
const { setAvailableUpdate } = useInterfaceStore.getState();

adapter.log("Updater", "Checking for updates");

const result = await check();
try {
const result = await check();

if (result) {
const currentVersion = import.meta.env.VERSION;
const latestVersion = result.version;

if (result && (force || result.version !== lastPromptedVersion)) {
adapter.log("Updater", `New version available: ${result.version}`);
adapter.log("Updater", `Current: ${currentVersion}, Latest: ${latestVersion}`);

setAvailableUpdate(result);
setLastPromptedVersion(result.version);
if (compareVersions(latestVersion, currentVersion) > 0) {
const showAlert = force || result.version !== lastPromptedVersion;

setAvailableUpdate(result, showAlert);
setLastPromptedVersion(result.version);
}
} else {
adapter.log("Updater", "No updates available");
}
} catch (err: any) {
console.warn("Failed to check for updates", err);
}
}

Expand Down Expand Up @@ -349,9 +339,7 @@ export class DesktopAdapter implements SurrealistAdapter {

const historySize = getSetting("serving", "historySize");

useDatabaseStore
.getState()
.pushConsoleLine(event.payload as string, historySize);
useDatabaseStore.getState().pushConsoleLine(event.payload as string, historySize);
throttleLevel++;
});

Expand Down
12 changes: 12 additions & 0 deletions src/assets/changelogs/3.0.6.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
title: Surrealist 3.0.6
summary: Minor improvements
date: 2024/10/09
---

- Added a dedicated update button in the settings dialog
- Useful when you previously dismissed an update alert
- Allow executing queries when focused in the variables panel
- Fixed escaped table names not fetching records in the Explorer view
- Fixed some wording in the API Docs view
- Improved internal handling of datasets
110 changes: 16 additions & 94 deletions src/components/App/modals/updater.tsx
Original file line number Diff line number Diff line change
@@ -1,107 +1,23 @@
import { ActionIcon, Alert, Box, Dialog, Group, Text } from "@mantine/core";
import { invoke } from "@tauri-apps/api/core";
import { relaunch } from "@tauri-apps/plugin-process";
import { type MouseEvent, useState } from "react";
import { ActionIcon, Box, Dialog, Group, Text } from "@mantine/core";
import type { MouseEvent } from "react";
import { Icon } from "~/components/Icon";
import { useStable } from "~/hooks/stable";
import { useConfirmation } from "~/providers/Confirmation";
import { useConfigStore } from "~/stores/config";
import { useDesktopUpdater } from "~/hooks/updater";
import { useInterfaceStore } from "~/stores/interface";
import { iconClose, iconDownload } from "~/util/icons";
import classes from "../style.module.scss";

type Phase = "idle" | "downloading" | "error";

function extractMajor(version: string) {
return Number.parseInt(version.split(".")[0] ?? 0);
}

export function UpdaterDialog() {
const { hideAvailableUpdate } = useInterfaceStore.getState();

const update = useInterfaceStore((s) => s.availableUpdate);
const showUpdate = useInterfaceStore((s) => s.showAvailableUpdate);
const [phase, setPhase] = useState<Phase>("idle");
const [packageTotal, setPackageTotal] = useState(0);
const [packageProgress, setPackageProgress] = useState(0);

const currentMajor = extractMajor(import.meta.env.VERSION);
const latestMajor = extractMajor(update?.version || "0.0.0");
const isDangerous = latestMajor > currentMajor;
const { phase, progress, version, startUpdate } = useDesktopUpdater();

const hideUpdate = useStable((e: MouseEvent) => {
e.stopPropagation();
hideAvailableUpdate();
});

const installUpdate = useStable(async () => {
if (!update || phase !== "idle") return;

if (isDangerous) {
const config = useConfigStore.getState();

await invoke("backup_config", {
config: JSON.stringify(config),
version: config.configVersion,
});
}

setPhase("downloading");
setPackageProgress(0);

try {
await update.downloadAndInstall((e) => {
if (e.event === "Started") {
setPackageTotal(e.data.contentLength || 0);
} else if (e.event === "Progress") {
setPackageProgress((p) => p + e.data.chunkLength);
}
});

await relaunch();
} catch (err: any) {
console.error(err);
setPhase("error");
}
});

const promptUpdate = useConfirmation({
title: "New major version",
message: (
<>
The update you are about to install is a new major version of
Surrealist. Are you sure you want to proceed?
<Alert mt="xl" color="orange" title="Warning">
An upgrade could result in incompatibility with older
versions of SurrealDB.
</Alert>
</>
),
confirmText: (
<Group gap="xs">
Install update
<Icon path={iconDownload} />
</Group>
),
confirmProps: { variant: "gradient" },
dismissText: "Don't update now",
onConfirm: () => installUpdate(),
onDismiss: () => hideAvailableUpdate(),
});

const handleClick = useStable(() => {
if (isDangerous) {
promptUpdate();
} else {
installUpdate();
}
});

const progress =
packageTotal > 0
? ((packageProgress / packageTotal) * 100).toFixed(0)
: 0;

return (
<Dialog
opened={showUpdate}
Expand All @@ -120,7 +36,7 @@ export function UpdaterDialog() {
classNames={{
root: classes.updateDialog,
}}
onClick={handleClick}
onClick={startUpdate}
>
<ActionIcon
onClick={hideUpdate}
Expand All @@ -133,20 +49,26 @@ export function UpdaterDialog() {
</ActionIcon>
<Group>
<Box className={classes.updateDialogIcon}>
<Icon path={iconDownload} size="lg" c="white" />
<Icon
path={iconDownload}
size="lg"
c="white"
/>
</Box>
<Box miw={200}>
<Text c="white" fw={500} fz="lg">
<Text
c="white"
fw={500}
fz="lg"
>
New version available
</Text>
{phase === "downloading" ? (
<Text c="gray.5">Installing... ({progress}%)</Text>
) : phase === "error" ? (
<Text c="red">Failed to install update</Text>
) : (
<Text c="gray.5">
Click to install version {update?.version}
</Text>
<Text c="gray.5">Click to install version {version}</Text>
)}
</Box>
</Group>
Expand Down
Loading

0 comments on commit 6a308ae

Please sign in to comment.