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
2 changes: 1 addition & 1 deletion build/splash.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width,initial-scale=1" />
<title></title>
<title>DSH Desktop</title>
<style>
:root { color-scheme: light; }
* { box-sizing: border-box; }
Expand Down
4 changes: 2 additions & 2 deletions src/main/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1125,7 +1125,7 @@ function createWindow(): BrowserWindow {
minWidth: 900,
minHeight: 640,
show: false,
title: '',
title: app.getName(),
icon: desktopIconPath(),
...(process.platform === 'darwin' ? {
titleBarStyle: 'hiddenInset' as const,
Expand Down Expand Up @@ -1183,7 +1183,7 @@ function createWindow(): BrowserWindow {
})
window.on('page-title-updated', (event) => {
event.preventDefault()
window.setTitle('')
window.setTitle(app.getName())
})
window.webContents.on('console-message', (details) => {
if (details.level !== 'error') return
Expand Down
42 changes: 42 additions & 0 deletions test/main-window-title.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { readFile } from 'node:fs/promises'
import { describe, expect, it } from 'vitest'

async function windowSource(): Promise<string> {
const main = await readFile('src/main/index.ts', 'utf8')
const start = main.indexOf('function createWindow(): BrowserWindow {')
expect(start).toBeGreaterThanOrEqual(0)
return main.slice(start, main.indexOf('\nasync function openHarness(', start))
}

// createWindow lives in the application entry point, which starts Electron on import.
describe('main window title', () => {
it('uses the configured app name before any page loads', async () => {
const source = await windowSource()

expect(source).toContain('title: app.getName()')
expect(source).not.toMatch(/title:\s*(['"])\1/)
})

it('keeps the app name when renderer pages update their title', async () => {
const source = await windowSource()

expect(source).toMatch(
/window\.on\('page-title-updated', \(event\) => \{\s*event\.preventDefault\(\)\s*window\.setTitle\(app\.getName\(\)\)\s*\}\)/
)
expect(source).not.toMatch(/\.setTitle\((['"])\1\)/)
})

it('retains hidden native captions on macOS and Windows', async () => {
const source = await windowSource()

expect(source).toMatch(/process\.platform === 'darwin' \? \{\s*titleBarStyle: 'hiddenInset'/)
expect(source).toMatch(/isWindows\s*\? \{\s*titleBarStyle: 'hidden'/)
expect(source).toContain('titleBarOverlay: windowsTitleBarOverlay(')
})

it('does not give the startup page an empty document title', async () => {
const splash = await readFile('build/splash.html', 'utf8')

expect(splash).toContain('<title>DSH Desktop</title>')
})
})