forked from facebook/react-native-devtools-frontend
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFuseboxWindowTitleManager.ts
More file actions
51 lines (43 loc) · 1.37 KB
/
FuseboxWindowTitleManager.ts
File metadata and controls
51 lines (43 loc) · 1.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
// Copyright (c) Meta Platforms, Inc. and affiliates.
// Copyright 2024 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
export class FuseboxWindowTitleManager {
static #instance: FuseboxWindowTitleManager;
#appDisplayName?: string;
#deviceName?: string;
#suffix?: string;
private constructor() {}
static instance(): FuseboxWindowTitleManager {
if (!this.#instance) {
this.#instance = new FuseboxWindowTitleManager();
}
return this.#instance;
}
setAppInfo(appDisplayName: string | undefined, deviceName: string | undefined): void {
this.#appDisplayName = appDisplayName;
this.#deviceName = deviceName;
this.#updateTitle();
}
setSuffix(suffix: string): void {
this.#suffix = suffix;
this.#updateTitle();
}
#updateTitle(): void {
const parts: string[] = [];
if (this.#appDisplayName) {
parts.push(this.#appDisplayName);
}
if (this.#deviceName) {
parts.push(`(${this.#deviceName})`);
}
if (this.#suffix) {
parts.push(this.#suffix);
}
// On macOS, window titles conventionally omit the app name
if (!(navigator.userAgent.includes('Electron') && navigator.userAgent.includes('Macintosh'))) {
parts.push('- React Native DevTools');
}
document.title = parts.join(' ');
}
}