Skip to content

Commit

Permalink
Add GPMDP and strip default foobar2k suffix
Browse files Browse the repository at this point in the history
  • Loading branch information
pendo324 committed Jun 20, 2020
1 parent 70dd482 commit 7d4b979
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 3 deletions.
12 changes: 10 additions & 2 deletions src/players/foobar2000/foobarHandler_win32.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,19 @@ class FoobarHandler extends Handler {
return '';
}

if (processes[0].windowTitle === 'foobar2000') {
const windowTitle = processes[0].windowTitle;

if (windowTitle === 'foobar2000') {
return '';
}

return processes[0].windowTitle;
// remove the default [foobar2000] from the end of the window title
const defaultSuffix = '[foobar2000]';
if (windowTitle.endsWith(defaultSuffix)) {
return windowTitle.split(defaultSuffix)[0].trim();
}

return windowTitle;
}
}

Expand Down
42 changes: 42 additions & 0 deletions src/players/gpmdp/gpmdpHandler_win32.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import Handler from './../Handler';
import { getProcessByName } from '@pendo324/get-process-by-name';

class GpmdpHandler extends Handler {
constructor() {
super({
os: 'win32',
source: 'Desktop',
id: 'gpmdp',
name: 'Google Play Desktop Player'
});
}

async getTrack() {
const processes = (
await getProcessByName('Google Play Music Desktop Player.exe')
).filter((t) => t.windowTitle && t.windowTitle.length > 0);

if (!processes.length) {
// TODO: add better check/error handling here
// alert('Tool needs updating.');
return '';
}

const windowTitle = processes[0].windowTitle;

if (windowTitle.startsWith('(Paused)')) {
return 'Paused.';
}

if (
windowTitle === 'Google Play Music Desktop Player' ||
windowTitle === 'crash service'
) {
return '';
}

return windowTitle;
}
}

export default GpmdpHandler;
12 changes: 12 additions & 0 deletions src/players/gpmdp/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { remote } from 'electron';
const { platform } = remote.require('os');

export const supportedPlatforms = ['win32'];

const platformHandler = supportedPlatforms.find((p) => platform() === p);

if (typeof platformHandler === 'undefined') {
throw new Error('Platform not supported.');
}

export default require(`./gpmdpHandler_${platformHandler}`).default;
4 changes: 3 additions & 1 deletion src/players/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import * as mpcQt from './mpc-qt';
import * as mpcHc from './mpc-hc';
import * as mpv from './mpv';
import * as vlc from './vlc';
import * as gpmdp from './gpmdp';

import * as Web from './Web';

Expand All @@ -18,7 +19,8 @@ export const desktop = {
mpcQt,
mpcHc,
mpv,
vlc
vlc,
gpmdp
};

export const web = {
Expand Down

0 comments on commit 7d4b979

Please sign in to comment.