File structure update - all source files now in src directory, cider-ui renamed to renderer, main/backend-related files in main directory, base implementation of mpris and start of backend rework
6
index.js
|
@ -16,7 +16,7 @@ function CreateWindow() {
|
|||
});
|
||||
|
||||
/** CIDER **/
|
||||
const ciderwin = require("./resources/functions/cider-base")
|
||||
const ciderwin = require("./src/main/cider-base")
|
||||
app.win = ciderwin
|
||||
app.win.CreateBrowserWindow()
|
||||
/** CIDER **/
|
||||
|
@ -37,9 +37,7 @@ app.on('ready', () => {
|
|||
|
||||
app.on('before-quit', () => {
|
||||
app.isQuiting = true;
|
||||
console.warn('---------------------------------------------------------------------');
|
||||
console.warn(`${app.getName()} has closed.`);
|
||||
console.warn('---------------------------------------------------------------------');
|
||||
console.warn(`${app.getName()} exited.`);
|
||||
});
|
||||
|
||||
// Widevine Stuff
|
||||
|
|
|
@ -30,6 +30,7 @@
|
|||
"electron-window-state": "^5.0.3",
|
||||
"express": "^4.17.2",
|
||||
"get-port": "^5.1.1",
|
||||
"mpris-service": "^2.1.2",
|
||||
"react": "^17.0.2",
|
||||
"react-dom": "^17.0.2",
|
||||
"source-map-support": "^0.5.21",
|
||||
|
@ -87,14 +88,12 @@
|
|||
"extends": null,
|
||||
"files": [
|
||||
"**/*",
|
||||
"./src/**/*",
|
||||
"./resources/icons/icon.*"
|
||||
],
|
||||
"linux": {
|
||||
"target": [
|
||||
"AppImage",
|
||||
"deb",
|
||||
"snap",
|
||||
"rpm"
|
||||
"pacman"
|
||||
],
|
||||
"synopsis": "A new look into listening and enjoying music in style and performance. ",
|
||||
"category": "AudioVideo",
|
||||
|
|
|
@ -21,7 +21,7 @@ const CiderBase = {
|
|||
|
||||
let win = null
|
||||
const options = {
|
||||
icon: join(__dirname, `../icons/icon.ico`),
|
||||
icon: join(__dirname, `../../resources/icons/icon.ico`),
|
||||
width: mainWindowState.width,
|
||||
height: mainWindowState.height,
|
||||
x: mainWindowState.x,
|
||||
|
@ -174,7 +174,7 @@ const CiderBase = {
|
|||
async InitWebServer() {
|
||||
const webRemotePort = await getPort({port : 9000});
|
||||
const webapp = express();
|
||||
const webRemotePath = path.join(__dirname, '../cider-ui/');
|
||||
const webRemotePath = path.join(__dirname, '../renderer/');
|
||||
webapp.set("views", path.join(webRemotePath, "views"));
|
||||
webapp.set("view engine", "ejs");
|
||||
|
5
src/main/init.js
Normal file
|
@ -0,0 +1,5 @@
|
|||
const {app} = require('electron');
|
||||
|
||||
module.export = () => {
|
||||
if (process.platform === "linux") app.commandLine.appendSwitch('disable-features', 'MediaSessionService');
|
||||
}
|
102
src/main/mpris.js
Normal file
|
@ -0,0 +1,102 @@
|
|||
const {app} = require('electron'),
|
||||
Player = require('mpris-service');
|
||||
|
||||
// Remember to use playerctl when debugging this.
|
||||
// I'm just putting this here as I keep forgetting the command.
|
||||
// Copied from AME
|
||||
|
||||
let mediaPlayer;
|
||||
|
||||
module.exports = {
|
||||
connect: (win) => {
|
||||
if (process.platform !== "linux") return;
|
||||
|
||||
mediaPlayer = Player({
|
||||
name: 'Cider',
|
||||
identity: 'Cider',
|
||||
supportedUriSchemes: [],
|
||||
supportedMimeTypes: [],
|
||||
supportedInterfaces: ['player']
|
||||
});
|
||||
mediaPlayer = Object.assign(mediaPlayer, { canQuit: true, canControl: true, canPause: true, canPlay: true, canGoNext: true })
|
||||
|
||||
|
||||
let pos_atr = {durationInMillis: 0};
|
||||
mediaPlayer.getPosition = function () {
|
||||
const durationInMicro = pos_atr.durationInMillis * 1000;
|
||||
const percentage = parseFloat(0) || 0;
|
||||
return durationInMicro * percentage;
|
||||
}
|
||||
|
||||
mediaPlayer.active = true
|
||||
|
||||
mediaPlayer.on('playpause', async () => {
|
||||
win.webContents.executeJavaScript('MusicKitInterop.pausePlay()').catch(err => console.error(err))
|
||||
});
|
||||
|
||||
mediaPlayer.on('play', async () => {
|
||||
win.webContents.executeJavaScript('MusicKitInterop.pausePlay()').catch(err => console.error(err))
|
||||
});
|
||||
|
||||
mediaPlayer.on('pause', async () => {
|
||||
win.webContents.executeJavaScript('MusicKitInterop.pausePlay()').catch(err => console.error(err))
|
||||
});
|
||||
|
||||
mediaPlayer.on('next', async () => {
|
||||
win.webContents.executeJavaScript('MusicKitInterop.nextTrack()').catch(err => console.error(err))
|
||||
});
|
||||
|
||||
mediaPlayer.on('previous', async () => {
|
||||
win.webContents.executeJavaScript('MusicKitInterop.previousTrack()').catch(err => console.error(err))
|
||||
});
|
||||
},
|
||||
|
||||
updateAttributes: (attributes) => {
|
||||
if (process.platform !== "linux") return;
|
||||
|
||||
const MetaData = {
|
||||
'mpris:trackid': mediaPlayer.objectPath(`track/${attributes.playParams.id.replace(/[.]+/g, "")}`),
|
||||
'mpris:length': attributes.durationInMillis * 1000, // In microseconds
|
||||
'mpris:artUrl': (attributes.artwork.url.replace('/{w}x{h}bb', '/512x512bb')).replace('/2000x2000bb', '/35x35bb'),
|
||||
'xesam:title': `${attributes.name}`,
|
||||
'xesam:album': `${attributes.albumName}`,
|
||||
'xesam:artist': [`${attributes.artistName}`,],
|
||||
'xesam:genre': attributes.genreNames
|
||||
}
|
||||
|
||||
if (mediaPlayer.metadata["mpris:trackid"] === MetaData["mpris:trackid"]) {
|
||||
return
|
||||
}
|
||||
|
||||
mediaPlayer.metadata = MetaData
|
||||
},
|
||||
|
||||
updateState: (attributes) => {
|
||||
if (process.platform !== "linux") return;
|
||||
|
||||
function setPlaybackIfNeeded(status) {
|
||||
if (mediaPlayer.playbackStatus === status) {
|
||||
return
|
||||
}
|
||||
mediaPlayer.playbackStatus = status;
|
||||
}
|
||||
|
||||
switch (attributes.status) {
|
||||
case true: // Playing
|
||||
setPlaybackIfNeeded('Playing');
|
||||
break;
|
||||
case false: // Paused
|
||||
setPlaybackIfNeeded('Paused');
|
||||
break;
|
||||
default: // Stopped
|
||||
setPlaybackIfNeeded('Stopped');
|
||||
break;
|
||||
}
|
||||
},
|
||||
|
||||
clearActivity: () => {
|
||||
if (process.platform !== "linux") return;
|
||||
mediaPlayer.metadata = {'mpris:trackid': '/org/mpris/MediaPlayer2/TrackList/NoTrack'}
|
||||
mediaPlayer.playbackStatus = 'Stopped';
|
||||
},
|
||||
}
|
Before Width: | Height: | Size: 1.6 KiB After Width: | Height: | Size: 1.6 KiB |
Before Width: | Height: | Size: 521 B After Width: | Height: | Size: 521 B |
Before Width: | Height: | Size: 500 B After Width: | Height: | Size: 500 B |
Before Width: | Height: | Size: 1.4 KiB After Width: | Height: | Size: 1.4 KiB |
Before Width: | Height: | Size: 511 B After Width: | Height: | Size: 511 B |
Before Width: | Height: | Size: 493 B After Width: | Height: | Size: 493 B |
Before Width: | Height: | Size: 831 B After Width: | Height: | Size: 831 B |
Before Width: | Height: | Size: 17 KiB After Width: | Height: | Size: 17 KiB |
Before Width: | Height: | Size: 12 KiB After Width: | Height: | Size: 12 KiB |
Before Width: | Height: | Size: 487 B After Width: | Height: | Size: 487 B |
Before Width: | Height: | Size: 384 B After Width: | Height: | Size: 384 B |
Before Width: | Height: | Size: 640 B After Width: | Height: | Size: 640 B |
Before Width: | Height: | Size: 1.6 KiB After Width: | Height: | Size: 1.6 KiB |
Before Width: | Height: | Size: 618 B After Width: | Height: | Size: 618 B |
Before Width: | Height: | Size: 1.6 KiB After Width: | Height: | Size: 1.6 KiB |
Before Width: | Height: | Size: 584 B After Width: | Height: | Size: 584 B |
Before Width: | Height: | Size: 710 B After Width: | Height: | Size: 710 B |
Before Width: | Height: | Size: 1.2 KiB After Width: | Height: | Size: 1.2 KiB |
Before Width: | Height: | Size: 33 KiB After Width: | Height: | Size: 33 KiB |
Before Width: | Height: | Size: 531 B After Width: | Height: | Size: 531 B |
Before Width: | Height: | Size: 1.3 KiB After Width: | Height: | Size: 1.3 KiB |
Before Width: | Height: | Size: 518 B After Width: | Height: | Size: 518 B |
Before Width: | Height: | Size: 538 B After Width: | Height: | Size: 538 B |
Before Width: | Height: | Size: 1.1 KiB After Width: | Height: | Size: 1.1 KiB |
Before Width: | Height: | Size: 772 B After Width: | Height: | Size: 772 B |
Before Width: | Height: | Size: 409 B After Width: | Height: | Size: 409 B |
Before Width: | Height: | Size: 622 B After Width: | Height: | Size: 622 B |