fix(desktop): Lotus links use the public web app, and open in-app (#248)
CI / Build & Quality Checks (pull_request) Successful in 1m50s
CI / Trigger Desktop Build (pull_request) Skipped
CI / Docker image build & smoke test (pull_request) Skipped
CI / Secret scan (gitleaks) (pull_request) Successful in 8s
CI / Playwright smoke (e2e) (pull_request) Successful in 9m19s
CI / Build & Quality Checks (pull_request) Successful in 1m50s
CI / Trigger Desktop Build (pull_request) Skipped
CI / Docker image build & smoke test (pull_request) Skipped
CI / Secret scan (gitleaks) (pull_request) Successful in 8s
CI / Playwright smoke (e2e) (pull_request) Successful in 9m19s
Lotus permalinks (#130) were built from window.location.origin. In the desktop app that's the local tauri-plugin-localhost server (hash-routed), so "Copy Lotus Link" copied e.g. http://localhost:…/#/home/!room…, which works for nobody else. And the link recogniser only knew that local base, so a real https://chat.lotusguild.org/home/… link in a message opened the browser instead of the room. - useLotusShareBase: in the desktop app, links for other people use config `webAppUrl` (https only, set by cinny-desktop #23) in web path-routing form; otherwise the origin, as before. Used by "Copy Lotus Link" on messages, the space menu and space tabs. - The recogniser accepts several bases: the origin, plus `webAppUrl` in the desktop app. - The web app is unchanged. Verified with a simulated desktop (Tauri bridge + webAppUrl) against a local Synapse. Copied links are https://chat.lotusguild.org/home/<room>/<event> and https://chat.lotusguild.org/<space>. A public link in a message renders as the room pill and clicking it opens the room in-app, with nothing sent to the system browser. The web app still copies origin links. Unit tests for the base selection; Playwright 20 passed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01PPmy3tPq869XDW4njjVaKA
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
be8e49a2bb
commit
1ea6987083
@@ -0,0 +1,23 @@
|
||||
import { test } from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import { lotusLinkBases, lotusShareBase } from './useLotusLinkBase';
|
||||
|
||||
const LOCAL = 'http://localhost:44548/#/';
|
||||
const WEB = 'https://chat.lotusguild.org';
|
||||
|
||||
test('web: shared links use the page origin', () => {
|
||||
assert.equal(lotusShareBase(WEB, false, WEB), WEB);
|
||||
assert.deepEqual(lotusLinkBases(WEB, false, undefined), [WEB]);
|
||||
});
|
||||
|
||||
test('desktop with webAppUrl: shared links use the public web app', () => {
|
||||
assert.equal(lotusShareBase(LOCAL, true, `${WEB}/`), WEB);
|
||||
assert.deepEqual(lotusLinkBases(LOCAL, true, WEB), [LOCAL, WEB]);
|
||||
});
|
||||
|
||||
test('desktop without a valid webAppUrl falls back to the origin', () => {
|
||||
[undefined, '', 'http://chat.lotusguild.org', 'nonsense'].forEach((v) => {
|
||||
assert.equal(lotusShareBase(LOCAL, true, v), LOCAL, String(v));
|
||||
assert.deepEqual(lotusLinkBases(LOCAL, true, v), [LOCAL]);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,37 @@
|
||||
import { useMemo } from 'react';
|
||||
import { useClientConfig } from './useClientConfig';
|
||||
import { isTauri } from './useTauri';
|
||||
import { getOriginBaseUrl } from '../pages/pathUtils';
|
||||
import { resolveWebAppUrl } from '../utils/callInBrowser';
|
||||
|
||||
/**
|
||||
* [Gitea #248] Base URL for Lotus links meant for other people.
|
||||
*
|
||||
* On the web that's this page's origin. In the desktop app the page is served
|
||||
* from a local address (and hash-routed), which nobody else can open, so use
|
||||
* the public web app from config `webAppUrl` (web path routing) instead.
|
||||
* Without a valid `webAppUrl` it falls back to the origin, as before.
|
||||
*/
|
||||
export const lotusShareBase = (originBase: string, desktop: boolean, webAppUrl: unknown): string =>
|
||||
(desktop && resolveWebAppUrl(webAppUrl)) || originBase;
|
||||
|
||||
/**
|
||||
* Every base a Lotus link to this deployment may start with: the origin, plus
|
||||
* the public web app in the desktop app, so a shared https link opens in-app.
|
||||
*/
|
||||
export const lotusLinkBases = (
|
||||
originBase: string,
|
||||
desktop: boolean,
|
||||
webAppUrl: unknown,
|
||||
): string[] => {
|
||||
const shared = lotusShareBase(originBase, desktop, webAppUrl);
|
||||
return shared === originBase ? [originBase] : [originBase, shared];
|
||||
};
|
||||
|
||||
export const useLotusShareBase = (): string => {
|
||||
const { hashRouter, webAppUrl } = useClientConfig();
|
||||
return useMemo(
|
||||
() => lotusShareBase(getOriginBaseUrl(hashRouter), isTauri(), webAppUrl),
|
||||
[hashRouter, webAppUrl],
|
||||
);
|
||||
};
|
||||
Reference in New Issue
Block a user