Skip to content

Commit ad56847

Browse files
committed
feat: add missing action icon fallback
1 parent 1de55d4 commit ad56847

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

packages/electron-chrome-extensions/src/browser-action.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,13 +200,24 @@ export const injectBrowserAction = () => {
200200
const bgImage = `url(${iconUrl})`
201201

202202
if (this.pendingIcon) {
203+
this.pendingIcon.onload = this.pendingIcon.onerror = () => {}
203204
this.pendingIcon = undefined
204205
}
205206

206207
// Preload icon to prevent it from blinking
207208
const img = (this.pendingIcon = new Image())
209+
img.onerror = () => {
210+
if (this.isConnected) {
211+
this.classList.toggle('no-icon', true)
212+
if (this.title) {
213+
this.dataset.letter = this.title.charAt(0)
214+
}
215+
this.pendingIcon = undefined
216+
}
217+
}
208218
img.onload = () => {
209219
if (this.isConnected) {
220+
this.classList.toggle('no-icon', false)
210221
this.style.backgroundImage = bgImage
211222
this.pendingIcon = undefined
212223
}
@@ -304,6 +315,25 @@ export const injectBrowserAction = () => {
304315
background-color: var(--browser-action-hover-bg, rgba(255, 255, 255, 0.3));
305316
}
306317
318+
.action.no-icon::after {
319+
content: attr(data-letter);
320+
text-transform: uppercase;
321+
font-size: .7rem;
322+
background-color: #757575;
323+
color: white;
324+
border-radius: 4px;
325+
position: absolute;
326+
top: 50%;
327+
left: 50%;
328+
transform: translate(-50%, -50%);
329+
width: 80%;
330+
height: 80%;
331+
display: flex;
332+
flex: 0 0 auto;
333+
align-items: center;
334+
justify-content: center;
335+
}
336+
307337
.badge {
308338
box-shadow: 0px 0px 1px 1px var(--browser-action-badge-outline, #444);
309339
box-sizing: border-box;

0 commit comments

Comments
 (0)