Skip to content

Commit fec1c86

Browse files
committed
add keepAwake option - useful for uninterrupted monitoring
1 parent f59a2ea commit fec1c86

File tree

4 files changed

+62
-12
lines changed

4 files changed

+62
-12
lines changed

manifest.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"description": "Show active intervals, scheduled timeouts, animation frames, idle callbacks, eval invocations, media events and properties",
66
"minimum_chrome_version": "135.0",
77
"homepage_url": "https://github.com/zendive/browser-api-monitor",
8-
"permissions": ["storage"],
8+
"permissions": ["storage", "power"],
99
"host_permissions": ["*://*/*"],
1010
"devtools_page": "public/api-monitor-devtools.html",
1111
"icons": {

src/api/settings.ts

+1
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ export const DEFAULT_SETTINGS = {
130130
paused: false,
131131
devtoolsPanelShown: false,
132132
wrapperCallstackType: EWrapperCallstackType.SHORT,
133+
keepAwake: false,
133134
};
134135

135136
export function panelsArray2Map(panels: TSettingsPanel[]) {

src/view/menu/TogglePanels.svelte

+59-10
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,16 @@
1414
let wrapperCallstackType = $state(DEFAULT_SETTINGS.wrapperCallstackType);
1515
let reloadMessageEl: Alert | null = null;
1616
let selfEl: HTMLElement | null = null;
17+
let keepAwake = $state.raw(false);
1718
1819
getSettings().then((state) => {
1920
panels = state.panels;
2021
wrapperCallstackType = state.wrapperCallstackType;
22+
keepAwake = state.keepAwake;
23+
24+
if (keepAwake) {
25+
chrome.power.requestKeepAwake('display');
26+
}
2127
});
2228
2329
runtimeListen(async (o) => {
@@ -48,6 +54,18 @@
4854
});
4955
reloadMessageEl?.show();
5056
}
57+
58+
function onToggleKeepAwake() {
59+
keepAwake = !keepAwake;
60+
61+
if (keepAwake) {
62+
chrome.power.requestKeepAwake('display');
63+
} else {
64+
chrome.power.releaseKeepAwake();
65+
}
66+
67+
setSettings({ keepAwake });
68+
}
5169
</script>
5270

5371
<button
@@ -62,9 +80,9 @@
6280
<div bind:this={selfEl} popover="auto" id="toggle-panels-menu" role="menu">
6381
<table class="menu-content">
6482
<tbody>
65-
<tr class="menu-item -dash">
66-
<td>Callstack Type</td>
67-
<td>
83+
<tr class="menu-item -dash-bottom">
84+
<td class="-left">Callstack Type</td>
85+
<td class="-right">
6886
<button
6987
class="btn-toggle"
7088
title="Toggle callstack type: full/short"
@@ -84,7 +102,7 @@
84102

85103
{#each panels as panel, index (panel.key)}
86104
<tr class="menu-item">
87-
<td>
105+
<td class="-left">
88106
<a
89107
href="void(0)"
90108
class="toggle-visibility"
@@ -98,10 +116,10 @@
98116
</td>
99117

100118
{#if !NON_WRAPPABLE.includes(panel.key)}
101-
<td>
119+
<td class="-right">
102120
<button
103121
class="btn-toggle"
104-
title="wrap/unwrap function to start/stop collect it's metrics"
122+
title="Wrap/unwrap function to start/stop collect it's metrics"
105123
onclick={() => void onTogglePanelWrap(index)}
106124
>
107125
{`${panel.wrap ? 'wrapped' : 'unwrapped'}`}
@@ -110,6 +128,20 @@
110128
{/if}
111129
</tr>
112130
{/each}
131+
132+
<tr class="menu-item -dash-top">
133+
<td class="-left">
134+
Prevent the system from sleeping in response to user inactivity
135+
</td>
136+
<td class="-right">
137+
<button
138+
class="btn-toggle"
139+
onclick={onToggleKeepAwake}
140+
>
141+
{`${keepAwake ? 'on' : 'off'}`}
142+
</button>
143+
</td>
144+
</tr>
113145
</tbody>
114146
</table>
115147
</div>
@@ -134,13 +166,31 @@
134166
padding: 0 0.375rem;
135167
136168
.menu-content {
169+
margin: 0.2rem 0;
170+
137171
.menu-item {
138-
line-height: 1.4rem;
172+
td {
173+
line-height: 1rem;
174+
padding: 0.1rem 0 0.1rem 0;
139175
140-
&.-dash {
176+
&.-left {
177+
max-width: 12rem;
178+
}
179+
&.-right {
180+
display: flex;
181+
align-items: center;
182+
justify-content: center;
183+
}
184+
}
185+
186+
&.-dash-bottom {
141187
border-bottom: 1px solid var(--border);
142188
}
143189
190+
&.-dash-top {
191+
border-top: 1px solid var(--border);
192+
}
193+
144194
.toggle-visibility {
145195
color: var(--text);
146196
text-wrap: nowrap;
@@ -152,9 +202,8 @@
152202
153203
.btn-toggle {
154204
color: var(--text);
155-
border-left: 1px solid var(--border);
156-
border-right: none;
157205
margin-left: 0.375rem;
206+
font-weight: bold;
158207
}
159208
}
160209
}

src/view/store/session.store.svelte.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ export async function toggleDebug(traceId: string) {
3333
}
3434

3535
const QUOTA_THRESHOLD = chrome.storage.session.QUOTA_BYTES;
36-
const MARGINAL_SIZE = 40; // for ASCII string in an array
36+
const MARGINAL_SIZE = 40; // for ASCII string in an array
3737
async function toggleSet(set: Set<string>, traceId: string): Promise<boolean> {
3838
if (set.has(traceId)) {
3939
set.delete(traceId);

0 commit comments

Comments
 (0)