Skip to content
Merged
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
5 changes: 5 additions & 0 deletions .changeset/simpler-settings.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"ewiz": minor
---

**Settings are easier to find your way around.** The seven tabs across the top are now a sidebar grouped into Battery, Power and eWiz. Each pane starts with one plain sentence about what it's for and a link to a page on ewiz.app that explains every setting. Settings most people never need (sleep enforcement, discharge, the MagSafe LED, charge power, AI agents, network profiles and the like) are hidden until you turn on **Advanced settings**, so a new Mac owner first sees the handful that matter. Some groups have clearer names, for example "Battery health" instead of "Long-term care" and "Heat protection" instead of "Heat". **Donate** now goes straight to the pay-what-you-want checkout.
6 changes: 4 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,10 @@ jobs:
draft: false
make_latest: true

# Point the public in-app update feeds at this release: appcast.xml (Sparkle,
# SUFeedURL) and appcast.json (the old updater in copies up to 0.18.5). Done inline
# Legacy feeds for installed copies up to 0.19.10, which read them from
# stroke-app/ewiz-releases: appcast.xml (Sparkle) and appcast.json (the old updater
# in copies up to 0.18.5). Newer builds read https://ewiz.app/appcast.xml, which
# serves this release's own asset. Remove this step once old copies have updated. Done inline
# here rather than in a separate `release: published` workflow because releases
# published by the default GITHUB_TOKEN do NOT emit an event that can
# trigger another workflow — so that feed workflow never fired on its own.
Expand Down
6 changes: 5 additions & 1 deletion apps/macos/DISTRIBUTION.md
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,11 @@ for Updates…" and the menu's Update banner. Sparkle's window shows the check,
the download's progress and the install, then relaunches the new version.

- The app reads `SUFeedURL` from Info.plist (written by `scripts/package-app.sh`):
`raw.githubusercontent.com/stroke-app/ewiz-releases/main/appcast.xml`.
`https://ewiz.app/appcast.xml`. The website (`apps/web/src/routes/appcast[.]xml.ts`)
proxies the `appcast.xml` attached to the latest GitHub release, so publishing the
release is all it takes. Copies up to 0.19.10 still read
`raw.githubusercontent.com/stroke-app/ewiz-releases/main/appcast.xml`, which the
release workflow keeps updating until those copies have moved on.
- **Trust** is the EdDSA key, not a Developer ID: `SUPublicEDKey` in Info.plist is
`UpdateSignature.publicKeyBase64`, and every DMG in the feed carries that key's
`sparkle:edSignature`, made by `licensetool sign-update` from the
Expand Down
5 changes: 3 additions & 2 deletions apps/macos/Sources/EWizKit/EWizLinks.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@ public enum EWizLinks {
/// one. The license window and the "isn't linked to a Mac" error send people here.
public static let license = URL(string: "https://ewiz.app/license")!

/// Settings › About › Donate.
public static let donate = URL(string: "https://ewiz.app/donate")!
/// Settings › About › Donate: the website redirects this to the pay-what-you-want
/// checkout, so the checkout link can change without an app release.
public static let donate = URL(string: "https://ewiz.app/donate/checkout")!

/// Where Contact Support and the license window's help link write to.
public static let supportEmail = "hello@ewiz.app"
Expand Down
816 changes: 495 additions & 321 deletions apps/macos/Sources/eWiz/SettingsView.swift

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion apps/macos/scripts/package-app.sh
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ strip -x "$CONTENTS/MacOS/ewiz-mcp"
# the proof Sparkle relies on; with it valid, Sparkle also accepts a change of code-signing
# identity, which is what carries ad-hoc installs over to the self-signed certificate.
BUILD_NUMBER="$("$REPO_DIR/scripts/build-number.sh" "$VERSION")"
SPARKLE_FEED="https://raw.githubusercontent.com/stroke-app/ewiz-releases/main/appcast.xml"
SPARKLE_FEED="https://ewiz.app/appcast.xml"
# Read from the source so the key the app trusts and the key licensetool checks its
# signatures against are one constant.
SPARKLE_PUBLIC_KEY="$(sed -n 's/.*publicKeyBase64 = "\([A-Za-z0-9+\/=]*\)".*/\1/p' "$REPO_DIR/Sources/EWizKit/UpdateSignature.swift")"
Expand Down
19 changes: 12 additions & 7 deletions apps/web/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,25 @@
# Base URL of the site (used by auth + links)
VITE_BASE_URL="http://localhost:3000"

# Postgres connection string
DATABASE_URL="postgres://user:password@localhost:5432/battlify"

# Better Auth — generate with: pnpm auth:secret
# Better Auth — generate with: bun run auth:secret
BETTER_AUTH_SECRET="replace-with-a-long-random-string"

# GitHub OAuth (https://github.com/settings/developers)
GITHUB_CLIENT_ID=""
GITHUB_CLIENT_SECRET=""
# Sign-in is Google and Apple only.
# Redirect URI: <VITE_BASE_URL>/api/auth/callback/<google|apple>

# Google OAuth (https://console.cloud.google.com/apis/credentials)
GOOGLE_CLIENT_ID=""
GOOGLE_CLIENT_SECRET=""

# Sign in with Apple (https://developer.apple.com/account/resources)
# Services ID, Team ID, and the Key ID + .p8 of a "Sign in with Apple" key.
# APPLE_PRIVATE_KEY: the .p8 contents on one line, newlines written as \n.
APPLE_CLIENT_ID=""
APPLE_TEAM_ID=""
APPLE_KEY_ID=""
APPLE_PRIVATE_KEY=""
APPLE_APP_BUNDLE_IDENTIFIER=""

# Dodo Payments (https://app.dodopayments.com)
DODO_PAYMENTS_API_KEY=""
DODO_PAYMENTS_WEBHOOK_SECRET=""
Expand Down
1 change: 1 addition & 0 deletions apps/web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
"cnfast": "0.0.8",
"dodopayments": "^2.40.1",
"drizzle-orm": "0.45.2",
"jose": "^6.1.3",
"lucide-react": "1.22.0",
"motion": "^12.42.2",
"postgres": "3.4.9",
Expand Down
17 changes: 4 additions & 13 deletions apps/web/src/components/auth/sign-in-methods.tsx
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
import { SiGithub, SiGoogle } from "@icons-pack/react-simple-icons";
import { SiApple, SiGoogle } from "@icons-pack/react-simple-icons";
import { useMutation, useQuery } from "@tanstack/react-query";
import { CheckIcon, MailIcon } from "lucide-react";
import { CheckIcon } from "lucide-react";
import { toast } from "sonner";

import { Button } from "#/components/ui/button";
import { authClient } from "#/lib/auth/auth-client";
import { $getSocialProviders } from "#/lib/auth/functions";

const PROVIDERS = [
{ id: "github", label: "GitHub", icon: SiGithub },
{ id: "google", label: "Google", icon: SiGoogle },
{ id: "apple", label: "Apple", icon: SiApple },
] as const;

/**
* Lists how this account can sign in and lets the user connect the other
* provider, so GitHub and Google both open the same account and license.
* provider, so Google and Apple both open the same account and license.
*/
export function SignInMethods() {
const { data: accounts } = useQuery({
Expand Down Expand Up @@ -76,15 +76,6 @@ export function SignInMethods() {
)}
</li>
))}
<li className="flex items-center justify-between py-2">
<span className="flex items-center gap-2.5 text-sm">
<MailIcon className="size-4" aria-hidden />
Email and password
</span>
<span className="text-xs text-muted-foreground">
{linked.has("credential") ? "Set" : "Not set"}
</span>
</li>
</ul>
</section>
);
Expand Down
8 changes: 7 additions & 1 deletion apps/web/src/components/landing/landing-data.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
export const LINKS = {
github: "https://github.com/stroke-app/ewiz",
/** This website's source. */
siteSource: "https://github.com/stroke-app/ewiz-releases",
siteSource: "https://github.com/stroke-app/ewiz/tree/main/apps/web",
releases: "https://github.com/stroke-app/ewiz/releases",
feedback: "https://github.com/stroke-app/ewiz/issues",
/**
* Pay-what-you-want donation checkout (Dodo). Every Donate button goes through
* /donate/checkout, which redirects here, so the target can change without an
* app release.
*/
donateCheckout: "https://checkout.dodopayments.com/session/cks_0NsOth7ruTtl42VyOoxxM",
x: "https://x.com/broisnischal",
stroke: "https://stroke.click",
site: "https://nischal-dahal.com.np",
Expand Down
14 changes: 11 additions & 3 deletions apps/web/src/components/landing/landing-page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,14 @@ function Features({
Pick a feature to see where it lives in the app. The window is clickable: switch tabs,
flip a switch, try a menu bar style.
</p>
<p className="mt-2 text-[15px]">
<Link
to="/features"
className="text-muted-foreground underline underline-offset-4 transition-colors hover:text-foreground"
>
See every setting explained
</Link>
</p>

<div className="mt-10 grid gap-8 lg:grid-cols-[minmax(0,20rem)_minmax(0,1fr)] lg:gap-14">
<ol className="flex flex-col self-start border-l border-border">
Expand Down Expand Up @@ -724,12 +732,12 @@ function ClosingCta() {
</div>
<p className="mt-4 text-sm text-muted-foreground">
Already using it and want to help?{" "}
<Link
to="/donate"
<a
href="/donate/checkout"
className="text-foreground underline decoration-border underline-offset-4 transition-colors hover:decoration-foreground"
>
Donate
</Link>
</a>
</p>
</Container>
</section>
Expand Down
7 changes: 2 additions & 5 deletions apps/web/src/components/sign-in-social-button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,7 @@ interface SocialLoginButtonProps {
}

export function SignInSocialButton(props: SocialLoginButtonProps) {
const providerLabel =
props.provider === "github"
? "GitHub"
: props.provider.charAt(0).toUpperCase() + props.provider.slice(1);
const providerLabel = props.provider.charAt(0).toUpperCase() + props.provider.slice(1);

const mutation = useMutation({
mutationFn: async () =>
Expand All @@ -41,7 +38,7 @@ export function SignInSocialButton(props: SocialLoginButtonProps) {
onClick={() => mutation.mutate()}
>
{props.icon}
{providerLabel}
Continue with {providerLabel}
</Button>
);
}
9 changes: 7 additions & 2 deletions apps/web/src/components/site/site-shell.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,13 @@ export function SiteHeader() {
<AppIcon className="size-8" />
</Link>
<nav className="flex items-center gap-3 text-sm text-muted-foreground sm:gap-6 sm:text-[15px]">
<Link to="/features" className={NAV_LINK}>
Features
</Link>
<Link to="/pricing" className={NAV_LINK}>
Pricing
</Link>
<Link to="/changelog" className={NAV_LINK}>
<Link to="/changelog" className={cn(NAV_LINK, "hidden sm:inline")}>
Changelog
</Link>
<Link to="/blog" className={cn(NAV_LINK, "hidden sm:inline")}>
Expand All @@ -72,6 +75,7 @@ type FooterLink = { label: string } & (
| {
to:
| "/"
| "/features"
| "/pricing"
| "/download"
| "/changelog"
Expand All @@ -89,11 +93,12 @@ const FOOTER_COLUMNS: Array<{ title: string; links: FooterLink[] }> = [
{
title: "Product",
links: [
{ label: "Features", to: "/features" },
{ label: "Pricing", to: "/pricing" },
{ label: "Download", to: "/download" },
{ label: "Changelog", to: "/changelog" },
{ label: "Blog", to: "/blog" },
{ label: "Donate", to: "/donate" },
{ label: "Donate", href: "/donate/checkout" },
],
},
{
Expand Down
13 changes: 10 additions & 3 deletions apps/web/src/env/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,18 @@ export const env = createEnv({
VITE_BASE_URL: z.url().default("http://localhost:3000"),
BETTER_AUTH_SECRET: z.string().min(1),

// OAuth2 providers, optional, update as needed
GITHUB_CLIENT_ID: z.string().optional(),
GITHUB_CLIENT_SECRET: z.string().optional(),
// Sign-in providers (the only ways in). Each is optional so the worker
// boots before it's set up; the login page hides providers that aren't.
GOOGLE_CLIENT_ID: z.string().optional(),
GOOGLE_CLIENT_SECRET: z.string().optional(),
// Sign in with Apple: the Services ID, your Team ID, and the Key ID + .p8
// private key of a "Sign in with Apple" key. The client secret is a JWT
// the server signs from these (see lib/auth/apple.ts).
APPLE_CLIENT_ID: z.string().optional(),
APPLE_TEAM_ID: z.string().optional(),
APPLE_KEY_ID: z.string().optional(),
APPLE_PRIVATE_KEY: z.string().optional(),
APPLE_APP_BUNDLE_IDENTIFIER: z.string().optional(),

// Dodo Payments — https://better-auth.com/docs/plugins/dodopayments
// Optional so the app still boots before you paste real values in.
Expand Down
28 changes: 28 additions & 0 deletions apps/web/src/lib/auth/apple.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import "@tanstack/react-start/server-only";
import { importPKCS8, SignJWT } from "jose";

import { env } from "#/env/server";

export const appleConfigured = Boolean(
env.APPLE_CLIENT_ID && env.APPLE_TEAM_ID && env.APPLE_KEY_ID && env.APPLE_PRIVATE_KEY,
);

/**
* Apple wants the OAuth client secret as an ES256 JWT signed with the .p8 key,
* valid for at most six months. https://better-auth.com/docs/authentication/apple
*
* The key may be stored with literal "\n"s (one-line secrets), so restore them.
*/
export async function appleClientSecret(): Promise<string> {
const pem = env.APPLE_PRIVATE_KEY!.replace(/\\n/g, "\n").trim();
const key = await importPKCS8(pem, "ES256");
const now = Math.floor(Date.now() / 1000);
return new SignJWT({})
.setProtectedHeader({ alg: "ES256", kid: env.APPLE_KEY_ID! })
.setIssuer(env.APPLE_TEAM_ID!)
.setSubject(env.APPLE_CLIENT_ID!)
.setAudience("https://appleid.apple.com")
.setIssuedAt(now)
.setExpirationTime(now + 180 * 24 * 60 * 60)
.sign(key);
}
46 changes: 23 additions & 23 deletions apps/web/src/lib/auth/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { tanstackStartCookies } from "better-auth/tanstack-start";
import { eq } from "drizzle-orm";

import { env } from "#/env/server";
import { appleClientSecret, appleConfigured } from "#/lib/auth/apple";
import { db } from "#/lib/db";
import * as schema from "#/lib/db/schema";
import { issueLicenseForUser } from "#/lib/license/service";
Expand All @@ -22,18 +23,20 @@ export const auth = betterAuth({
baseURL: env.VITE_BASE_URL,
// The old host stays attached for already-installed apps; accept auth
// requests from it too so sign-in doesn't fail on origin checks there.
trustedOrigins: [env.VITE_BASE_URL, "https://battlify.discerns.app"],
// Apple posts the OAuth callback from appleid.apple.com (form_post).
trustedOrigins: [env.VITE_BASE_URL, "https://battlify.discerns.app", "https://appleid.apple.com"],
// https://better-auth.com/docs/concepts/users-accounts#account-linking
// One person, one account: GitHub, Google and email sign-ins with the same
// address resolve to the same user (and the same license). Both providers
// verify the email they return, so they are trusted to link.
// One person, one account: Google and Apple sign-ins with the same address
// resolve to the same user (and the same license). Both verify the email they
// return, so they are trusted to link. Accounts made with the old email/password
// sign-in are reached the same way: sign in with Google or Apple on that address.
account: {
accountLinking: {
enabled: true,
trustedProviders: ["google", "github"],
// Email/password sign-ups are never verified here (no verification
// mail is sent), so the default `true` makes every Google/GitHub
// sign-in for an existing account fail with "account_not_linked".
trustedProviders: ["google", "apple"],
// Old email/password accounts were never verified (no verification
// mail was sent), so the default `true` would make every Google/Apple
// sign-in for one of them fail with "account_not_linked".
// Linking marks the email verified, since the provider vouched for it.
requireLocalEmailVerified: false,
},
Expand Down Expand Up @@ -121,17 +124,9 @@ export const auth = betterAuth({
},

// https://better-auth.com/docs/concepts/oauth
// Only register a provider when its credentials are actually configured,
// so the worker still boots when GitHub/Google aren't set up yet.
// Google and Apple are the only ways in. A provider is registered only when its
// credentials are configured, so the worker still boots without them.
socialProviders: {
...(env.GITHUB_CLIENT_ID && env.GITHUB_CLIENT_SECRET
? {
github: {
clientId: env.GITHUB_CLIENT_ID,
clientSecret: env.GITHUB_CLIENT_SECRET,
},
}
: {}),
...(env.GOOGLE_CLIENT_ID && env.GOOGLE_CLIENT_SECRET
? {
google: {
Expand All @@ -140,11 +135,16 @@ export const auth = betterAuth({
},
}
: {}),
},

// https://better-auth.com/docs/authentication/email-password
emailAndPassword: {
enabled: true,
...(appleConfigured
? {
// Async so the client-secret JWT is signed when auth initialises.
apple: async () => ({
clientId: env.APPLE_CLIENT_ID!,
clientSecret: await appleClientSecret(),
appBundleIdentifier: env.APPLE_APP_BUNDLE_IDENTIFIER,
}),
}
: {}),
},

experimental: {
Expand Down
3 changes: 2 additions & 1 deletion apps/web/src/lib/auth/functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { createServerFn, createServerOnlyFn } from "@tanstack/react-start";
import { getRequest, setResponseHeader } from "@tanstack/react-start/server";

import { env } from "#/env/server";
import { appleConfigured } from "#/lib/auth/apple";
import { auth } from "#/lib/auth/auth";

/**
Expand All @@ -22,8 +23,8 @@ export const $getUser = createServerFn({ method: "GET" }).handler(async () => {
* instead of offering a button that fails with "Provider not found".
*/
export const $getSocialProviders = createServerFn({ method: "GET" }).handler(() => ({
github: Boolean(env.GITHUB_CLIENT_ID && env.GITHUB_CLIENT_SECRET),
google: Boolean(env.GOOGLE_CLIENT_ID && env.GOOGLE_CLIENT_SECRET),
apple: appleConfigured,
}));

interface GetUserServerQuery {
Expand Down
Loading
Loading