feat(tray): make most basic version work

This commit is contained in:
Johannes Millan 2020-10-27 23:48:20 +01:00
parent 14c0f7743c
commit c9a4e8270b
70 changed files with 32 additions and 74 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 638 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 694 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 740 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 821 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 850 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 862 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 924 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 981 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 983 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1,009 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 577 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 975 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 995 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1,008 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 629 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 680 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 749 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 801 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 824 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 880 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 920 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 925 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 952 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 812 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 758 B

View file

@ -1,14 +1,12 @@
import { App, ipcMain, Menu, nativeTheme, Tray } from 'electron';
import { existsSync, readFileSync } from 'fs';
// const dbus = require('./dbus');
import { errorHandler } from './error-handler';
import { IPC } from './ipc-events.const';
const GNOME_SHELL_EXT_MIN_VERSION = 2;
let tray;
let isIndicatorRunning = false;
let isGnomeShellExtensionRunning = false;
let DIR: string;
const isGnomeShellExtensionRunning = false;
export const initIndicator = ({
IS_LINUX,
@ -27,68 +25,25 @@ export const initIndicator = ({
app: App;
ICONS_FOLDER: string;
}) => {
const isGnomeShellExtensionInstalled = isGnomeShellInstalled(IS_LINUX, IS_GNOME);
DIR = ICONS_FOLDER + 'indicator/';
initAppListeners(app);
initListeners(isGnomeShellExtensionInstalled);
initListeners();
// if we have the gnome shell extension installed set up bus
if (IS_GNOME && isGnomeShellExtensionInstalled) {
// TODO
// dbus.init({
// quitApp,
// showApp,
// });
isGnomeShellExtensionRunning = true;
return;
} else if (IS_GNOME) {
// don't start anything on GNOME as the indicator might not be visible and
// the quiting behaviour confusing
return;
} else {
// otherwise create a regular tray icon
// switch tray icon based on
const trayIcoFile = nativeTheme.shouldUseDarkColors
? 'tray-ico-d.png'
: 'tray-ico-l.png';
const suf = nativeTheme.shouldUseDarkColors
? '-d.png'
: '-l.png';
tray = new Tray(DIR + `stopped${suf}`);
tray.setContextMenu(createContextMenu(showApp, quitApp));
tray = new Tray(ICONS_FOLDER + trayIcoFile);
tray.setContextMenu(createContextMenu(showApp, quitApp));
tray.on('click', () => {
showApp();
});
isIndicatorRunning = true;
return tray;
}
tray.on('click', () => {
showApp();
});
isIndicatorRunning = true;
return tray;
// }
};
function isGnomeShellInstalled(IS_LINUX, IS_GNOME) {
// check if shell extension is installed
let isGnomeShellExtInstalled = false;
if (IS_LINUX && IS_GNOME) {
// tslint:disable-next-line
const LINUX_HOME_DIR = process.env['HOME'];
const EXTENSION_PATH = LINUX_HOME_DIR + '/.local/share/gnome-shell/extensions/indicator@johannes.super-productivity.com';
if (existsSync(EXTENSION_PATH)) {
const metaData = readFileSync(EXTENSION_PATH + '/metadata.json').toString();
const version = JSON.parse(metaData).version;
if (version >= GNOME_SHELL_EXT_MIN_VERSION) {
isGnomeShellExtInstalled = true;
} else {
errorHandler('Indicator: Outdated version '
+ version
+ ' of Gnome Shell Extension installed. Please install at least version '
+ GNOME_SHELL_EXT_MIN_VERSION + '.');
}
}
}
return isGnomeShellExtInstalled;
}
function initAppListeners(app) {
if (tray) {
app.on('before-quit', () => {
@ -99,7 +54,7 @@ function initAppListeners(app) {
}
}
function initListeners(isGnomeShellExtInstalled) {
function initListeners() {
ipcMain.on(IPC.CURRENT_TASK_UPDATED, (ev, params) => {
const currentTask = params.current;
// const lastActiveTaskTask = params.lastActiveTask;
@ -109,25 +64,26 @@ function initListeners(isGnomeShellExtInstalled) {
if (currentTask) {
msg = createIndicatorStr(currentTask);
}
console.log(currentTask);
// if (isGnomeShellExtInstalled) {
// // gnome indicator handling
// if (currentTask && currentTask.title) {
// dbus.setTask(currentTask.id, msg);
// } else if (!currentTask && lastActiveTaskTask && !lastActiveTaskTask.isDone) {
// const msg = createIndicatorStr(lastActiveTaskTask);
// dbus.setTask('PAUSED', msg);
// } else {
// dbus.setTask('NONE', 'NONE');
// }
// } else
//
if (tray) {
// tray handling
if (currentTask && currentTask.title) {
const suf = nativeTheme.shouldUseDarkColors
? '-d'
: '-l';
const progress = currentTask.timeSpent / currentTask.timeEstimate;
const f = Math.min(Math.round(progress * 15), 15);
const t = DIR + `running-anim${suf}/${f || 0}@2x.png`;
tray.setTitle(msg);
tray.setImage(t);
} else {
tray.setTitle('');
const suf = nativeTheme.shouldUseDarkColors
? '-d.png'
: '-l.png';
tray.setImage(DIR + `stopped${suf}`);
}
}
});

View file

@ -21,6 +21,8 @@ export class TaskElectronEffects {
taskChangeElectron$: any = this._actions$.pipe(
ofType(
TaskActionTypes.SetCurrentTask,
TaskActionTypes.UnsetCurrentTask,
TaskActionTypes.AddTimeSpent,
),
withLatestFrom(this._store$.pipe(select(selectCurrentTask))),
tap(([action, current]) => {