Skip to content

Commit 60050a3

Browse files
committed
ui: Add Zen mode
1 parent 1c63dc7 commit 60050a3

File tree

7 files changed

+101
-7
lines changed

7 files changed

+101
-7
lines changed

ui/src/core/app_impl.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,8 @@ export class AppImpl implements App {
126126
readonly startupCommandsSetting: Setting<CommandInvocation[]>;
127127
readonly enforceStartupCommandAllowlistSetting: Setting<boolean>;
128128
private _isInternalUser?: boolean;
129+
private _zenModeEnabled = false;
130+
private _topbarVisibleInZenMode = false;
129131

130132
// This constructor is invoked only once, when frontend/index.ts invokes
131133
// AppMainImpl.initialize().
@@ -197,6 +199,34 @@ export class AppImpl implements App {
197199
};
198200
}
199201

202+
get zenModeEnabled(): boolean {
203+
return this._zenModeEnabled;
204+
}
205+
206+
get topbarVisibleInZenMode(): boolean {
207+
return this._topbarVisibleInZenMode;
208+
}
209+
210+
showTopbarInZenMode(): void {
211+
this._topbarVisibleInZenMode = true;
212+
raf.scheduleFullRedraw();
213+
}
214+
215+
hideTopbarInZenMode(): void {
216+
this._topbarVisibleInZenMode = false;
217+
raf.scheduleFullRedraw();
218+
}
219+
220+
toggleZenMode(): void {
221+
this._zenModeEnabled = !this._zenModeEnabled;
222+
if (this._zenModeEnabled) {
223+
// When entering zen mode, reset omnibox and hide topbar
224+
this.omnibox.reset(false);
225+
this._topbarVisibleInZenMode = false;
226+
}
227+
raf.scheduleFullRedraw();
228+
}
229+
200230
openTraceFromFile(file: File) {
201231
return this.openTrace({type: 'FILE', file});
202232
}

ui/src/core/trace_impl.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,14 @@ export class TraceImpl implements Trace, Disposable {
314314
return this.app.isInternalUser;
315315
}
316316

317+
get zenModeEnabled(): boolean {
318+
return this.app.zenModeEnabled;
319+
}
320+
321+
toggleZenMode(): void {
322+
this.app.toggleZenMode();
323+
}
324+
317325
get perfDebugging() {
318326
return this.app.perfDebugging;
319327
}

ui/src/core_plugins/dev.perfetto.CoreCommands/index.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,12 @@ export default class CoreCommands implements PerfettoPlugin {
146146
ctx.commands.registerCommand({
147147
id: 'dev.perfetto.OpenCommandPalette',
148148
name: 'Open command palette',
149-
callback: () => ctx.omnibox.setMode(OmniboxMode.Command),
149+
callback: () => {
150+
if (AppImpl.instance.zenModeEnabled) {
151+
AppImpl.instance.showTopbarInZenMode();
152+
}
153+
ctx.omnibox.setMode(OmniboxMode.Command);
154+
},
150155
defaultHotkey: '!Mod+Shift+P',
151156
});
152157

@@ -205,6 +210,15 @@ export default class CoreCommands implements PerfettoPlugin {
205210
icon: 'folder_open',
206211
});
207212

213+
ctx.commands.registerCommand({
214+
id: 'dev.perfetto.ToggleZenMode',
215+
name: 'Toggle zen mode',
216+
defaultHotkey: 'Shift+F',
217+
callback: () => {
218+
AppImpl.instance.toggleZenMode();
219+
},
220+
});
221+
208222
const OPEN_LEGACY_COMMAND_ID = 'dev.perfetto.OpenTraceInLegacyUi';
209223
ctx.commands.registerCommand({
210224
id: OPEN_LEGACY_COMMAND_ID,

ui/src/frontend/omnibox.ts

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,8 @@ export class Omnibox implements m.ClassComponent<OmniboxAttrs> {
7575
}
7676

7777
private renderPromptOmnibox(): m.Children {
78-
const omnibox = AppImpl.instance.omnibox;
78+
const app = AppImpl.instance;
79+
const omnibox = app.omnibox;
7980
const prompt = assertExists(omnibox.pendingPrompt);
8081

8182
let options: OmniboxOption[] | undefined = undefined;
@@ -111,16 +112,23 @@ export class Omnibox implements m.ClassComponent<OmniboxAttrs> {
111112
},
112113
onSubmit: (value, _alt) => {
113114
omnibox.resolvePrompt(value);
115+
if (app.zenModeEnabled === true) {
116+
app.hideTopbarInZenMode();
117+
}
114118
},
115119
onClose: () => {
116120
omnibox.rejectPrompt();
121+
if (app.zenModeEnabled === true) {
122+
app.hideTopbarInZenMode();
123+
}
117124
},
118125
});
119126
}
120127

121128
private renderCommandOmnibox(): m.Children {
122129
// Fuzzy-filter commands by the filter string.
123-
const {commands, omnibox} = AppImpl.instance;
130+
const app = AppImpl.instance;
131+
const {commands, omnibox} = app;
124132
const filteredCmds = commands.fuzzyFilterCommands(omnibox.text);
125133

126134
// Create an array of commands with attached heuristics from the recent
@@ -173,10 +181,16 @@ export class Omnibox implements m.ClassComponent<OmniboxAttrs> {
173181
this.omniboxInputEl.blur();
174182
}
175183
omnibox.reset();
184+
if (app.zenModeEnabled === true) {
185+
app.hideTopbarInZenMode();
186+
}
176187
},
177188
onSubmit: (key: string) => {
178189
this.addRecentCommand(key);
179190
commands.runCommand(key);
191+
if (app.zenModeEnabled === true) {
192+
app.hideTopbarInZenMode();
193+
}
180194
},
181195
onGoBack: () => {
182196
omnibox.reset();
@@ -210,13 +224,19 @@ export class Omnibox implements m.ClassComponent<OmniboxAttrs> {
210224
const tag = alt ? undefined : 'omnibox_query';
211225
if (trace === undefined) return;
212226
addQueryResultsTab(trace, config, tag);
227+
if (AppImpl.instance.zenModeEnabled === true) {
228+
AppImpl.instance.hideTopbarInZenMode();
229+
}
213230
},
214231
onClose: () => {
215232
AppImpl.instance.omnibox.setText('');
216233
if (this.omniboxInputEl) {
217234
this.omniboxInputEl.blur();
218235
}
219236
AppImpl.instance.omnibox.reset();
237+
if (AppImpl.instance.zenModeEnabled === true) {
238+
AppImpl.instance.hideTopbarInZenMode();
239+
}
220240
},
221241
onGoBack: () => {
222242
AppImpl.instance.omnibox.reset();
@@ -249,6 +269,9 @@ export class Omnibox implements m.ClassComponent<OmniboxAttrs> {
249269
if (this.omniboxInputEl) {
250270
this.omniboxInputEl.blur();
251271
}
272+
if (AppImpl.instance.zenModeEnabled === true) {
273+
AppImpl.instance.hideTopbarInZenMode();
274+
}
252275
},
253276
onSubmit: (value, _mod, shift) => {
254277
if (trace === undefined) return; // No trace loaded.
@@ -261,6 +284,9 @@ export class Omnibox implements m.ClassComponent<OmniboxAttrs> {
261284
if (this.omniboxInputEl) {
262285
this.omniboxInputEl.blur();
263286
}
287+
if (AppImpl.instance.zenModeEnabled === true) {
288+
AppImpl.instance.hideTopbarInZenMode();
289+
}
264290
},
265291
rightContent: trace && this.renderStepThrough(trace),
266292
});

ui/src/frontend/timeline_page/timeline_page.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,14 @@ class TimelinePage implements m.ClassComponent<TimelinePageAttrs> {
5757

5858
view({attrs}: m.CVnode<TimelinePageAttrs>) {
5959
const {trace} = attrs;
60+
const zenMode = AppImpl.instance.zenModeEnabled;
61+
const showOverview = OVERVIEW_PANEL_FLAG.get() && !zenMode;
6062
return m(
6163
'.pf-timeline-page',
6264
m(
6365
TabPanel,
6466
{trace},
65-
OVERVIEW_PANEL_FLAG.get() &&
67+
showOverview &&
6668
m(Minimap, {
6769
trace,
6870
className: 'pf-timeline-page__overview',

ui/src/frontend/ui_main.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,17 +57,21 @@ export class UiMain implements m.ClassComponent {
5757
(trace?.engine.numRequestsPending ?? 0) > 0 ||
5858
taskTracker.hasPendingTasks();
5959

60+
const zenMode = app.zenModeEnabled;
61+
const showStatusBar = showStatusBarFlag.get() && !zenMode;
62+
const showTopbar = !zenMode || app.topbarVisibleInZenMode;
63+
6064
return m('main.pf-ui-main', [
61-
m(Sidebar),
62-
m(Topbar, {trace}),
65+
!zenMode && m(Sidebar),
66+
showTopbar && m(Topbar, {trace}),
6367
m(LinearProgress, {
6468
className: 'pf-ui-main__loading',
6569
state: isSomethingLoading ? 'indeterminate' : 'none',
6670
}),
6771
m('.pf-ui-main__page-container', app.pages.renderPageForCurrentRoute()),
6872
m(CookieConsent),
6973
maybeRenderFullscreenModalDialog(),
70-
showStatusBarFlag.get() && renderStatusBar(trace),
74+
showStatusBar && renderStatusBar(trace),
7175
app.perfDebugging.renderPerfStats(),
7276
]);
7377
}

ui/src/public/app.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,16 @@ export interface App {
6161
// certain internal links or expose certain experimental features by default.
6262
readonly isInternalUser: boolean;
6363

64+
// True if zen mode is enabled. Zen mode hides the sidebar, overview,
65+
// and status bar to provide a distraction-free viewing experience.
66+
readonly zenModeEnabled: boolean;
67+
68+
/**
69+
* Toggle zen mode on/off. Zen mode hides the sidebar, overview,
70+
* and status bar to provide a distraction-free viewing experience.
71+
*/
72+
toggleZenMode(): void;
73+
6474
/**
6575
* Navigate to a new page.
6676
*/

0 commit comments

Comments
 (0)