Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 58 additions & 0 deletions apps/native/src/components/widget/settings/general-tab.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import { fireEvent, render, screen } from "@testing-library/react";
import { open } from "@tauri-apps/plugin-shell";
import { describe, expect, it, vi } from "vitest";
import { GeneralTab } from "./general-tab";

vi.mock("@tauri-apps/api/app", () => ({
getVersion: vi.fn().mockResolvedValue("0.0.0-test"),
}));

vi.mock("@tauri-apps/plugin-shell", () => ({
open: vi.fn().mockResolvedValue(undefined),
}));

vi.mock("@/components/widget/controls/directory-picker", () => ({
DirectoryPicker: ({ label }: { label: string }) => <div>{label}</div>,
}));

vi.mock("@/components/widget/controls/bootstrap-config", () => ({
BootstrapConfig: ({ label }: { label: string }) => <div>{label}</div>,
}));

vi.mock("@/tauri-api", () => ({
darwinAPI: {
ui: {
setPrefs: vi.fn().mockResolvedValue(undefined),
},
},
}));

const sendDiagnosticsField = {
state: { value: false },
handleChange: vi.fn(),
};

describe("GeneralTab", () => {
it("opens the Support Nixmac page from settings", async () => {
render(
<GeneralTab
configDir="/Users/test/.darwin"
handleRefreshHosts={vi.fn()}
hasFlake
host="Test-MacBook"
hosts={["Test-MacBook"]}
saveHost={vi.fn()}
sendDiagnosticsField={sendDiagnosticsField as never}
setSettingsOpen={vi.fn()}
/>,
);

await screen.findByText("0.0.0-test");
expect(screen.getByText("Support Nixmac")).toBeInTheDocument();
expect(screen.getByText("Help fund continued development.")).toBeInTheDocument();

fireEvent.click(screen.getByRole("button", { name: "Open Support Nixmac" }));

expect(open).toHaveBeenCalledWith("https://nixmac.com/support");
});
});
43 changes: 34 additions & 9 deletions apps/native/src/components/widget/settings/general-tab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ import { getWebSiteUrl } from "@/lib/env";
import { useWidgetStore } from "@/stores/widget-store";
import { darwinAPI } from "@/tauri-api";
import { getVersion } from "@tauri-apps/api/app";
import { open } from '@tauri-apps/plugin-shell';
import { open } from "@tauri-apps/plugin-shell";
import type { AnyFieldApi } from "@tanstack/react-form";
import { ExternalLink } from "lucide-react";
import { useEffect, useRef, useState } from "react";

interface GeneralTabProps {
Expand All @@ -29,6 +30,18 @@ interface GeneralTabProps {
sendDiagnosticsField: AnyFieldApi;
}

// Support should always land on the public website, even in local app builds.
const SUPPORT_NIXMAC_URL = "https://nixmac.com/support";

async function openExternalUrl(url: string) {
try {
await open(url);
} catch (error) {
console.warn("Failed to open external URL with Tauri shell; falling back to browser window.", error);
window.open(url, "_blank");
}
}

export function GeneralTab({
configDir,
hasFlake,
Expand Down Expand Up @@ -87,15 +100,9 @@ export function GeneralTab({
<div>
<button
type="button"
onClick={async () => {
onClick={() => {
const base = getWebSiteUrl().replace(/\/$/, "");
const url = `${base}/privacy-policy`;
try {
await open(url);
} catch (err) {
// Fallback to window.open if Tauri shell fails for some reason (e.g. during direct development in the web app)
window.open(url, "_blank");
}
openExternalUrl(`${base}/privacy-policy`);
}}
className="mt-2 text-xs text-zinc-400 underline hover:text-zinc-200"
>
Expand All @@ -120,6 +127,24 @@ export function GeneralTab({
/>
</div>

<div className="flex items-center justify-between rounded-lg border border-border p-3">
<div className="space-y-0.5">
<div className="font-medium text-sm">Support Nixmac</div>
<div className="text-muted-foreground text-xs">
Help fund continued development.
</div>
</div>
<Button
aria-label="Open Support Nixmac"
onClick={() => openExternalUrl(SUPPORT_NIXMAC_URL)}
size="sm"
variant="outline"
>
Open
<ExternalLink className="h-3.5 w-3.5" />
</Button>
</div>

<VersionRow />
</div>
</div>
Expand Down
Loading