Skip to content

Commit

Permalink
left-sidebar: Add initial character of Realm Name instead of default …
Browse files Browse the repository at this point in the history
…icon.

This PR adds a feature for showing the first char of realm name as the server icon when the
icon fails to load for some reasons.
  • Loading branch information
priyank-p authored and akashnimare committed Sep 14, 2018
1 parent 2ece432 commit 0ad4ea4
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 1 deletion.
10 changes: 10 additions & 0 deletions app/renderer/css/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,16 @@ body {
padding: 2px 0;
}

.server-tab .alt-icon {
font-family: Verdana;
font-weight: 600;
font-size: 22px;
border: 2px solid #222c31;
margin-left: 17%;
width: 33px;
border-radius: 50%;
}

.tab .server-tab:hover {
opacity: 0.8;
}
Expand Down
1 change: 1 addition & 0 deletions app/renderer/js/components/webview.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class WebView extends BaseComponent {
disablewebsecurity
${this.props.preload ? 'preload="js/preload.js"' : ''}
partition="persist:webviewsession"
name="${this.props.name}"
webpreferences="allowRunningInsecureContent, javascript=yes">
</webview>`;
}
Expand Down
27 changes: 26 additions & 1 deletion app/renderer/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -214,8 +214,12 @@ class ServerManagerView {

const $serverImgs = document.querySelectorAll('.server-icons');
$serverImgs.forEach($serverImg => {
if ($serverImg.src.includes('img/icon.png')) {
this.displayInitalCharLogo($serverImg);
}

$serverImg.addEventListener('error', () => {
$serverImg.src = 'img/icon.png';
this.displayInitalCharLogo($serverImg);
});
});

Expand All @@ -237,6 +241,27 @@ class ServerManagerView {
return currentIndex;
}

displayInitalCharLogo($img) {
const $altIcon = document.createElement('div');
const $parent = $img.parentElement;
const $container = $parent.parentElement;
const webviewId = $container.dataset.tabId;
const $webview = document.querySelector(`webview[data-tab-id="${webviewId}"]`);
const realmName = $webview.getAttribute('name');

if (realmName === null) {
$img.src = '/img/icon.png';
return;
}

$altIcon.textContent = realmName.charAt(0) || 'Z';
$altIcon.classList.add('server-icon');
$altIcon.classList.add('alt-icon');

$parent.removeChild($img);
$parent.appendChild($altIcon);
}

sidebarHoverEvent(SidebarButton, SidebarTooltip, addServer = false) {
SidebarButton.addEventListener('mouseover', () => {
SidebarTooltip.removeAttribute('style');
Expand Down

0 comments on commit 0ad4ea4

Please sign in to comment.