Skip to content
This repository has been archived by the owner on May 18, 2024. It is now read-only.

Commit

Permalink
Merge branch 'develop' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
coredev-uk authored Feb 17, 2022
2 parents a02b633 + 16c0f84 commit 5fa345e
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 66 deletions.
3 changes: 2 additions & 1 deletion src/main/base/browserwindow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ export class BrowserWindow {
y: undefined,
minWidth: 900,
minHeight: 390,
frame: false,
frame: (process.platform === "linux"),
title: "Cider",
vibrancy: "fullscreen-ui",
transparent: process.platform === "darwin",
Expand Down Expand Up @@ -130,6 +130,7 @@ export class BrowserWindow {
this.startWebServer();

BrowserWindow.win = new bw(this.options);
BrowserWindow.win.setMenuBarVisibility(false)
const ws = new wsapi(BrowserWindow.win)
ws.InitWebSockets()
// and load the renderer.
Expand Down
1 change: 0 additions & 1 deletion src/main/base/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ export class Store {
"close_button_hide": false,
"open_on_startup": false,
"discord_rpc": 1, // 0 = disabled, 1 = enabled as Cider, 2 = enabled as Apple Music
"discord_rpc_clear_on_pause": true,
"language": "en_US", // electron.app.getLocale().replace('-', '_') this can be used in future
"playbackNotifications": true,
"update_branch": "main"
Expand Down
98 changes: 42 additions & 56 deletions src/main/plugins/discordrpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ export default class DiscordRichPresence {
* Private variables for interaction in plugins
*/
private static _store: any;
private _app : any;
private _attributes : any;
private _app: any;
private _attributes: any;
private static _connection: boolean = false;

/**
Expand Down Expand Up @@ -76,10 +76,10 @@ export default class DiscordRichPresence {

// Login to Discord
this._client.login({clientId})
.then(() => {
DiscordRichPresence._connection = true;
})
.catch((e: any) => console.error(`[DiscordRichPresence][connect] ${e}`));
.then(() => {
DiscordRichPresence._connection = true;
})
.catch((e: any) => console.error(`[DiscordRichPresence][connect] ${e}`));
}

/**
Expand All @@ -94,43 +94,43 @@ export default class DiscordRichPresence {
}).catch((e: any) => console.error(`[DiscordRPC][disconnect] ${e}`));
}

/**
* Filter the Discord activity object
*/
private filterActivity(activity: any, attributes: any): Object {
// Checks if the name is greater than 128 because some songs can be that long
/**
* Filter the Discord activity object
*/
private filterActivity(activity: any, attributes: any): Object {

// Checks if the name is greater than 128 because some songs can be that long
if (activity.details && activity.details.length > 128) {
activity.details = activity.details.substring(0, 125) + '...'
}

// Check large image
if (activity.largeImageKey == null || activity.largeImageKey === "" || activity.largeImageKey.length > 256) {
// Check large image
if (activity.largeImageKey == null || activity.largeImageKey === "" || activity.largeImageKey.length > 256) {
activity.largeImageKey = "cider";
}

// Timestamp
if (new Date(attributes.endTime).getTime() < 0) {
delete activity.startTime
delete activity.endTime
}
// Timestamp
if (new Date(attributes.endTime).getTime() < 0) {
delete activity.startTime
delete activity.endTime
}

// not sure
if (!attributes.artistName) {
delete activity.state;
}
// not sure
if (!attributes.artistName) {
delete activity.state;
}

if (!activity.largeImageText || activity.largeImageText.length < 2) {
if (!activity.largeImageText || activity.largeImageText.length < 2) {
delete activity.largeImageText
}

activity.buttons.forEach((key: {label: string, url: string}, _v: Number) => {
if (key.url.includes('undefined') || key.url.includes('no-id-found')) {
activity.buttons.forEach((key: { label: string, url: string }, _v: Number) => {
if (key.url.includes('undefined') || key.url.includes('no-id-found')) {
activity.buttons.splice(key, 1);
}
})
return activity
}
}
})
return activity
}

/**
* Sets the activity of the client
Expand Down Expand Up @@ -158,29 +158,15 @@ export default class DiscordRichPresence {
]
};

this._activity = this.filterActivity(this._activity, attributes)
this._activity = this.filterActivity(this._activity, attributes)

// Check if its pausing (false) or playing (true)
if (!attributes.status) {
if (DiscordRichPresence._store.general.discord_rpc_clear_on_pause) {
this._client.clearActivity()
this._client.clearActivity()
.catch((e: any) => console.error(`[DiscordRichPresence][clearActivity] ${e}`));
} else {
this._activity.smallImageKey = 'pause';
this._activity.smallImageText = 'Paused';
delete this._activity.endTimestamp;
delete this._activity.startTimestamp;
this._client.setActivity(this._activity)
.catch((e: any) => console.error(`[DiscordRichPresence][setActivity] ${e}`));
}
} else if (this._activity && this._activityCache !== this._activity && this._activity.details) {
if (!DiscordRichPresence._store.general.discord_rpc_clear_on_pause) {
this._activity.smallImageKey = 'play';
this._activity.smallImageText = 'Playing';
}

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;
}

Expand All @@ -207,21 +193,21 @@ export default class DiscordRichPresence {
this.connect((DiscordRichPresence._store.general.discord_rpc == 1) ? '911790844204437504' : '886578863147192350');
console.debug(`[Plugin][${this.name}] Ready.`);
ipcMain.on('updateRPCImage', (_event, imageurl) => {
fetch('https://api.cider.sh/v1/images' ,{
fetch('https://api.cider.sh/v1/images', {

method: 'POST',
body: JSON.stringify({url : imageurl}),
headers: {
body: JSON.stringify({url: imageurl}),
headers: {
'Content-Type': 'application/json',
'User-Agent': _win.webContents.getUserAgent()
},
})
.then(res => res.json())
.then(function(json){
self._attributes["artwork"]["url"] = json.url
self.updateActivity(self._attributes)
})
.then(res => res.json())
.then(function (json) {
self._attributes["artwork"]["url"] = json.url
self.updateActivity(self._attributes)
})

})
}

Expand Down
4 changes: 4 additions & 0 deletions src/renderer/style.less
Original file line number Diff line number Diff line change
Expand Up @@ -3134,6 +3134,10 @@ body[platform='darwin'] {
}
}

body[platform='linux'] #window-controls-container {
display: none;
}

.percent {
display: inline-block;
position: relative;
Expand Down
8 changes: 0 additions & 8 deletions src/renderer/views/pages/settings.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -568,14 +568,6 @@
</select>
</div>
</div>
<div class="md-option-line" v-show="app.cfg.general.discord_rpc != 0">
<div class="md-option-segment">
{{$root.getLz('settings.option.connectivity.discordRPC.clearOnPause')}}
</div>
<div class="md-option-segment md-option-segment_auto">
<input type="checkbox" v-model="app.cfg.general.discord_rpc_clear_on_pause" switch/>
</div>
</div>
<div class="md-option-line">
<div class="md-option-segment">
{{$root.getLz('settings.option.connectivity.lastfmScrobble')}}
Expand Down

0 comments on commit 5fa345e

Please sign in to comment.