Add ref=<app_id> to external links pointing to yaak.app

This commit is contained in:
Gregory Schier
2025-05-16 07:53:22 -07:00
parent 749df338c5
commit 0be7d0283b
10 changed files with 31 additions and 27 deletions

View File

@@ -7,6 +7,7 @@
"*"
],
"permissions": [
"core:app:allow-identifier",
"core:event:allow-emit",
"core:event:allow-listen",
"core:event:allow-unlisten",

View File

@@ -1,12 +1,11 @@
import type { ReactNode } from 'react';
import { useAppInfo } from '../hooks/useAppInfo';
import { appInfo } from '../lib/appInfo';
interface Props {
children: ReactNode;
}
export function IsDev({ children }: Props) {
const appInfo = useAppInfo();
if (!appInfo.isDev) {
return null;
}

View File

@@ -2,7 +2,7 @@ import type { LicenseCheckStatus } from '@yaakapp-internal/license';
import { useLicense } from '@yaakapp-internal/license';
import type { ReactNode } from 'react';
import { openSettings } from '../commands/openSettings';
import { appInfo } from '../hooks/useAppInfo';
import { appInfo } from '../lib/appInfo';
import { useLicenseConfirmation } from '../hooks/useLicenseConfirmation';
import { BadgeButton } from './core/BadgeButton';
import type { ButtonProps } from './core/Button';

View File

@@ -3,7 +3,7 @@ import { patchModel, settingsAtom } from '@yaakapp-internal/models';
import { useAtomValue } from 'jotai';
import React from 'react';
import { activeWorkspaceAtom } from '../../hooks/useActiveWorkspace';
import { useAppInfo } from '../../hooks/useAppInfo';
import { appInfo } from '../../lib/appInfo';
import { useCheckForUpdates } from '../../hooks/useCheckForUpdates';
import { revealInFinderText } from '../../lib/reveal';
import { Checkbox } from '../core/Checkbox';
@@ -18,7 +18,6 @@ import { VStack } from '../core/Stacks';
export function SettingsGeneral() {
const workspace = useAtomValue(activeWorkspaceAtom);
const settings = useAtomValue(settingsAtom);
const appInfo = useAppInfo();
const checkForUpdates = useCheckForUpdates();
if (settings == null || workspace == null) {

View File

@@ -2,7 +2,7 @@ import { openUrl } from '@tauri-apps/plugin-opener';
import { useLicense } from '@yaakapp-internal/license';
import { useRef } from 'react';
import { openSettings } from '../commands/openSettings';
import { useAppInfo } from '../hooks/useAppInfo';
import { appInfo } from '../lib/appInfo';
import { useCheckForUpdates } from '../hooks/useCheckForUpdates';
import { useExportData } from '../hooks/useExportData';
import { useImportData } from '../hooks/useImportData';
@@ -17,7 +17,6 @@ import { KeyboardShortcutsDialog } from './KeyboardShortcutsDialog';
export function SettingsDropdown() {
const importData = useImportData();
const exportData = useExportData();
const appInfo = useAppInfo();
const dropdownRef = useRef<DropdownRef>(null);
const checkForUpdates = useCheckForUpdates();
const { check } = useLicense();

View File

@@ -1,6 +1,7 @@
import { Link as RouterLink } from '@tanstack/react-router';
import classNames from 'classnames';
import type { HTMLAttributes } from 'react';
import { appInfo } from '../../lib/appInfo';
import { Icon } from './Icon';
interface Props extends HTMLAttributes<HTMLAnchorElement> {
@@ -13,9 +14,15 @@ export function Link({ href, children, className, ...other }: Props) {
className = classNames(className, 'relative underline hover:text-violet-600');
if (isExternal) {
let finalHref = href;
if (href.startsWith('https://yaak.app')) {
const url = new URL(href);
url.searchParams.set('ref', appInfo.identifier);
finalHref = url.toString();
}
return (
<a
href={href}
href={finalHref}
target="_blank"
rel="noopener noreferrer"
className={classNames(className, 'pr-4 inline-flex items-center')}

View File

@@ -1,15 +0,0 @@
import { invokeCmd } from '../lib/tauri';
export interface AppInfo {
isDev: boolean;
version: string;
name: string;
appDataDir: string;
appLogDir: string;
}
export const appInfo = (await invokeCmd('cmd_metadata')) as AppInfo;
export function useAppInfo() {
return appInfo;
}

View File

@@ -1,13 +1,11 @@
import { useMutation } from '@tanstack/react-query';
import { InlineCode } from '../components/core/InlineCode';
import { showAlert } from '../lib/alert';
import { appInfo } from '../lib/appInfo';
import { minPromiseMillis } from '../lib/minPromiseMillis';
import { invokeCmd } from '../lib/tauri';
import { useAppInfo } from './useAppInfo';
export function useCheckForUpdates() {
const appInfo = useAppInfo();
return useMutation({
mutationKey: ['check_for_updates'],
mutationFn: async () => {

View File

@@ -1,11 +1,11 @@
import { setWindowTitle } from '@yaakapp-internal/mac-window';
import { useAtomValue } from 'jotai';
import { useEffect } from 'react';
import { appInfo } from '../lib/appInfo';
import { resolvedModelName } from '../lib/resolvedModelName';
import { useActiveEnvironment } from './useActiveEnvironment';
import { activeRequestAtom } from './useActiveRequest';
import { activeWorkspaceAtom } from './useActiveWorkspace';
import { appInfo } from './useAppInfo';
export function useSyncWorkspaceRequestTitle() {
const activeWorkspace = useAtomValue(activeWorkspaceAtom);

16
src-web/lib/appInfo.ts Normal file
View File

@@ -0,0 +1,16 @@
import { getIdentifier } from '@tauri-apps/api/app';
import { invokeCmd } from './tauri';
export interface AppInfo {
isDev: boolean;
version: string;
name: string;
appDataDir: string;
appLogDir: string;
identifier: string;
}
export const appInfo = {
...(await invokeCmd('cmd_metadata')),
identifier: await getIdentifier(),
} as AppInfo;