Skip to content

Commit

Permalink
Use'template' icons for tray when macOS
Browse files Browse the repository at this point in the history
  • Loading branch information
rak-phillip committed Sep 2, 2021
1 parent 62bfec0 commit a258115
Showing 1 changed file with 27 additions and 4 deletions.
31 changes: 27 additions & 4 deletions src/main/tray.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import fs from 'fs';
import pth from 'path';
import os from 'os';

import Electron from 'electron';
import yaml from 'yaml';
Expand Down Expand Up @@ -51,8 +52,30 @@ export class Tray {

protected kubernetesState = State.STOPPED;

private isMacOs = () => {
return os.platform() === 'darwin';
}

private trayIconsMacOs = {
stopped: 'icons/[email protected]',
starting: 'icons/[email protected]',
started: 'icons/[email protected]',
stopping: 'icons/[email protected]',
error: 'icons/[email protected]'
}

private trayIcons = {
stopped: '',
starting: 'icons/logo-square-bw.png',
started: 'icons/logo-square.png',
stopping: '',
error: 'icons/logo-square-red.png'
}

private trayIconSet = this.isMacOs() ? this.trayIconsMacOs : this.trayIcons

constructor() {
this.trayMenu = new Electron.Tray(resources.get('icons/logo-square-bw.png'));
this.trayMenu = new Electron.Tray(resources.get(this.trayIconSet.starting));
this.trayMenu.setToolTip('Rancher Desktop');

// Discover k8s contexts
Expand Down Expand Up @@ -159,18 +182,18 @@ export class Tray {
};

let icon = resources.get('icons/kubernetes-icon-black.png');
let logo = resources.get('icons/logo-square-bw.png');
let logo = resources.get(this.trayIconSet.starting);

if (this.kubernetesState === State.STARTED) {
icon = resources.get('/icons/kubernetes-icon-color.png');
logo = resources.get('/icons/logo-square.png');
logo = resources.get(this.trayIconSet.started);
// Update the contexts as a new kubernetes context will be added
this.updateContexts();
} else if (this.kubernetesState === State.ERROR) {
// For licensing reasons, we cannot just tint the Kubernetes logo.
// Here we're using an icon from GitHub's octicons set.
icon = resources.get('/icons/issue-opened-16.png');
logo = resources.get('/icons/logo-square-red.png');
logo = resources.get(this.trayIconSet.error);
}

const stateMenu = this.contextMenuItems.find(item => item.id === 'state');
Expand Down

0 comments on commit a258115

Please sign in to comment.