Skip to content
This repository has been archived by the owner on Mar 7, 2023. It is now read-only.

Commit

Permalink
Play/Pause state fix.
Browse files Browse the repository at this point in the history
  • Loading branch information
Braasileiro committed Aug 11, 2021
1 parent 024143d commit 490ff22
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 21 deletions.
3 changes: 1 addition & 2 deletions package-assets.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
const fs = require('fs');
const shell = require('shelljs');

shell.cp('-R', './source/view', './build/');
shell.cp('./source/input.js', "./build/input.js");
shell.cp('-R', './src/view', './build/');

if (!fs.existsSync('./build/assets')) {
shell.mkdir('./build/assets');
Expand Down
12 changes: 7 additions & 5 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { app, BrowserWindow, Tray, Menu, ipcMain, dialog, globalShortcut, native

const RPC = new Client({ transport: 'ipc' });
const APP_PACKAGE = require('../package.json');
const APP_PREFERENCES = new Configstore(APP_PACKAGE.name, { "closeToTray": false, "minimizeToTray": false });
const APP_PREFERENCES = new Configstore(APP_PACKAGE.name, { 'closeToTray': false, 'minimizeToTray': false });

var tray: Tray;

Expand All @@ -19,7 +19,7 @@ function main() {
const url = 'https://raw.githubusercontent.com/Braasileiro/DeezerRPC/master/package.json';

checkUrl(url)
.then(() => got(url).then(response => {
.then(() => got(url).then((response: any) => {
const json = JSON.parse(response.body);

if (json.version != APP_PACKAGE.version) {
Expand All @@ -38,6 +38,8 @@ function main() {
} else {
createMainWindow();
}
} else {
createMainWindow();
}
})
)
Expand All @@ -55,16 +57,16 @@ function createMainWindow() {
// User agent
switch (process.platform) {
case 'linux':
userAgent = 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.212 Safari/537.36'
userAgent = 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.131 Safari/537.36'
break;

case 'darwin':
userAgent = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 11_3_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.212 Safari/537.36'
userAgent = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 11_5_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.131 Safari/537.36'
break;

// win32
default:
userAgent = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.212 Safari/537.36'
userAgent = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.131 Safari/537.36'
break;
}

Expand Down
30 changes: 16 additions & 14 deletions src/preload.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import moment from 'moment'
import dayjs from 'dayjs';
import Song from './model/Song';
import { ipcRenderer } from 'electron';


function initializeListeners() {
setInterval(function () {
const songContent = document.querySelector("div.marquee-content")?.querySelectorAll("a.track-link")
const isListening = document.querySelector("button.svg-icon-group-btn.is-highlight")?.querySelector("svg.svg-icon.svg-icon-pause") != null
const songContent = document.querySelector('div.marquee-content')?.querySelectorAll('a.track-link');
const isListening = !(document.querySelector('button.svg-icon-group-btn.is-highlight > svg > g > path')?.outerHTML == '<path d="m5 2 18 10L5 22V2z"></path>');

if (songContent != null && songContent.length > 0) {
ipcRenderer.send('song-changed', new Song(
Expand All @@ -19,20 +19,20 @@ function initializeListeners() {
return;
}

const queueContent = document.querySelector("div.queuelist-cover-title")
const queueContent = document.querySelector('div.queuelist-cover-title');

if (queueContent != null) {
ipcRenderer.send('song-changed', new Song(
queueContent.textContent!,
document.querySelector("div.queuelist-cover-subtitle")?.textContent!,
document.querySelector('div.queuelist-cover-subtitle')?.textContent!,
timestamp(),
isListening
));

return;
}

const customContent = document.querySelector("div.marquee-content")?.textContent?.split(" · ");
const customContent = document.querySelector('div.marquee-content')?.textContent?.split(" · ");

if (customContent != null) {
ipcRenderer.send('song-changed', new Song(
Expand All @@ -46,14 +46,16 @@ function initializeListeners() {
}

function timestamp(): number {
const sMax = document.querySelector("div.slider-counter.slider-counter-max")!.textContent
const sCurrent = document.querySelector("div.slider-counter.slider-counter-current")!.textContent

return moment(Date.now())
.add(sMax?.substring(0, 2), "m")
.add(sMax?.substring(3), "s")
.subtract(sCurrent?.substring(0, 2), "m")
.subtract(sCurrent?.substring(3), "s")
const sMax = document.querySelector('div.slider-counter.slider-counter-max')!.textContent;
const sCurrent = document.querySelector('div.slider-counter.slider-counter-current')!.textContent;

if (!sMax || !sCurrent) return 0;

return dayjs(Date.now())
.add(parseInt(sMax?.substring(0, 2)), 'm')
.add(parseInt(sMax?.substring(3)), 's')
.subtract(parseInt(sCurrent?.substring(0, 2)), 'm')
.subtract(parseInt(sCurrent?.substring(3)), 's')
.unix();
}

Expand Down

0 comments on commit 490ff22

Please sign in to comment.