Skip to content

A free and open source instant messaging and VoIP chat app built for friends, groups, and communities.

TypeScript fluxerfluxerapp

feat(desktop): title windows with the last instance's name

Hampuse0fc45a0c9a6
diff --git a/fluxer_desktop/src/common/DesktopConfig.ts b/fluxer_desktop/src/common/DesktopConfig.ts
index 0d62c19eb..a76e66cb4 100644
--- a/fluxer_desktop/src/common/DesktopConfig.ts
+++ b/fluxer_desktop/src/common/DesktopConfig.ts
@@ -1,4 +1,3 @@
-import {isObjectLike as isRecord} from '@fluxer/record_utils/src/RecordGuards';
// SPDX-License-Identifier: AGPL-3.0-or-later
import fs from 'node:fs';
@@ -11,7 +10,9 @@ import {
isGlobalShortcutAction,
} from '@electron/common/GlobalShortcutActions';
import type {DesktopTroubleshootingSettings, DesktopWindowBehaviorSettings} from '@electron/common/Types';
+import {readInstanceProductNameReport} from '@fluxer/desktop_ipc/src/InstanceProductNameContract';
import {InstanceEndpointKind, normalizeInstanceEndpoint} from '@fluxer/instance_bootstrap/src/EndpointNormalization';
+import {isObjectLike as isRecord} from '@fluxer/record_utils/src/RecordGuards';
import log from 'electron-log';
export type {DesktopTroubleshootingSettings, DesktopWindowBehaviorSettings} from '@electron/common/Types';
@@ -27,10 +28,16 @@ interface DesktopConfig extends Record<string, unknown> {
theme_allowed_local_files?: Array<string>;
app_origin?: string;
preboot_theme?: string;
+ instance_product_names?: Array<PersistedInstanceProductName>;
global_shortcuts?: PersistedGlobalShortcutsSettings;
mac_screen_recording_requested?: boolean;
}
+interface PersistedInstanceProductName {
+ instance_key: string;
+ product_name: string;
+}
+
export type GlobalShortcutsPortalConsent = 'unset' | 'granted' | 'declined';
interface PersistedGlobalShortcutAction {
@@ -77,6 +84,7 @@ interface PersistedDesktopTroubleshootingSettings {
const INSTANCE_ENDPOINT_ARGS = ['--fluxer-instance'];
const PREBOOT_THEME_PATTERN = /^[a-z0-9][a-z0-9_-]{0,63}$/u;
+const INSTANCE_PRODUCT_NAMES_MAX_ENTRIES = 32;
let config: DesktopConfig = {};
let configPath: string | null = null;
@@ -210,7 +218,7 @@ function sanitizePersistedGlobalShortcutActions(value: unknown): Array<Persisted
return actions.length > 0 ? actions : undefined;
}
-export function sanitizePersistedGlobalShortcutsSettings(value: unknown): PersistedGlobalShortcutsSettings | undefined {
+function sanitizePersistedGlobalShortcutsSettings(value: unknown): PersistedGlobalShortcutsSettings | undefined {
if (!isRecord(value)) {
return undefined;
}
@@ -269,6 +277,23 @@ function sanitizePrebootTheme(value: unknown): string | undefined {
return typeof value === 'string' && PREBOOT_THEME_PATTERN.test(value) ? value : undefined;
}
+function sanitizeInstanceProductNames(value: unknown): Array<PersistedInstanceProductName> | undefined {
+ if (!Array.isArray(value)) {
+ return undefined;
+ }
+ const entries: Array<PersistedInstanceProductName> = [];
+ const seen = new Set<string>();
+ for (const item of value) {
+ if (!isRecord(item)) continue;
+ const report = readInstanceProductNameReport({instanceKey: item.instance_key, productName: item.product_name});
+ if (report === null || seen.has(report.instanceKey)) continue;
+ seen.add(report.instanceKey);
+ entries.push({instance_key: report.instanceKey, product_name: report.productName});
+ if (entries.length === INSTANCE_PRODUCT_NAMES_MAX_ENTRIES) break;
+ }
+ return entries.length > 0 ? entries : undefined;
+}
+
function sanitizeDesktopConfig(value: unknown): DesktopConfig {
if (!isRecord(value)) {
return {};
@@ -323,87 +348,60 @@ function sanitizeDesktopConfig(value: unknown): DesktopConfig {
} else {
delete nextConfig.preboot_theme;
}
+ const instanceProductNames = sanitizeInstanceProductNames(value.instance_product_names);
+ if (instanceProductNames) {
+ nextConfig.instance_product_names = instanceProductNames;
+ } else {
+ delete nextConfig.instance_product_names;
+ }
return nextConfig;
}
+function firstBoolean(fallback: boolean, ...values: ReadonlyArray<unknown>): boolean {
+ for (const value of values) {
+ if (typeof value === 'boolean') {
+ return value;
+ }
+ }
+ return fallback;
+}
+
function normalizeDesktopWindowBehaviorSettings(
- settings?: PersistedDesktopWindowBehaviorSettings | Partial<DesktopWindowBehaviorSettings>,
+ settings?: PersistedDesktopWindowBehaviorSettings & Partial<DesktopWindowBehaviorSettings>,
): DesktopWindowBehaviorSettings {
const defaults = getDefaultDesktopWindowBehaviorSettings();
- const normalizedSettings = settings as
- | (PersistedDesktopWindowBehaviorSettings & Partial<DesktopWindowBehaviorSettings>)
- | undefined;
const normalized = {
- showTrayIcon:
- typeof normalizedSettings?.showTrayIcon === 'boolean' ? normalizedSettings.showTrayIcon : defaults.showTrayIcon,
- coloredTrayIcon:
- typeof normalizedSettings?.coloredTrayIcon === 'boolean'
- ? normalizedSettings.coloredTrayIcon
- : defaults.coloredTrayIcon,
- darkTaskbarBadge:
- typeof normalizedSettings?.darkTaskbarBadge === 'boolean'
- ? normalizedSettings.darkTaskbarBadge
- : defaults.darkTaskbarBadge,
- minimizeToTray:
- typeof normalizedSettings?.minimizeToTray === 'boolean'
- ? normalizedSettings.minimizeToTray
- : typeof normalizedSettings?.minimizeToTrayV2 === 'boolean'
- ? normalizedSettings.minimizeToTrayV2
- : defaults.minimizeToTray,
- closeToTray:
- typeof normalizedSettings?.closeToTray === 'boolean'
- ? normalizedSettings.closeToTray
- : typeof normalizedSettings?.closeToTrayV2 === 'boolean'
- ? normalizedSettings.closeToTrayV2
- : defaults.closeToTray,
- startMinimized:
- typeof normalizedSettings?.startMinimized === 'boolean'
- ? normalizedSettings.startMinimized
- : defaults.startMinimized,
- useNativeTitleBar:
- typeof normalizedSettings?.useNativeTitleBar === 'boolean'
- ? normalizedSettings.useNativeTitleBar
- : defaults.useNativeTitleBar,
- activeUseNativeTitleBar:
- typeof normalizedSettings?.activeUseNativeTitleBar === 'boolean'
- ? normalizedSettings.activeUseNativeTitleBar
- : typeof normalizedSettings?.useNativeTitleBar === 'boolean'
- ? normalizedSettings.useNativeTitleBar
- : defaults.useNativeTitleBar,
- rememberWindowState:
- typeof normalizedSettings?.rememberWindowState === 'boolean'
- ? normalizedSettings.rememberWindowState
- : defaults.rememberWindowState,
- allowTransparency:
- typeof normalizedSettings?.allowTransparency === 'boolean'
- ? normalizedSettings.allowTransparency
- : defaults.allowTransparency,
- activeAllowTransparency:
- typeof normalizedSettings?.activeAllowTransparency === 'boolean'
- ? normalizedSettings.activeAllowTransparency
- : typeof normalizedSettings?.allowTransparency === 'boolean'
- ? normalizedSettings.allowTransparency
- : defaults.allowTransparency,
- smoothScrolling:
- typeof normalizedSettings?.smoothScrolling === 'boolean'
- ? normalizedSettings.smoothScrolling
- : defaults.smoothScrolling,
- activeSmoothScrolling:
- typeof normalizedSettings?.activeSmoothScrolling === 'boolean'
- ? normalizedSettings.activeSmoothScrolling
- : typeof normalizedSettings?.smoothScrolling === 'boolean'
- ? normalizedSettings.smoothScrolling
- : defaults.smoothScrolling,
- middleClickAutoscroll:
- typeof normalizedSettings?.middleClickAutoscroll === 'boolean'
- ? normalizedSettings.middleClickAutoscroll
- : defaults.middleClickAutoscroll,
- activeMiddleClickAutoscroll:
- typeof normalizedSettings?.activeMiddleClickAutoscroll === 'boolean'
- ? normalizedSettings.activeMiddleClickAutoscroll
- : typeof normalizedSettings?.middleClickAutoscroll === 'boolean'
- ? normalizedSettings.middleClickAutoscroll
- : defaults.middleClickAutoscroll,
+ showTrayIcon: firstBoolean(defaults.showTrayIcon, settings?.showTrayIcon),
+ coloredTrayIcon: firstBoolean(defaults.coloredTrayIcon, settings?.coloredTrayIcon),
+ darkTaskbarBadge: firstBoolean(defaults.darkTaskbarBadge, settings?.darkTaskbarBadge),
+ minimizeToTray: firstBoolean(defaults.minimizeToTray, settings?.minimizeToTray, settings?.minimizeToTrayV2),
+ closeToTray: firstBoolean(defaults.closeToTray, settings?.closeToTray, settings?.closeToTrayV2),
+ startMinimized: firstBoolean(defaults.startMinimized, settings?.startMinimized),
+ useNativeTitleBar: firstBoolean(defaults.useNativeTitleBar, settings?.useNativeTitleBar),
+ activeUseNativeTitleBar: firstBoolean(
+ defaults.useNativeTitleBar,
+ settings?.activeUseNativeTitleBar,
+ settings?.useNativeTitleBar,
+ ),
+ rememberWindowState: firstBoolean(defaults.rememberWindowState, settings?.rememberWindowState),
+ allowTransparency: firstBoolean(defaults.allowTransparency, settings?.allowTransparency),
+ activeAllowTransparency: firstBoolean(
+ defaults.allowTransparency,
+ settings?.activeAllowTransparency,
+ settings?.allowTransparency,
+ ),
+ smoothScrolling: firstBoolean(defaults.smoothScrolling, settings?.smoothScrolling),
+ activeSmoothScrolling: firstBoolean(
+ defaults.smoothScrolling,
+ settings?.activeSmoothScrolling,
+ settings?.smoothScrolling,
+ ),
+ middleClickAutoscroll: firstBoolean(defaults.middleClickAutoscroll, settings?.middleClickAutoscroll),
+ activeMiddleClickAutoscroll: firstBoolean(
+ defaults.middleClickAutoscroll,
+ settings?.activeMiddleClickAutoscroll,
+ settings?.middleClickAutoscroll,
+ ),
};
if (!normalized.showTrayIcon) {
normalized.minimizeToTray = false;
@@ -436,14 +434,11 @@ function normalizeDesktopTroubleshootingSettings(
): DesktopTroubleshootingSettings {
const defaults = getDefaultDesktopTroubleshootingSettings();
return {
- disableHardwareAcceleration:
- typeof settings?.disableHardwareAcceleration === 'boolean'
- ? settings.disableHardwareAcceleration
- : defaults.disableHardwareAcceleration,
- disableModuleUpdates:
- typeof settings?.disableModuleUpdates === 'boolean'
- ? settings.disableModuleUpdates
- : defaults.disableModuleUpdates,
+ disableHardwareAcceleration: firstBoolean(
+ defaults.disableHardwareAcceleration,
+ settings?.disableHardwareAcceleration,
+ ),
+ disableModuleUpdates: firstBoolean(defaults.disableModuleUpdates, settings?.disableModuleUpdates),
};
}
@@ -598,6 +593,27 @@ export function setPrebootTheme(theme: string): void {
saveDesktopConfig();
}
+export function getLaunchProductName(): string | null {
+ return sanitizeInstanceProductNames(config.instance_product_names)?.[0]?.product_name ?? null;
+}
+
+export function rememberInstanceProductName(report: unknown): void {
+ const accepted = readInstanceProductNameReport(report);
+ if (accepted === null) {
+ return;
+ }
+ const current = sanitizeInstanceProductNames(config.instance_product_names) ?? [];
+ const latest = current[0];
+ if (latest?.instance_key === accepted.instanceKey && latest.product_name === accepted.productName) {
+ return;
+ }
+ config.instance_product_names = [
+ {instance_key: accepted.instanceKey, product_name: accepted.productName},
+ ...current.filter((entry) => entry.instance_key !== accepted.instanceKey),
+ ].slice(0, INSTANCE_PRODUCT_NAMES_MAX_ENTRIES);
+ saveDesktopConfig();
+}
+
export function hasRequestedMacScreenRecording(): boolean {
return config.mac_screen_recording_requested === true;
}
diff --git a/fluxer_desktop/src/main/LocalAppFileRequestHandler.ts b/fluxer_desktop/src/main/LocalAppFileRequestHandler.ts
index 67c16f792..dc9fcc3ef 100644
--- a/fluxer_desktop/src/main/LocalAppFileRequestHandler.ts
+++ b/fluxer_desktop/src/main/LocalAppFileRequestHandler.ts
@@ -30,6 +30,7 @@ const METHOD_NOT_ALLOWED_HEADERS: Readonly<Record<string, string>> = Object.free
export interface LocalAppIndexContext {
readonly prebootTheme: string | null;
+ readonly productName: string | null;
readonly cleartextInstanceOrigins?: ReadonlyArray<string>;
}
@@ -146,6 +147,7 @@ export class DesktopLocalAppFileRequestHandler {
html: file.contents.toString('utf8'),
nonce,
prebootTheme: context.prebootTheme,
+ productName: context.productName,
});
headers.set(
'Content-Security-Policy',
diff --git a/fluxer_desktop/src/main/LocalAppIndexHTML.ts b/fluxer_desktop/src/main/LocalAppIndexHTML.ts
index 088b3b218..6a086c224 100644
--- a/fluxer_desktop/src/main/LocalAppIndexHTML.ts
+++ b/fluxer_desktop/src/main/LocalAppIndexHTML.ts
@@ -2,6 +2,7 @@
import {randomBytes} from 'node:crypto';
import {LOCAL_APP_STATIC_CDN_ENDPOINT_PLACEHOLDER} from '@electron/main/LocalAppStaticMetadata';
+import {readInstanceProductName} from '@fluxer/desktop_ipc/src/InstanceProductNameContract';
const CSP_NONCE_PLACEHOLDER = '{{CSP_NONCE_PLACEHOLDER}}';
const MEDIA_PRECONNECT_TAG = '<link rel="preconnect" href="{{MEDIA_ENDPOINT}}">';
@@ -10,11 +11,21 @@ const HTML_OPEN_TAG = /<html(?=[\s>])[^>]*>/iu;
const HTML_CLASS_ATTRIBUTE = /\sclass\s*=/iu;
const THEME_CLASS_PREFIX = 'theme-';
const SAFE_THEME_TOKEN = /^[a-z0-9][a-z0-9_-]{0,63}$/iu;
+const TITLE_ELEMENT = /<title(?=[\s>])[^>]*>[^<]*<\/title>/iu;
+const SERVED_PRODUCT_NAME_META = /<meta\s+name="apple-mobile-web-app-title"\s+content="[^"]*"/iu;
+const HTML_ESCAPES: Readonly<Record<string, string>> = Object.freeze({
+ '&': '&amp;',
+ '<': '&lt;',
+ '>': '&gt;',
+ '"': '&quot;',
+ "'": '&#39;',
+});
interface LocalAppIndexHTMLInput {
readonly html: string;
readonly nonce: string;
readonly prebootTheme: string | null;
+ readonly productName: string | null;
}
export function randomLocalAppCSPNonce(): string {
@@ -26,7 +37,22 @@ export function rewriteLocalAppIndexHTML(input: LocalAppIndexHTMLInput): string
.replaceAll(CSP_NONCE_PLACEHOLDER, input.nonce)
.replaceAll(LOCAL_APP_STATIC_CDN_ENDPOINT_PLACEHOLDER, '')
.replaceAll(MEDIA_PRECONNECT_TAG, '');
- return stampPrebootTheme(substituted, input.prebootTheme);
+ return stampProductName(stampPrebootTheme(substituted, input.prebootTheme), input.productName);
+}
+
+function escapeHTML(value: string): string {
+ return value.replace(/[&<>"']/gu, (character) => HTML_ESCAPES[character] ?? character);
+}
+
+function stampProductName(html: string, productName: string | null): string {
+ const name = readInstanceProductName(productName);
+ if (name === null) {
+ return html;
+ }
+ const escaped = escapeHTML(name);
+ return html
+ .replace(TITLE_ELEMENT, (element) => `${element.slice(0, element.indexOf('>') + 1)}${escaped}</title>`)
+ .replace(SERVED_PRODUCT_NAME_META, `<meta name="apple-mobile-web-app-title" content="${escaped}"`);
}
function stampPrebootTheme(html: string, theme: string | null): string {
diff --git a/fluxer_desktop/src/main/LocalAppProtocol.ts b/fluxer_desktop/src/main/LocalAppProtocol.ts
index 89d1310cb..689eced14 100644
--- a/fluxer_desktop/src/main/LocalAppProtocol.ts
+++ b/fluxer_desktop/src/main/LocalAppProtocol.ts
@@ -1,6 +1,7 @@
// SPDX-License-Identifier: AGPL-3.0-or-later
import {DESKTOP_APP_SCHEME} from '@electron/common/Constants';
+import {getLaunchProductName} from '@electron/common/DesktopConfig';
import {createChildLogger} from '@electron/common/Logger';
import {getDesktopOutboundHTTP} from '@electron/main/DesktopOutboundHTTP';
import {restoreRememberedRuntimePlan} from '@electron/main/DesktopRuntimeDiscovery';
@@ -23,28 +24,28 @@ const log = createChildLogger('LocalAppProtocol');
const THEME_STORAGE_KEY = 'theme';
-export class LocalAppProtocolSchemeRegistrationOrderError extends Error {
+class LocalAppProtocolSchemeRegistrationOrderError extends Error {
public constructor() {
super('Local app protocol scheme privileges must be registered before Electron app ready');
this.name = 'LocalAppProtocolSchemeRegistrationOrderError';
}
}
-export class LocalAppProtocolHandlerRegistrationOrderError extends Error {
+class LocalAppProtocolHandlerRegistrationOrderError extends Error {
public constructor() {
super('Local app protocol handler must be registered after Electron app ready');
this.name = 'LocalAppProtocolHandlerRegistrationOrderError';
}
}
-export class LocalAppProtocolHandlerOwnershipError extends Error {
+class LocalAppProtocolHandlerOwnershipError extends Error {
public constructor() {
super('Local app protocol already has a handler owned outside this runtime');
this.name = 'LocalAppProtocolHandlerOwnershipError';
}
}
-export class LocalAppProtocolShutdownAdmissionError extends Error {
+class LocalAppProtocolShutdownAdmissionError extends Error {
public constructor() {
super('Local app protocol is shutting down');
this.name = 'LocalAppProtocolShutdownAdmissionError';
@@ -135,7 +136,7 @@ export class DesktopLocalAppProtocol {
return this.runtimePlans.findPlanForRoute(runtimeKey);
}
- public planForRoute(runtimeKey: string): Promise<LocalAppRuntimePlan | null> {
+ private planForRoute(runtimeKey: string): Promise<LocalAppRuntimePlan | null> {
const known = this.runtimePlans.findPlanForRoute(runtimeKey);
if (known != null) {
return Promise.resolve(known);
@@ -190,9 +191,10 @@ export class DesktopLocalAppProtocol {
log.info('Deactivated the local app runtime plan');
}
- public getIndexContext(): LocalAppIndexContext {
+ private getIndexContext(): LocalAppIndexContext {
return {
prebootTheme: readPrebootTheme(),
+ productName: getLaunchProductName(),
cleartextInstanceOrigins: getDesktopOutboundHTTP().registeredCleartextOrigins(),
};
}
diff --git a/packages/desktop_ipc/src/InstanceProductNameContract.ts b/packages/desktop_ipc/src/InstanceProductNameContract.ts
new file mode 100644
index 000000000..59d4f582a
--- /dev/null
+++ b/packages/desktop_ipc/src/InstanceProductNameContract.ts
@@ -0,0 +1,43 @@
+// SPDX-License-Identifier: AGPL-3.0-or-later
+
+export const DESKTOP_INSTANCE_PRODUCT_NAME_CHANNEL = 'desktop-instance-product-name:report';
+
+const INSTANCE_PRODUCT_NAME_MAX_LENGTH = 80;
+const INSTANCE_PRODUCT_NAME_KEY_MAX_LENGTH = 2048;
+
+export interface InstanceProductNameReport {
+ readonly instanceKey: string;
+ readonly productName: string;
+}
+
+function containsControlCharacter(value: string): boolean {
+ for (let index = 0; index < value.length; index += 1) {
+ const code = value.charCodeAt(index);
+ if (code <= 0x1f || (code >= 0x7f && code <= 0x9f)) {
+ return true;
+ }
+ }
+ return false;
+}
+
+export function readInstanceProductName(value: unknown): string | null {
+ if (typeof value !== 'string') return null;
+ const trimmed = value.trim();
+ if (trimmed.length === 0 || trimmed.length > INSTANCE_PRODUCT_NAME_MAX_LENGTH) return null;
+ return containsControlCharacter(trimmed) ? null : trimmed;
+}
+
+function readInstanceProductNameKey(value: unknown): string | null {
+ if (typeof value !== 'string') return null;
+ if (value.length === 0 || value.length > INSTANCE_PRODUCT_NAME_KEY_MAX_LENGTH) return null;
+ return containsControlCharacter(value) ? null : value;
+}
+
+export function readInstanceProductNameReport(value: unknown): InstanceProductNameReport | null {
+ if (value == null || typeof value !== 'object' || Array.isArray(value)) return null;
+ const record = value as Record<string, unknown>;
+ const instanceKey = readInstanceProductNameKey(record.instanceKey);
+ const productName = readInstanceProductName(record.productName);
+ if (instanceKey === null || productName === null) return null;
+ return {instanceKey, productName};
+}
diff --git a/packages/desktop_ipc/src/NativeTitlebarShell.ts b/packages/desktop_ipc/src/NativeTitlebarShell.ts
index 19d0e6389..86ab67f41 100644
--- a/packages/desktop_ipc/src/NativeTitlebarShell.ts
+++ b/packages/desktop_ipc/src/NativeTitlebarShell.ts
@@ -15,9 +15,11 @@ export const NATIVE_TITLEBAR_CLASS = {
controlClose: 'fluxer-native-titlebar__control--close',
} as const;
-export const NATIVE_TITLEBAR_WORDMARK_VIEWBOX = '0 0 1374 366';
+const NATIVE_TITLEBAR_DEFAULT_PRODUCT_NAME = 'Fluxer';
-export const NATIVE_TITLEBAR_WORDMARK_PATHS: ReadonlyArray<string> = [
+const NATIVE_TITLEBAR_WORDMARK_VIEWBOX = '0 0 1374 366';
+
+const NATIVE_TITLEBAR_WORDMARK_PATHS: ReadonlyArray<string> = [
'M0 358.4V20.48h82.944V358.4H0Zm41.472-120.32v-67.584h172.032v67.584H41.472Zm0-148.48V20.48h189.44V89.6H41.472ZM258.951 358.4V0h82.944v358.4h-82.944ZM462.92 365.568c-29.35 0-51.2-10.24-65.536-30.72-13.995-20.48-20.992-51.883-20.992-94.208V88.064h82.948v151.552c0 19.797 2.73 33.621 8.19 41.472 5.8 7.851 13.99 11.776 24.57 11.776 7.51 0 14.34-1.877 20.48-5.632 6.49-4.096 12.12-10.069 16.9-17.92 4.78-8.192 8.36-18.603 10.75-31.232 2.73-12.629 4.1-27.819 4.1-45.568V88.064h82.94V358.4h-70.65V252.928h-3.59c-2.05 26.283-6.65 47.787-13.82 64.512-7.17 16.384-17.07 28.501-29.7 36.352-12.63 7.851-28.16 11.776-46.59 11.776ZM647.569 358.4l84.99-135.68-83.97-134.656h96.26l39.42 87.552h2.56l38.4-87.552h95.23l-81.4 134.656 82.43 135.68h-97.79l-37.38-86.016h-2.05l-41.47 86.016h-95.23Z',
'M1045.96 365.568c-25.6 0-47.101-3.584-64.511-10.752-17.06-7.509-30.89-17.579-41.47-30.208-10.58-12.971-18.26-27.648-23.04-44.032-4.44-16.384-6.66-33.621-6.66-51.712 0-19.456 2.39-38.059 7.17-55.808 5.12-17.749 12.8-33.451 23.04-47.104 10.58-13.995 24.07-24.917 40.45-32.768 16.73-8.192 36.691-12.288 59.901-12.288s43.01 4.096 59.4 12.288c16.72 7.851 30.03 18.944 39.93 33.28 9.9 14.336 16.22 30.891 18.95 49.664 3.07 18.773 2.73 39.083-1.03 60.928l-196.091 3.072v-45.056l132.601-2.56-10.75 26.112c2.05-15.701 1.71-28.843-1.02-39.424-2.39-10.923-7-19.115-13.83-24.576-6.82-5.803-16.21-8.704-28.16-8.704-12.63 0-22.69 3.243-30.2 9.728-7.51 6.485-12.801 15.701-15.881 27.648-3.07 11.605-4.6 25.429-4.6 41.472 0 27.648 4.6 47.787 13.821 60.416 9.22 12.629 23.38 18.944 42.5 18.944 8.19 0 15.01-1.024 20.48-3.072 5.46-2.048 9.89-4.949 13.31-8.704 3.41-4.096 5.8-8.875 7.17-14.336 1.36-5.803 1.87-12.288 1.53-19.456l75.78 4.096c1.02 11.264-.17 22.869-3.59 34.816-3.07 11.947-9.04 23.04-17.92 33.28-8.87 10.24-21.33 18.603-37.37 25.088-15.7 6.485-35.67 9.728-59.91 9.728ZM1193.45 358.4V88.0639h71.68V195.584h4.1c2.05-28.672 5.97-51.2 11.77-67.584 6.15-16.725 13.66-28.5011 22.53-35.3281 9.22-7.168 19.46-10.752 30.72-10.752 6.15 0 12.46.853 18.95 2.56 6.82 1.707 13.48 4.437 19.96 8.192l-4.09 92.1601c-7.51-4.437-14.85-7.68-22.02-9.728-7.17-2.389-13.99-3.584-20.48-3.584-10.92 0-20.14 3.072-27.65 9.216-7.51 6.144-13.31 15.189-17.4 27.136-3.76 11.947-5.64 26.453-5.64 43.52V358.4h-82.43Z',
];
@@ -34,21 +36,38 @@ export const NATIVE_TITLEBAR_CONTROL_ICON_PATH = {
export type NativeTitlebarControlIconName = keyof typeof NATIVE_TITLEBAR_CONTROL_ICON_PATH;
-export function nativeTitlebarControlIconSvg(icon: NativeTitlebarControlIconName): string {
+function nativeTitlebarControlIconSvg(icon: NativeTitlebarControlIconName): string {
return (
'<svg viewBox="0 0 256 256" fill="currentColor" xmlns="http://www.w3.org/2000/svg">' +
`<path d="${NATIVE_TITLEBAR_CONTROL_ICON_PATH[icon]}"/></svg>`
);
}
-export function nativeTitlebarWordmarkSvg(className: string = NATIVE_TITLEBAR_CLASS.wordmark): string {
+function nativeTitlebarWordmarkSvg(className: string = NATIVE_TITLEBAR_CLASS.wordmark): string {
const paths = NATIVE_TITLEBAR_WORDMARK_PATHS.map((d) => `<path fill="currentColor" d="${d}"/>`).join('');
return (
- `<svg class="${className}" role="img" aria-label="Fluxer" xmlns="http://www.w3.org/2000/svg" ` +
+ `<svg class="${className}" role="img" aria-label="${NATIVE_TITLEBAR_DEFAULT_PRODUCT_NAME}" xmlns="http://www.w3.org/2000/svg" ` +
`fill="none" viewBox="${NATIVE_TITLEBAR_WORDMARK_VIEWBOX}">${paths}</svg>`
);
}
+function escapeHtml(value: string): string {
+ return value
+ .replaceAll('&', '&amp;')
+ .replaceAll('<', '&lt;')
+ .replaceAll('>', '&gt;')
+ .replaceAll('"', '&quot;')
+ .replaceAll("'", '&#39;');
+}
+
+function nativeTitlebarProductNameHtml(productName: string): string {
+ const name = escapeHtml(productName);
+ return (
+ `<span class="${NATIVE_TITLEBAR_CLASS.wordmark}" role="img" dir="auto" aria-label="${name}" ` +
+ `style="align-items:center;display:inline-flex;font-weight:800;line-height:1">${name}</span>`
+ );
+}
+
interface StartupControlLabels {
readonly minimize: string;
readonly maximize: string;
@@ -74,7 +93,7 @@ function controlButtonHtml(
);
}
-export function nativeTitlebarControlsHtml(labels: StartupControlLabels = DEFAULT_STARTUP_CONTROL_LABELS): string {
+function nativeTitlebarControlsHtml(labels: StartupControlLabels = DEFAULT_STARTUP_CONTROL_LABELS): string {
return (
`<div class="${NATIVE_TITLEBAR_CLASS.controls}">` +
controlButtonHtml('minimize', 'minimize', labels.minimize) +
@@ -84,8 +103,15 @@ export function nativeTitlebarControlsHtml(labels: StartupControlLabels = DEFAUL
);
}
-export function buildNativeTitlebarStartupHtml(layout: NativeTitlebarLayout): string {
- const brand = `<div class="${NATIVE_TITLEBAR_CLASS.left}">${nativeTitlebarWordmarkSvg()}</div>`;
+export function buildNativeTitlebarStartupHtml(
+ layout: NativeTitlebarLayout,
+ productName: string | null = null,
+): string {
+ const mark =
+ productName === null || productName === NATIVE_TITLEBAR_DEFAULT_PRODUCT_NAME
+ ? nativeTitlebarWordmarkSvg()
+ : nativeTitlebarProductNameHtml(productName);
+ const brand = `<div class="${NATIVE_TITLEBAR_CLASS.left}">${mark}</div>`;
const spacer = `<div class="${NATIVE_TITLEBAR_CLASS.spacer}"></div>`;
if (layout === 'macos') {
return `${spacer}${brand}`;