various formatting, mpris patch, menubar patch
This commit is contained in:
parent
900e011ad2
commit
dfd3fe6271
7 changed files with 151 additions and 132 deletions
|
@ -16,17 +16,17 @@ export default class ChromecastPlugin {
|
||||||
private audioClient = require('castv2-client').Client;
|
private audioClient = require('castv2-client').Client;
|
||||||
private mdns = require('mdns-js');
|
private mdns = require('mdns-js');
|
||||||
|
|
||||||
private devices : any = [];
|
private devices: any = [];
|
||||||
private castDevices : any = [];
|
private castDevices: any = [];
|
||||||
|
|
||||||
// private GCRunning = false;
|
// private GCRunning = false;
|
||||||
// private GCBuffer: any;
|
// private GCBuffer: any;
|
||||||
// private expectedConnections = 0;
|
// private expectedConnections = 0;
|
||||||
// private currentConnections = 0;
|
// private currentConnections = 0;
|
||||||
private activeConnections : any = [];
|
private activeConnections: any = [];
|
||||||
// private requests = [];
|
// private requests = [];
|
||||||
// private GCstream = new Stream.PassThrough(),
|
// private GCstream = new Stream.PassThrough(),
|
||||||
private connectedHosts : any = {};
|
private connectedHosts: any = {};
|
||||||
// private port = false;
|
// private port = false;
|
||||||
// private server = false;
|
// private server = false;
|
||||||
// private bufcount = 0;
|
// private bufcount = 0;
|
||||||
|
@ -40,7 +40,7 @@ export default class ChromecastPlugin {
|
||||||
let browser = this.mdns.createBrowser(this.mdns.tcp('googlecast'));
|
let browser = this.mdns.createBrowser(this.mdns.tcp('googlecast'));
|
||||||
browser.on('ready', browser.discover);
|
browser.on('ready', browser.discover);
|
||||||
|
|
||||||
browser.on('update', (service :any) => {
|
browser.on('update', (service: any) => {
|
||||||
if (service.addresses && service.fullname && service.fullname.includes('_googlecast._tcp')) {
|
if (service.addresses && service.fullname && service.fullname.includes('_googlecast._tcp')) {
|
||||||
this.ondeviceup(service.addresses[0], service.fullname.substring(0, service.fullname.indexOf("._googlecast")) + " " + (service.type[0].description ?? ""), '', 'googlecast');
|
this.ondeviceup(service.addresses[0], service.fullname.substring(0, service.fullname.indexOf("._googlecast")) + " " + (service.type[0].description ?? ""), '', 'googlecast');
|
||||||
}
|
}
|
||||||
|
@ -48,18 +48,21 @@ export default class ChromecastPlugin {
|
||||||
const Client = require('node-ssdp').Client;
|
const Client = require('node-ssdp').Client;
|
||||||
// also do a SSDP/UPnP search
|
// also do a SSDP/UPnP search
|
||||||
let ssdpBrowser = new Client();
|
let ssdpBrowser = new Client();
|
||||||
ssdpBrowser.on('response', (headers :any , statusCode : any, rinfo: any) => {
|
ssdpBrowser.on('response', (headers: any, statusCode: any, rinfo: any) => {
|
||||||
var location = getLocation(headers);
|
var location = getLocation(headers);
|
||||||
if (location != null) {
|
if (location != null) {
|
||||||
this.getServiceDescription(location, rinfo.address);
|
this.getServiceDescription(location, rinfo.address);
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
function getLocation(headers: any) {
|
function getLocation(headers: any) {
|
||||||
let location = null;
|
let location = null;
|
||||||
if (headers["LOCATION"] != null ){location = headers["LOCATION"]}
|
if (headers["LOCATION"] != null) {
|
||||||
else if (headers["Location"] != null ){location = headers["Location"]}
|
location = headers["LOCATION"]
|
||||||
|
} else if (headers["Location"] != null) {
|
||||||
|
location = headers["Location"]
|
||||||
|
}
|
||||||
return location;
|
return location;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -85,7 +88,7 @@ export default class ChromecastPlugin {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private getServiceDescription(url:any, address:any) {
|
private getServiceDescription(url: any, address: any) {
|
||||||
const request = require('request');
|
const request = require('request');
|
||||||
request.get(url, (error: any, response: any, body: any) => {
|
request.get(url, (error: any, response: any, body: any) => {
|
||||||
if (!error && response.statusCode === 200) {
|
if (!error && response.statusCode === 200) {
|
||||||
|
@ -95,7 +98,7 @@ export default class ChromecastPlugin {
|
||||||
}
|
}
|
||||||
|
|
||||||
private ondeviceup(host: any, name: any, location: any, type: any) {
|
private ondeviceup(host: any, name: any, location: any, type: any) {
|
||||||
if (this.castDevices.findIndex((item:any) => item.host === host && item.name === name && item.location === location && item.type === type) === -1) {
|
if (this.castDevices.findIndex((item: any) => item.host === host && item.name === name && item.location === location && item.type === type) === -1) {
|
||||||
this.castDevices.push({
|
this.castDevices.push({
|
||||||
name: name,
|
name: name,
|
||||||
host: host,
|
host: host,
|
||||||
|
@ -106,7 +109,7 @@ export default class ChromecastPlugin {
|
||||||
this.devices.push(host);
|
this.devices.push(host);
|
||||||
}
|
}
|
||||||
if (name) {
|
if (name) {
|
||||||
this._win.webContents.executeJavaScript(`console.log('deviceFound','ip: ${host} name:${name}')`).catch((err: any) => console.error(err));
|
this._win.webContents.executeJavaScript(`console.log('deviceFound','ip: ${host} name:${name}')`).catch((err: any) => console.error(err));
|
||||||
console.log("deviceFound", host, name);
|
console.log("deviceFound", host, name);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -134,7 +137,7 @@ export default class ChromecastPlugin {
|
||||||
|
|
||||||
private loadMedia(client: any, song: any, artist: any, album: any, albumart: any, cb?: any) {
|
private loadMedia(client: any, song: any, artist: any, album: any, albumart: any, cb?: any) {
|
||||||
// const u = 'http://' + this.getIp() + ':' + server.address().port + '/';
|
// const u = 'http://' + this.getIp() + ':' + server.address().port + '/';
|
||||||
// const DefaultMediaReceiver : any = require('castv2-client').DefaultMediaReceiver;
|
// const DefaultMediaReceiver : any = require('castv2-client').DefaultMediaReceiver;
|
||||||
client.launch(CiderReceiver, (err: any, player: any) => {
|
client.launch(CiderReceiver, (err: any, player: any) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
console.log(err);
|
console.log(err);
|
||||||
|
@ -181,7 +184,7 @@ export default class ChromecastPlugin {
|
||||||
|
|
||||||
// send websocket ip
|
// send websocket ip
|
||||||
|
|
||||||
player.sendIp("ws://"+this.getIp()+":26369");
|
player.sendIp("ws://" + this.getIp() + ":26369");
|
||||||
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -191,7 +194,7 @@ export default class ChromecastPlugin {
|
||||||
let alias = 0;
|
let alias = 0;
|
||||||
let ifaces: any = os.networkInterfaces();
|
let ifaces: any = os.networkInterfaces();
|
||||||
for (var dev in ifaces) {
|
for (var dev in ifaces) {
|
||||||
ifaces[dev].forEach((details:any) => {
|
ifaces[dev].forEach((details: any) => {
|
||||||
if (details.family === 'IPv4') {
|
if (details.family === 'IPv4') {
|
||||||
if (!/(loopback|vmware|internal|hamachi|vboxnet|virtualbox)/gi.test(dev + (alias ? ':' + alias : ''))) {
|
if (!/(loopback|vmware|internal|hamachi|vboxnet|virtualbox)/gi.test(dev + (alias ? ':' + alias : ''))) {
|
||||||
if (details.address.substring(0, 8) === '192.168.' ||
|
if (details.address.substring(0, 8) === '192.168.' ||
|
||||||
|
@ -222,7 +225,7 @@ export default class ChromecastPlugin {
|
||||||
client.muted = false;
|
client.muted = false;
|
||||||
|
|
||||||
client.connect(device.host, () => {
|
client.connect(device.host, () => {
|
||||||
// console.log('connected, launching app ...', 'http://' + this.getIp() + ':' + server.address().port + '/');
|
// console.log('connected, launching app ...', 'http://' + this.getIp() + ':' + server.address().port + '/');
|
||||||
if (!this.connectedHosts[device.host]) {
|
if (!this.connectedHosts[device.host]) {
|
||||||
this.connectedHosts[device.host] = client;
|
this.connectedHosts[device.host] = client;
|
||||||
this.activeConnections.push(client);
|
this.activeConnections.push(client);
|
||||||
|
@ -273,7 +276,7 @@ export default class ChromecastPlugin {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private async setupGCServer(){
|
private async setupGCServer() {
|
||||||
return ''
|
return ''
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -303,19 +306,19 @@ export default class ChromecastPlugin {
|
||||||
event.returnValue = this.castDevices
|
event.returnValue = this.castDevices
|
||||||
});
|
});
|
||||||
|
|
||||||
electron.ipcMain.on('performGCCast', (event, device, song, artist, album, albumart) => {
|
electron.ipcMain.on('performGCCast', (event, device, song, artist, album, albumart) => {
|
||||||
// this.setupGCServer().then( () => {
|
// this.setupGCServer().then( () => {
|
||||||
this._win.webContents.setAudioMuted(true);
|
this._win.webContents.setAudioMuted(true);
|
||||||
console.log(device);
|
console.log(device);
|
||||||
this.stream(device, song, artist, album, albumart);
|
this.stream(device, song, artist, album, albumart);
|
||||||
// })
|
// })
|
||||||
});
|
});
|
||||||
|
|
||||||
electron.ipcMain.on('getChromeCastDevices', (_event, _data) => {
|
electron.ipcMain.on('getChromeCastDevices', (_event, _data) => {
|
||||||
this.searchForGCDevices();
|
this.searchForGCDevices();
|
||||||
});
|
});
|
||||||
|
|
||||||
electron.ipcMain.on('stopGCast', (_event) => {
|
electron.ipcMain.on('stopGCast', (_event) => {
|
||||||
this._win.webContents.setAudioMuted(false);
|
this._win.webContents.setAudioMuted(false);
|
||||||
this.activeConnections = [];
|
this.activeConnections = [];
|
||||||
this.connectedHosts = {};
|
this.connectedHosts = {};
|
||||||
|
|
|
@ -8,8 +8,8 @@ export default class DiscordRichPresence {
|
||||||
* Private variables for interaction in plugins
|
* Private variables for interaction in plugins
|
||||||
*/
|
*/
|
||||||
private static _store: any;
|
private static _store: any;
|
||||||
private _app : any;
|
private _app: any;
|
||||||
private _attributes : any;
|
private _attributes: any;
|
||||||
private static _connection: boolean = false;
|
private static _connection: boolean = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -76,17 +76,19 @@ export default class DiscordRichPresence {
|
||||||
|
|
||||||
// Login to Discord
|
// Login to Discord
|
||||||
this._client.login({clientId})
|
this._client.login({clientId})
|
||||||
.then(() => {
|
.then(() => {
|
||||||
DiscordRichPresence._connection = true;
|
DiscordRichPresence._connection = true;
|
||||||
})
|
})
|
||||||
.catch((e: any) => console.error(`[DiscordRichPresence][connect] ${e}`));
|
.catch((e: any) => console.error(`[DiscordRichPresence][connect] ${e}`));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Disconnects from Discord RPC
|
* Disconnects from Discord RPC
|
||||||
*/
|
*/
|
||||||
private disconnect() {
|
private disconnect() {
|
||||||
if (!this._client) return;
|
if (!this._client) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
this._client.destroy().then(() => {
|
this._client.destroy().then(() => {
|
||||||
DiscordRichPresence._connection = false;
|
DiscordRichPresence._connection = false;
|
||||||
|
@ -94,50 +96,56 @@ export default class DiscordRichPresence {
|
||||||
}).catch((e: any) => console.error(`[DiscordRPC][disconnect] ${e}`));
|
}).catch((e: any) => console.error(`[DiscordRPC][disconnect] ${e}`));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Filter the Discord activity object
|
* Filter the Discord activity object
|
||||||
*/
|
*/
|
||||||
private filterActivity(activity: any, attributes: any): Object {
|
private filterActivity(activity: any, attributes: any): Object {
|
||||||
|
|
||||||
// Checks if the name is greater than 128 because some songs can be that long
|
// Checks if the name is greater than 128 because some songs can be that long
|
||||||
if (activity.details && activity.details.length > 128) {
|
if (activity.details && activity.details.length > 128) {
|
||||||
activity.details = activity.details.substring(0, 125) + '...'
|
activity.details = activity.details.substring(0, 125) + '...'
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check large image
|
// Check large image
|
||||||
if (activity.largeImageKey == null || activity.largeImageKey === "" || activity.largeImageKey.length > 256) {
|
if (activity.largeImageKey == null || activity.largeImageKey === "" || activity.largeImageKey.length > 256) {
|
||||||
activity.largeImageKey = "cider";
|
activity.largeImageKey = "cider";
|
||||||
}
|
}
|
||||||
|
|
||||||
// Timestamp
|
// Timestamp
|
||||||
if (new Date(attributes.endTime).getTime() < 0) {
|
if (new Date(attributes.endTime).getTime() < 0) {
|
||||||
delete activity.startTime
|
delete activity.startTime
|
||||||
delete activity.endTime
|
delete activity.endTime
|
||||||
}
|
}
|
||||||
|
|
||||||
// not sure
|
// not sure
|
||||||
if (!attributes.artistName) {
|
if (!attributes.artistName) {
|
||||||
delete activity.state;
|
delete activity.state;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!activity.largeImageText || activity.largeImageText.length < 2) {
|
if (!activity.largeImageText || activity.largeImageText.length < 2) {
|
||||||
delete activity.largeImageText
|
delete activity.largeImageText
|
||||||
}
|
}
|
||||||
|
|
||||||
activity.buttons.forEach((key: {label: string, url: string}, _v: Number) => {
|
activity.buttons.forEach((key: { label: string, url: string }, _v: Number) => {
|
||||||
if (key.url.includes('undefined') || key.url.includes('no-id-found')) {
|
if (key.url.includes('undefined') || key.url.includes('no-id-found')) {
|
||||||
activity.buttons.splice(key, 1);
|
activity.buttons.splice(key, 1);
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
return activity
|
return activity
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the activity of the client
|
* Sets the activity of the client
|
||||||
* @param {object} attributes
|
* @param {object} attributes
|
||||||
*/
|
*/
|
||||||
private updateActivity(attributes: any) {
|
private updateActivity(attributes: any) {
|
||||||
if (!this._client) return;
|
if (DiscordRichPresence._store.general.discord_rpc == 0) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!this._client) {
|
||||||
|
this.connect(DiscordRichPresence._store.general.discord_rpc == 1 ? '911790844204437504' : '886578863147192350')
|
||||||
|
}
|
||||||
|
|
||||||
if (!DiscordRichPresence._connection) {
|
if (!DiscordRichPresence._connection) {
|
||||||
this._client.clearActivity().catch((e: any) => console.error(`[DiscordRichPresence][clearActivity] ${e}`));
|
this._client.clearActivity().catch((e: any) => console.error(`[DiscordRichPresence][clearActivity] ${e}`));
|
||||||
|
@ -158,20 +166,20 @@ export default class DiscordRichPresence {
|
||||||
] //To change attributes.url => preload/cider-preload.js
|
] //To change attributes.url => preload/cider-preload.js
|
||||||
};
|
};
|
||||||
|
|
||||||
this._activity = this.filterActivity(this._activity, attributes)
|
this._activity = this.filterActivity(this._activity, attributes)
|
||||||
|
|
||||||
// Check if its pausing (false) or playing (true)
|
// Check if its pausing (false) or playing (true)
|
||||||
if (!attributes.status) {
|
if (!attributes.status) {
|
||||||
if (DiscordRichPresence._store.general.discord_rpc_clear_on_pause) {
|
if (DiscordRichPresence._store.general.discord_rpc_clear_on_pause) {
|
||||||
this._client.clearActivity()
|
this._client.clearActivity()
|
||||||
.catch((e: any) => console.error(`[DiscordRichPresence][clearActivity] ${e}`));
|
.catch((e: any) => console.error(`[DiscordRichPresence][clearActivity] ${e}`));
|
||||||
} else {
|
} else {
|
||||||
this._activity.smallImageKey = 'pause';
|
this._activity.smallImageKey = 'pause';
|
||||||
this._activity.smallImageText = 'Paused';
|
this._activity.smallImageText = 'Paused';
|
||||||
delete this._activity.endTimestamp;
|
delete this._activity.endTimestamp;
|
||||||
delete this._activity.startTimestamp;
|
delete this._activity.startTimestamp;
|
||||||
this._client.setActivity(this._activity)
|
this._client.setActivity(this._activity)
|
||||||
.catch((e: any) => console.error(`[DiscordRichPresence][setActivity] ${e}`));
|
.catch((e: any) => console.error(`[DiscordRichPresence][setActivity] ${e}`));
|
||||||
}
|
}
|
||||||
} else if (this._activity && this._activityCache !== this._activity && this._activity.details) {
|
} else if (this._activity && this._activityCache !== this._activity && this._activity.details) {
|
||||||
if (!DiscordRichPresence._store.general.discord_rpc_clear_on_pause) {
|
if (!DiscordRichPresence._store.general.discord_rpc_clear_on_pause) {
|
||||||
|
@ -180,7 +188,7 @@ export default class DiscordRichPresence {
|
||||||
}
|
}
|
||||||
|
|
||||||
this._client.setActivity(this._activity)
|
this._client.setActivity(this._activity)
|
||||||
.catch((e: any) => console.error(`[DiscordRichPresence][updateActivity] ${e}`));
|
.catch((e: any) => console.error(`[DiscordRichPresence][updateActivity] ${e}`));
|
||||||
this._activityCache = this._activity;
|
this._activityCache = this._activity;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -207,21 +215,21 @@ export default class DiscordRichPresence {
|
||||||
this.connect((DiscordRichPresence._store.general.discord_rpc == 1) ? '911790844204437504' : '886578863147192350');
|
this.connect((DiscordRichPresence._store.general.discord_rpc == 1) ? '911790844204437504' : '886578863147192350');
|
||||||
console.debug(`[Plugin][${this.name}] Ready.`);
|
console.debug(`[Plugin][${this.name}] Ready.`);
|
||||||
ipcMain.on('updateRPCImage', (_event, imageurl) => {
|
ipcMain.on('updateRPCImage', (_event, imageurl) => {
|
||||||
if (!DiscordRichPresence._store.general.privateEnabled){
|
if (!DiscordRichPresence._store.general.privateEnabled) {
|
||||||
fetch('https://api.cider.sh/v1/images' ,{
|
fetch('https://api.cider.sh/v1/images', {
|
||||||
|
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
body: JSON.stringify({url : imageurl}),
|
body: JSON.stringify({url: imageurl}),
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
'User-Agent': _win.webContents.getUserAgent()
|
'User-Agent': _win.webContents.getUserAgent()
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
.then(res => res.json())
|
.then(res => res.json())
|
||||||
.then(function(json){
|
.then(function (json) {
|
||||||
self._attributes["artwork"]["url"] = json.url
|
self._attributes["artwork"]["url"] = json.url
|
||||||
self.updateActivity(self._attributes)
|
self.updateActivity(self._attributes)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -238,9 +246,10 @@ export default class DiscordRichPresence {
|
||||||
* @param attributes Music Attributes (attributes.status = current state)
|
* @param attributes Music Attributes (attributes.status = current state)
|
||||||
*/
|
*/
|
||||||
onPlaybackStateDidChange(attributes: object): void {
|
onPlaybackStateDidChange(attributes: object): void {
|
||||||
if (!DiscordRichPresence._store.general.privateEnabled){
|
if (!DiscordRichPresence._store.general.privateEnabled) {
|
||||||
this._attributes = attributes
|
this._attributes = attributes
|
||||||
this.updateActivity(attributes)}
|
this.updateActivity(attributes)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -248,8 +257,9 @@ export default class DiscordRichPresence {
|
||||||
* @param attributes Music Attributes
|
* @param attributes Music Attributes
|
||||||
*/
|
*/
|
||||||
onNowPlayingItemDidChange(attributes: object): void {
|
onNowPlayingItemDidChange(attributes: object): void {
|
||||||
if (!DiscordRichPresence._store.general.privateEnabled){
|
if (!DiscordRichPresence._store.general.privateEnabled) {
|
||||||
this._attributes = attributes
|
this._attributes = attributes
|
||||||
this.updateActivity(attributes)}
|
this.updateActivity(attributes)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -120,7 +120,7 @@ export default class LastFMPlugin {
|
||||||
} else {
|
} else {
|
||||||
return console.log('[LastFM] Did not add ', attributes.name, '—', artist, 'because now playing a other song.');
|
return console.log('[LastFM] Did not add ', attributes.name, '—', artist, 'because now playing a other song.');
|
||||||
}
|
}
|
||||||
}, Math.round(attributes.durationInMillis * Math.min((self._store.lastfm.scrobble_after / 100),0.8)));
|
}, Math.round(attributes.durationInMillis * Math.min((self._store.lastfm.scrobble_after / 100), 0.8)));
|
||||||
}
|
}
|
||||||
|
|
||||||
private async updateNowPlayingSong(attributes: any) {
|
private async updateNowPlayingSong(attributes: any) {
|
||||||
|
@ -264,14 +264,15 @@ export default class LastFMPlugin {
|
||||||
* @param attributes Music Attributes
|
* @param attributes Music Attributes
|
||||||
*/
|
*/
|
||||||
nowPlayingItemDidChangeLastFM(attributes: any): void {
|
nowPlayingItemDidChangeLastFM(attributes: any): void {
|
||||||
if (!this._store.general.privateEnabled){
|
if (!this._store.general.privateEnabled) {
|
||||||
attributes.status = true
|
attributes.status = true
|
||||||
if (!this._store.lastfm.filterLoop) {
|
if (!this._store.lastfm.filterLoop) {
|
||||||
this._lastfm.cachedNowPlayingAttributes = false;
|
this._lastfm.cachedNowPlayingAttributes = false;
|
||||||
this._lastfm.cachedAttributes = false
|
this._lastfm.cachedAttributes = false
|
||||||
|
}
|
||||||
|
this.updateNowPlayingSong(attributes)
|
||||||
|
this.scrobbleSong(attributes)
|
||||||
}
|
}
|
||||||
this.updateNowPlayingSong(attributes)
|
|
||||||
this.scrobbleSong(attributes)}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,7 +35,7 @@ export default class Thumbar {
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
private isMac: boolean = process.platform === 'darwin';
|
private isMac: boolean = process.platform === 'darwin';
|
||||||
private menubarTemplate: any = [
|
private _menuTemplate: any = [
|
||||||
{
|
{
|
||||||
label: app.getName(),
|
label: app.getName(),
|
||||||
submenu: [
|
submenu: [
|
||||||
|
@ -43,20 +43,20 @@ export default class Thumbar {
|
||||||
label: 'About',
|
label: 'About',
|
||||||
click: () => this._win.webContents.executeJavaScript(`app.appRoute('about')`)
|
click: () => this._win.webContents.executeJavaScript(`app.appRoute('about')`)
|
||||||
},
|
},
|
||||||
{ type: 'separator' },
|
{type: 'separator'},
|
||||||
{
|
{
|
||||||
label: 'Settings',
|
label: 'Settings',
|
||||||
accelerator: 'CommandOrControl+,',
|
accelerator: 'CommandOrControl+,',
|
||||||
click: () => this._win.webContents.executeJavaScript(`app.appRoute('settings')`)
|
click: () => this._win.webContents.executeJavaScript(`app.appRoute('settings')`)
|
||||||
},
|
},
|
||||||
{ type: 'separator' },
|
{type: 'separator'},
|
||||||
{ role: 'services' },
|
{role: 'services'},
|
||||||
{ type: 'separator' },
|
{type: 'separator'},
|
||||||
{ role: 'hide' },
|
{role: 'hide'},
|
||||||
{ role: 'hideOthers' },
|
{role: 'hideOthers'},
|
||||||
{ role: 'unhide' },
|
{role: 'unhide'},
|
||||||
{ type: 'separator' },
|
{type: 'separator'},
|
||||||
{ role: 'quit' }
|
{role: 'quit'}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -85,20 +85,20 @@ export default class Thumbar {
|
||||||
...(this.isMac ? [
|
...(this.isMac ? [
|
||||||
{type: 'separator'},
|
{type: 'separator'},
|
||||||
{role: 'front'},
|
{role: 'front'},
|
||||||
|
{role: 'close'},
|
||||||
] : [
|
] : [
|
||||||
{}
|
{role: 'close'},
|
||||||
]),
|
]),
|
||||||
{role: 'close'},
|
|
||||||
{type: 'separator'},
|
|
||||||
{
|
{
|
||||||
label: 'Edit',
|
label: 'Edit',
|
||||||
submenu: [
|
submenu: [
|
||||||
{ role: 'undo' },
|
{role: 'undo'},
|
||||||
{ role: 'redo' },
|
{role: 'redo'},
|
||||||
{ type: 'separator' },
|
{type: 'separator'},
|
||||||
{ role: 'cut' },
|
{role: 'cut'},
|
||||||
{ role: 'copy' },
|
{role: 'copy'},
|
||||||
{ role: 'paste' },
|
{role: 'paste'},
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{type: 'separator'},
|
{type: 'separator'},
|
||||||
|
@ -139,7 +139,7 @@ export default class Thumbar {
|
||||||
accelerator: 'CommandOrControl+Left',
|
accelerator: 'CommandOrControl+Left',
|
||||||
click: () => this._win.webContents.executeJavaScript(`MusicKitInterop.previous()`)
|
click: () => this._win.webContents.executeJavaScript(`MusicKitInterop.previous()`)
|
||||||
},
|
},
|
||||||
{ type: 'separator' },
|
{type: 'separator'},
|
||||||
{
|
{
|
||||||
label: 'Volume Up',
|
label: 'Volume Up',
|
||||||
accelerator: 'CommandOrControl+Up',
|
accelerator: 'CommandOrControl+Up',
|
||||||
|
@ -232,7 +232,8 @@ export default class Thumbar {
|
||||||
*/
|
*/
|
||||||
onReady(win: Electron.BrowserWindow): void {
|
onReady(win: Electron.BrowserWindow): void {
|
||||||
this._win = win;
|
this._win = win;
|
||||||
Menu.setApplicationMenu(Menu.buildFromTemplate(this.menubarTemplate))
|
const menu = Menu.buildFromTemplate(this._menuTemplate);
|
||||||
|
Menu.setApplicationMenu(menu)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -58,10 +58,9 @@ export default class mpris {
|
||||||
/**
|
/**
|
||||||
* Connects to MPRIS Service
|
* Connects to MPRIS Service
|
||||||
*/
|
*/
|
||||||
@mpris.linuxOnly
|
|
||||||
private static connect() {
|
private static connect() {
|
||||||
|
|
||||||
const player = Player({
|
const player = Player({
|
||||||
name: 'cider',
|
name: 'cider',
|
||||||
identity: 'Cider',
|
identity: 'Cider',
|
||||||
supportedUriSchemes: [],
|
supportedUriSchemes: [],
|
||||||
|
@ -94,7 +93,6 @@ export default class mpris {
|
||||||
/**
|
/**
|
||||||
* Update M.P.R.I.S Player Attributes
|
* Update M.P.R.I.S Player Attributes
|
||||||
*/
|
*/
|
||||||
@mpris.linuxOnly
|
|
||||||
private static updatePlayer(attributes: any) {
|
private static updatePlayer(attributes: any) {
|
||||||
|
|
||||||
const MetaData = {
|
const MetaData = {
|
||||||
|
@ -119,7 +117,6 @@ export default class mpris {
|
||||||
* @private
|
* @private
|
||||||
* @param attributes
|
* @param attributes
|
||||||
*/
|
*/
|
||||||
@mpris.linuxOnly
|
|
||||||
private static updatePlayerState(attributes: any) {
|
private static updatePlayerState(attributes: any) {
|
||||||
switch (attributes.status) {
|
switch (attributes.status) {
|
||||||
case true: // Playing
|
case true: // Playing
|
||||||
|
@ -139,6 +136,9 @@ export default class mpris {
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
private static clearState() {
|
private static clearState() {
|
||||||
|
if (!mpris.player) {
|
||||||
|
return
|
||||||
|
}
|
||||||
mpris.player.metadata = {'mpris:trackid': '/org/mpris/MediaPlayer2/TrackList/NoTrack'}
|
mpris.player.metadata = {'mpris:trackid': '/org/mpris/MediaPlayer2/TrackList/NoTrack'}
|
||||||
mpris.player.playbackStatus = Player.PLAYBACK_STATUS_STOPPED;
|
mpris.player.playbackStatus = Player.PLAYBACK_STATUS_STOPPED;
|
||||||
}
|
}
|
||||||
|
@ -160,6 +160,7 @@ export default class mpris {
|
||||||
/**
|
/**
|
||||||
* Runs on app ready
|
* Runs on app ready
|
||||||
*/
|
*/
|
||||||
|
@mpris.linuxOnly
|
||||||
onReady(_: any): void {
|
onReady(_: any): void {
|
||||||
console.debug(`[Plugin][${mpris.name}] Ready.`);
|
console.debug(`[Plugin][${mpris.name}] Ready.`);
|
||||||
}
|
}
|
||||||
|
@ -167,6 +168,7 @@ export default class mpris {
|
||||||
/**
|
/**
|
||||||
* Renderer ready
|
* Renderer ready
|
||||||
*/
|
*/
|
||||||
|
@mpris.linuxOnly
|
||||||
onRendererReady(): void {
|
onRendererReady(): void {
|
||||||
mpris.connect()
|
mpris.connect()
|
||||||
}
|
}
|
||||||
|
@ -174,19 +176,17 @@ export default class mpris {
|
||||||
/**
|
/**
|
||||||
* Runs on app stop
|
* Runs on app stop
|
||||||
*/
|
*/
|
||||||
|
@mpris.linuxOnly
|
||||||
onBeforeQuit(): void {
|
onBeforeQuit(): void {
|
||||||
console.debug(`[Plugin][${mpris.name}] Stopped.`);
|
console.debug(`[Plugin][${mpris.name}] Stopped.`);
|
||||||
try {
|
mpris.clearState()
|
||||||
mpris.clearState()
|
|
||||||
}catch(e) {
|
|
||||||
e = null
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Runs on playback State Change
|
* Runs on playback State Change
|
||||||
* @param attributes Music Attributes (attributes.status = current state)
|
* @param attributes Music Attributes (attributes.status = current state)
|
||||||
*/
|
*/
|
||||||
|
@mpris.linuxOnly
|
||||||
onPlaybackStateDidChange(attributes: object): void {
|
onPlaybackStateDidChange(attributes: object): void {
|
||||||
console.debug(`[Plugin][${mpris.name}] onPlaybackStateDidChange.`);
|
console.debug(`[Plugin][${mpris.name}] onPlaybackStateDidChange.`);
|
||||||
mpris.updatePlayerState(attributes)
|
mpris.updatePlayerState(attributes)
|
||||||
|
@ -196,6 +196,7 @@ export default class mpris {
|
||||||
* Runs on song change
|
* Runs on song change
|
||||||
* @param attributes Music Attributes
|
* @param attributes Music Attributes
|
||||||
*/
|
*/
|
||||||
|
@mpris.linuxOnly
|
||||||
onNowPlayingItemDidChange(attributes: object): void {
|
onNowPlayingItemDidChange(attributes: object): void {
|
||||||
console.debug(`[Plugin][${mpris.name}] onMetadataDidChange.`);
|
console.debug(`[Plugin][${mpris.name}] onMetadataDidChange.`);
|
||||||
mpris.updatePlayer(attributes);
|
mpris.updatePlayer(attributes);
|
||||||
|
|
|
@ -47,7 +47,6 @@ export default class Thumbar {
|
||||||
/**
|
/**
|
||||||
* Update the thumbnail toolbar
|
* Update the thumbnail toolbar
|
||||||
*/
|
*/
|
||||||
@Thumbar.windowsOnly
|
|
||||||
private updateButtons(attributes: any) {
|
private updateButtons(attributes: any) {
|
||||||
|
|
||||||
console.log(attributes)
|
console.log(attributes)
|
||||||
|
@ -102,6 +101,7 @@ export default class Thumbar {
|
||||||
/**
|
/**
|
||||||
* Runs on app ready
|
* Runs on app ready
|
||||||
*/
|
*/
|
||||||
|
@Thumbar.windowsOnly
|
||||||
onReady(win: Electron.BrowserWindow): void {
|
onReady(win: Electron.BrowserWindow): void {
|
||||||
this._win = win;
|
this._win = win;
|
||||||
console.debug(`[Plugin][${this.name}] Ready.`);
|
console.debug(`[Plugin][${this.name}] Ready.`);
|
||||||
|
@ -110,6 +110,7 @@ export default class Thumbar {
|
||||||
/**
|
/**
|
||||||
* Runs on app stop
|
* Runs on app stop
|
||||||
*/
|
*/
|
||||||
|
@Thumbar.windowsOnly
|
||||||
onBeforeQuit(): void {
|
onBeforeQuit(): void {
|
||||||
console.debug(`[Plugin][${this.name}] Stopped.`);
|
console.debug(`[Plugin][${this.name}] Stopped.`);
|
||||||
}
|
}
|
||||||
|
@ -118,6 +119,7 @@ export default class Thumbar {
|
||||||
* Runs on playback State Change
|
* Runs on playback State Change
|
||||||
* @param attributes Music Attributes (attributes.status = current state)
|
* @param attributes Music Attributes (attributes.status = current state)
|
||||||
*/
|
*/
|
||||||
|
@Thumbar.windowsOnly
|
||||||
onPlaybackStateDidChange(attributes: object): void {
|
onPlaybackStateDidChange(attributes: object): void {
|
||||||
this.updateButtons(attributes)
|
this.updateButtons(attributes)
|
||||||
}
|
}
|
||||||
|
@ -126,6 +128,7 @@ export default class Thumbar {
|
||||||
* Runs on song change
|
* Runs on song change
|
||||||
* @param attributes Music Attributes
|
* @param attributes Music Attributes
|
||||||
*/
|
*/
|
||||||
|
@Thumbar.windowsOnly
|
||||||
onNowPlayingItemDidChange(attributes: object): void {
|
onNowPlayingItemDidChange(attributes: object): void {
|
||||||
this.updateButtons(attributes)
|
this.updateButtons(attributes)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue