(feat): big call and chatting stuff #23

Merged
alois merged 33 commits from dev into main 2026-08-01 03:05:40 +03:00
7 changed files with 71 additions and 31 deletions
Showing only changes of commit cda0c48454 - Show all commits

(feat): improve secure storage

Alois 2026-07-21 13:42:52 +02:00
Signed by: alois
SSH key fingerprint: SHA256:GBzT2DXvAuGV9XIV5W3WrzVpjU54FThmxHXdbz95J24

View file

@ -36,6 +36,13 @@ if (verbose) {
app.commandLine.appendSwitch("log-level", "0");
}
if (
process.platform === "linux" &&
!app.commandLine.hasSwitch("password-store")
) {
app.commandLine.appendSwitch("password-store", "gnome-libsecret");
}
if (
process.platform === "linux" &&
process.env.XDG_SESSION_TYPE === "wayland" &&

View file

@ -34,10 +34,6 @@ function validateValue(value: unknown): asserts value is string {
}
export function getSecureStorageStatus(): DesktopSecureStorageStatus {
if (!safeStorage.isEncryptionAvailable()) {
return { available: false, backend: null };
}
const backend =
process.platform === "linux"
? safeStorage.getSelectedStorageBackend()
@ -48,7 +44,9 @@ export function getSecureStorageStatus(): DesktopSecureStorageStatus {
: null;
return {
available: process.platform !== "linux" || backend !== "basic_text",
available:
safeStorage.isEncryptionAvailable() &&
(process.platform !== "linux" || backend !== "basic_text"),
backend,
};
}

View file

@ -1,16 +1,18 @@
import { useState, useCallback, useEffect } from "react";
import { useStorage } from "@tensamin/storage/context";
import { Button } from "@tensamin/ui";
import { Checkbox } from "@tensamin/ui";
import {
Button,
Checkbox,
CreateScreen,
ErrorScreen,
Label,
Link,
Spinner,
} from "@tensamin/ui";
import { z } from "zod";
import { ErrorScreen } from "@tensamin/ui";
import { legalDocsSchema } from "@tensamin/shared/features/legal/schema";
import { log } from "@tensamin/shared/log";
import { Link } from "@tensamin/ui";
import { Label } from "@tensamin/ui";
import { CreateScreen } from "@tensamin/ui";
// Prevents the user from using Tensamin without accepting the privacy policy and terms of service.
export default function Screen(props: { children: React.ReactNode }) {
@ -27,6 +29,7 @@ export default function Screen(props: { children: React.ReactNode }) {
>(undefined);
const [loading, setLoading] = useState(true);
const [showLoading, setShowLoading] = useState(false);
const [acceptedPP, acceptPP] = useState(false);
const [acceptedTOS, acceptTOS] = useState(false);
@ -49,6 +52,7 @@ export default function Screen(props: { children: React.ReactNode }) {
useEffect(() => {
let active = true;
let loadingTimer: ReturnType<typeof setTimeout> | undefined;
void (async () => {
try {
@ -63,22 +67,17 @@ export default function Screen(props: { children: React.ReactNode }) {
return;
}
const current = await fetch("https://legal.tensamin.net/api/current")
.then((res) => res.json())
.catch((err) => {
if (!active) {
return undefined;
loadingTimer = setTimeout(() => {
if (active) setShowLoading(true);
}, 200);
const response = await fetch("https://legal.tensamin.net/api/current");
if (!response.ok) {
throw new Error(`Legal documents request failed: ${response.status}`);
}
const current: unknown = await response.json();
setError("Failed to load legal documents");
setErrorDescription(
"An error occurred while fetching the legal documents from the server. Please try again later.",
);
log(0, "Legal", "red", "Failed to fetch legal documents", err);
return undefined;
});
if (!active || current === undefined) {
if (!active) {
return;
}
@ -122,7 +121,16 @@ export default function Screen(props: { children: React.ReactNode }) {
!!currentLocalDocs &&
currentLocalDocs.tos.hash === safeCurrent.data.tos.hash,
);
} catch (err) {
if (!active) return;
setError("Failed to load legal documents");
setErrorDescription(
"An error occurred while fetching the legal documents from the server. Please try again later.",
);
log(0, "Legal", "red", "Failed to fetch legal documents", err);
} finally {
clearTimeout(loadingTimer);
if (active) {
setLoading(false);
}
@ -131,6 +139,7 @@ export default function Screen(props: { children: React.ReactNode }) {
return () => {
active = false;
clearTimeout(loadingTimer);
};
}, [load]);
@ -139,7 +148,22 @@ export default function Screen(props: { children: React.ReactNode }) {
}
if (loading || userId === undefined) {
return null;
if (!showLoading) return null;
return (
<CreateScreen>
<div className="flex flex-col items-center gap-3">
<Spinner className="size-8" />
<p className="text-sm text-muted-foreground">
Fetching legal documents...
</p>
<Link
label="status.methanium.net"
link="https://status.methanium.net"
/>
</div>
</CreateScreen>
);
}
const docsMatch =

View file

@ -53,6 +53,7 @@
libglvnd
libnotify
libpulseaudio
libsecret
libuuid
libxkbcommon
mesa
@ -104,7 +105,8 @@
cp -r usr/* "$out/"
mkdir -p "$out/bin"
makeWrapper "$out/opt/Tensamin/tensamin" "$out/bin/tensamin"
makeWrapper "$out/opt/Tensamin/tensamin" "$out/bin/tensamin" \
--prefix LD_LIBRARY_PATH : "${pkgs.lib.makeLibraryPath electronRuntimeLibs}"
substituteInPlace "$out/share/applications/Tensamin.desktop" \
--replace-fail "Exec=/opt/Tensamin/tensamin" "Exec=tensamin"
@ -172,6 +174,7 @@
libglvnd
libnotify
libpulseaudio
libsecret
libuuid
libxkbcommon
mesa

View file

@ -14,6 +14,7 @@
"build": "tsc -p tsconfig.json --noEmit"
},
"dependencies": {
"@tauri-apps/api": "^2",
"@tensamin/cache": "workspace:*",
"@tensamin/shared": "workspace:*",
"@tensamin/mtp": "workspace:*",

View file

@ -1,8 +1,10 @@
import type {} from "@tensamin/shared/desktopMedia";
import { isTauri } from "@tauri-apps/api/core";
import { getDatabaseEntry, setDatabaseEntry } from "@tensamin/shared/indexedDb";
export type SecureStorageStatus = {
backend: "electron-keyring" | "webcrypto" | "indexeddb";
backend:
"electron-keyring" | "application-storage" | "webcrypto" | "indexeddb";
secure: boolean;
reason?: string;
};
@ -84,6 +86,7 @@ export function isSecureEnvelope(value: unknown): value is SecureEnvelope {
}
export async function encodeSecureValue(value: unknown): Promise<unknown> {
if (isTauri()) return value;
const key = await getKey();
if (!key) return value;
const iv = crypto.getRandomValues(new Uint8Array(12));
@ -127,6 +130,7 @@ export async function getSecureStorageStatus(): Promise<SecureStorageStatus> {
: "Electron secure storage is unavailable.",
};
}
if (isTauri()) return { backend: "application-storage", secure: true };
return (await getKey())
? { backend: "webcrypto", secure: true }
: {

3
pnpm-lock.yaml generated
View file

@ -818,6 +818,9 @@ importers:
packages/storage:
dependencies:
'@tauri-apps/api':
specifier: ^2
version: 2.11.1
'@tensamin/cache':
specifier: workspace:*
version: link:../cache