Skip to content

Commit

Permalink
Merge pull request #577 from rak-phillip/bugfix/236-macos-tray-icons
Browse files Browse the repository at this point in the history
Add new tray icons for macOS
  • Loading branch information
mattfarina authored Sep 3, 2021
2 parents b41899d + 13bd353 commit 76830ec
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 4 deletions.
Binary file added resources/icons/[email protected]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resources/icons/[email protected]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resources/icons/[email protected]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resources/icons/[email protected]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resources/icons/[email protected]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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 readonly trayIconsMacOs = {
stopped: 'icons/[email protected]',
starting: 'icons/[email protected]',
started: 'icons/[email protected]',
stopping: 'icons/[email protected]',
error: 'icons/[email protected]'
}

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

private readonly 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 76830ec

Please sign in to comment.