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

This commit is contained in:
Core 2021-12-19 06:02:38 +00:00
parent 29be5dd481
commit 7d3e513187
85 changed files with 114 additions and 10 deletions

View file

@ -16,7 +16,7 @@ function CreateWindow() {
}); });
/** CIDER **/ /** CIDER **/
const ciderwin = require("./resources/functions/cider-base") const ciderwin = require("./src/main/cider-base")
app.win = ciderwin app.win = ciderwin
app.win.CreateBrowserWindow() app.win.CreateBrowserWindow()
/** CIDER **/ /** CIDER **/
@ -37,9 +37,7 @@ app.on('ready', () => {
app.on('before-quit', () => { app.on('before-quit', () => {
app.isQuiting = true; app.isQuiting = true;
console.warn('---------------------------------------------------------------------'); console.warn(`${app.getName()} exited.`);
console.warn(`${app.getName()} has closed.`);
console.warn('---------------------------------------------------------------------');
}); });
// Widevine Stuff // Widevine Stuff

View file

@ -30,6 +30,7 @@
"electron-window-state": "^5.0.3", "electron-window-state": "^5.0.3",
"express": "^4.17.2", "express": "^4.17.2",
"get-port": "^5.1.1", "get-port": "^5.1.1",
"mpris-service": "^2.1.2",
"react": "^17.0.2", "react": "^17.0.2",
"react-dom": "^17.0.2", "react-dom": "^17.0.2",
"source-map-support": "^0.5.21", "source-map-support": "^0.5.21",
@ -87,14 +88,12 @@
"extends": null, "extends": null,
"files": [ "files": [
"**/*", "**/*",
"./src/**/*",
"./resources/icons/icon.*" "./resources/icons/icon.*"
], ],
"linux": { "linux": {
"target": [ "target": [
"AppImage", "pacman"
"deb",
"snap",
"rpm"
], ],
"synopsis": "A new look into listening and enjoying music in style and performance. ", "synopsis": "A new look into listening and enjoying music in style and performance. ",
"category": "AudioVideo", "category": "AudioVideo",

View file

@ -21,7 +21,7 @@ const CiderBase = {
let win = null let win = null
const options = { const options = {
icon: join(__dirname, `../icons/icon.ico`), icon: join(__dirname, `../../resources/icons/icon.ico`),
width: mainWindowState.width, width: mainWindowState.width,
height: mainWindowState.height, height: mainWindowState.height,
x: mainWindowState.x, x: mainWindowState.x,
@ -174,7 +174,7 @@ const CiderBase = {
async InitWebServer() { async InitWebServer() {
const webRemotePort = await getPort({port : 9000}); const webRemotePort = await getPort({port : 9000});
const webapp = express(); 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("views", path.join(webRemotePath, "views"));
webapp.set("view engine", "ejs"); webapp.set("view engine", "ejs");

5
src/main/init.js Normal file
View 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
View 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';
},
}

View file

Before

Width:  |  Height:  |  Size: 1.6 KiB

After

Width:  |  Height:  |  Size: 1.6 KiB

Before After
Before After

View file

Before

Width:  |  Height:  |  Size: 521 B

After

Width:  |  Height:  |  Size: 521 B

Before After
Before After

View file

Before

Width:  |  Height:  |  Size: 500 B

After

Width:  |  Height:  |  Size: 500 B

Before After
Before After

View file

Before

Width:  |  Height:  |  Size: 1.4 KiB

After

Width:  |  Height:  |  Size: 1.4 KiB

Before After
Before After

View file

Before

Width:  |  Height:  |  Size: 511 B

After

Width:  |  Height:  |  Size: 511 B

Before After
Before After

View file

Before

Width:  |  Height:  |  Size: 493 B

After

Width:  |  Height:  |  Size: 493 B

Before After
Before After

View file

Before

Width:  |  Height:  |  Size: 831 B

After

Width:  |  Height:  |  Size: 831 B

Before After
Before After

View file

Before

Width:  |  Height:  |  Size: 17 KiB

After

Width:  |  Height:  |  Size: 17 KiB

Before After
Before After

View file

Before

Width:  |  Height:  |  Size: 12 KiB

After

Width:  |  Height:  |  Size: 12 KiB

Before After
Before After

View file

Before

Width:  |  Height:  |  Size: 487 B

After

Width:  |  Height:  |  Size: 487 B

Before After
Before After

View file

Before

Width:  |  Height:  |  Size: 384 B

After

Width:  |  Height:  |  Size: 384 B

Before After
Before After

View file

Before

Width:  |  Height:  |  Size: 640 B

After

Width:  |  Height:  |  Size: 640 B

Before After
Before After

View file

Before

Width:  |  Height:  |  Size: 1.6 KiB

After

Width:  |  Height:  |  Size: 1.6 KiB

Before After
Before After

View file

Before

Width:  |  Height:  |  Size: 618 B

After

Width:  |  Height:  |  Size: 618 B

Before After
Before After

View file

Before

Width:  |  Height:  |  Size: 1.6 KiB

After

Width:  |  Height:  |  Size: 1.6 KiB

Before After
Before After

View file

Before

Width:  |  Height:  |  Size: 584 B

After

Width:  |  Height:  |  Size: 584 B

Before After
Before After

View file

Before

Width:  |  Height:  |  Size: 710 B

After

Width:  |  Height:  |  Size: 710 B

Before After
Before After

View file

Before

Width:  |  Height:  |  Size: 1.2 KiB

After

Width:  |  Height:  |  Size: 1.2 KiB

Before After
Before After

View file

Before

Width:  |  Height:  |  Size: 33 KiB

After

Width:  |  Height:  |  Size: 33 KiB

Before After
Before After

View file

Before

Width:  |  Height:  |  Size: 531 B

After

Width:  |  Height:  |  Size: 531 B

Before After
Before After

View file

Before

Width:  |  Height:  |  Size: 1.3 KiB

After

Width:  |  Height:  |  Size: 1.3 KiB

Before After
Before After

View file

Before

Width:  |  Height:  |  Size: 518 B

After

Width:  |  Height:  |  Size: 518 B

Before After
Before After

View file

Before

Width:  |  Height:  |  Size: 538 B

After

Width:  |  Height:  |  Size: 538 B

Before After
Before After

View file

Before

Width:  |  Height:  |  Size: 1.1 KiB

After

Width:  |  Height:  |  Size: 1.1 KiB

Before After
Before After

View file

Before

Width:  |  Height:  |  Size: 772 B

After

Width:  |  Height:  |  Size: 772 B

Before After
Before After

View file

Before

Width:  |  Height:  |  Size: 409 B

After

Width:  |  Height:  |  Size: 409 B

Before After
Before After

View file

Before

Width:  |  Height:  |  Size: 622 B

After

Width:  |  Height:  |  Size: 622 B

Before After
Before After