setting up files for new caching method
This commit is contained in:
parent
ee2b332350
commit
9ffc065772
3 changed files with 86 additions and 13 deletions
17
index.js
17
index.js
|
@ -1,6 +1,6 @@
|
||||||
require('v8-compile-cache');
|
require('v8-compile-cache');
|
||||||
const {app, components} = require('electron'),
|
const {app, components} = require('electron'),
|
||||||
{resolve} = require("path"),
|
{resolve, join} = require("path"),
|
||||||
CiderBase = require('./src/main/cider-base');
|
CiderBase = require('./src/main/cider-base');
|
||||||
|
|
||||||
// Analytics for debugging.
|
// Analytics for debugging.
|
||||||
|
@ -27,8 +27,8 @@ const configDefaults = {
|
||||||
"spatial_properties": {
|
"spatial_properties": {
|
||||||
"presets": [],
|
"presets": [],
|
||||||
"gain": 0.8,
|
"gain": 0.8,
|
||||||
"listener_position": [0,0,0],
|
"listener_position": [0, 0, 0],
|
||||||
"audio_position": [0,0,0],
|
"audio_position": [0, 0, 0],
|
||||||
"room_dimensions": {
|
"room_dimensions": {
|
||||||
"width": 32,
|
"width": 32,
|
||||||
"height": 12,
|
"height": 12,
|
||||||
|
@ -75,15 +75,13 @@ const configDefaults = {
|
||||||
const merge = (target, source) => {
|
const merge = (target, source) => {
|
||||||
// Iterate through `source` properties and if an `Object` set property to merge of `target` and `source` properties
|
// Iterate through `source` properties and if an `Object` set property to merge of `target` and `source` properties
|
||||||
for (const key of Object.keys(source)) {
|
for (const key of Object.keys(source)) {
|
||||||
if (source[key] instanceof Object) Object.assign(source[key], merge(target[key], source[key]))
|
if (source[key] instanceof Object) Object.assign(source[key], merge(target[key], source[key]))
|
||||||
}
|
}
|
||||||
// Join `target` and modified `source`
|
// Join `target` and modified `source`
|
||||||
Object.assign(target || {}, source)
|
Object.assign(target || {}, source)
|
||||||
return target
|
return target
|
||||||
}
|
}
|
||||||
|
|
||||||
// Enable WebGPU and list adapters (EXPERIMENTAL.)
|
|
||||||
// Note: THIS HAS TO BE BEFORE ANYTHING GETS INITIALIZED.
|
|
||||||
|
|
||||||
const Store = require("electron-store");
|
const Store = require("electron-store");
|
||||||
app.cfg = new Store({
|
app.cfg = new Store({
|
||||||
|
@ -92,6 +90,11 @@ app.cfg = new Store({
|
||||||
let currentCfg = app.cfg.get()
|
let currentCfg = app.cfg.get()
|
||||||
app.cfg.set(merge(configDefaults, currentCfg))
|
app.cfg.set(merge(configDefaults, currentCfg))
|
||||||
|
|
||||||
|
app.paths = {
|
||||||
|
ciderCache: resolve(app.getPath("userData"), "CiderCache"),
|
||||||
|
themes: resolve(app.getPath("userData"), "Themes"),
|
||||||
|
plugins: resolve(app.getPath("userData"), "Plugins"),
|
||||||
|
}
|
||||||
|
|
||||||
switch (app.cfg.get("visual.hw_acceleration")) {
|
switch (app.cfg.get("visual.hw_acceleration")) {
|
||||||
default:
|
default:
|
||||||
|
|
|
@ -8,7 +8,8 @@ const os = require('os');
|
||||||
const yt = require('youtube-search-without-api-key');
|
const yt = require('youtube-search-without-api-key');
|
||||||
const discord = require('./discordrpc');
|
const discord = require('./discordrpc');
|
||||||
const lastfm = require('./lastfm');
|
const lastfm = require('./lastfm');
|
||||||
const { writeFile } = require('fs');
|
const { writeFile, writeFileSync, existsSync, mkdirSync } = require('fs');
|
||||||
|
const fs = require('fs');
|
||||||
const mpris = require('./mpris');
|
const mpris = require('./mpris');
|
||||||
const mm = require('music-metadata');
|
const mm = require('music-metadata');
|
||||||
const fetch = require('electron-fetch').default;
|
const fetch = require('electron-fetch').default;
|
||||||
|
@ -28,6 +29,7 @@ const CiderBase = {
|
||||||
},
|
},
|
||||||
clientPort: 0,
|
clientPort: 0,
|
||||||
CreateBrowserWindow() {
|
CreateBrowserWindow() {
|
||||||
|
this.VerifyFiles()
|
||||||
// Set default window sizes
|
// Set default window sizes
|
||||||
const mainWindowState = windowStateKeeper({
|
const mainWindowState = windowStateKeeper({
|
||||||
defaultWidth: 1024,
|
defaultWidth: 1024,
|
||||||
|
@ -132,6 +134,51 @@ const CiderBase = {
|
||||||
win.close();
|
win.close();
|
||||||
})
|
})
|
||||||
|
|
||||||
|
ipcMain.on('put-library-songs', (event, arg) => {
|
||||||
|
fs.writeFileSync(join(app.paths.ciderCache, "library-songs.json"), JSON.stringify(arg))
|
||||||
|
})
|
||||||
|
|
||||||
|
ipcMain.on('put-library-artists', (event, arg) => {
|
||||||
|
fs.writeFileSync(join(app.paths.ciderCache, "library-artists.json"), JSON.stringify(arg))
|
||||||
|
})
|
||||||
|
|
||||||
|
ipcMain.on('put-library-albums', (event, arg) => {
|
||||||
|
fs.writeFileSync(join(app.paths.ciderCache, "library-albums.json"), JSON.stringify(arg))
|
||||||
|
})
|
||||||
|
|
||||||
|
ipcMain.on('put-library-playlists', (event, arg) => {
|
||||||
|
fs.writeFileSync(join(app.paths.ciderCache, "library-playlists.json"), JSON.stringify(arg))
|
||||||
|
})
|
||||||
|
|
||||||
|
ipcMain.on('put-library-recentlyAdded', (event, arg) => {
|
||||||
|
fs.writeFileSync(join(app.paths.ciderCache, "library-recentlyAdded.json"), JSON.stringify(arg))
|
||||||
|
})
|
||||||
|
|
||||||
|
ipcMain.on('get-library-songs', (event) => {
|
||||||
|
let librarySongs = fs.readFileSync(join(app.paths.ciderCache, "library-songs.json"), "utf8")
|
||||||
|
event.returnValue = JSON.parse(librarySongs)
|
||||||
|
})
|
||||||
|
|
||||||
|
ipcMain.on('get-library-artists', (event) => {
|
||||||
|
let libraryArtists = fs.readFileSync(join(app.paths.ciderCache, "library-artists.json"), "utf8")
|
||||||
|
event.returnValue = JSON.parse(libraryArtists)
|
||||||
|
})
|
||||||
|
|
||||||
|
ipcMain.on('get-library-albums', (event) => {
|
||||||
|
let libraryAlbums = fs.readFileSync(join(app.paths.ciderCache, "library-albums.json"), "utf8")
|
||||||
|
event.returnValue = JSON.parse(libraryAlbums)
|
||||||
|
})
|
||||||
|
|
||||||
|
ipcMain.on('get-library-playlists', (event) => {
|
||||||
|
let libraryPlaylists = fs.readFileSync(join(app.paths.ciderCache, "library-playlists.json"), "utf8")
|
||||||
|
event.returnValue = JSON.parse(libraryPlaylists)
|
||||||
|
})
|
||||||
|
|
||||||
|
ipcMain.on('get-library-recentlyAdded', (event) => {
|
||||||
|
let libraryRecentlyAdded = fs.readFileSync(join(app.paths.ciderCache, "library-recentlyAdded.json"), "utf8")
|
||||||
|
event.returnValue = JSON.parse(libraryRecentlyAdded)
|
||||||
|
})
|
||||||
|
|
||||||
ipcMain.handle('getYTLyrics', async (event, track, artist) => {
|
ipcMain.handle('getYTLyrics', async (event, track, artist) => {
|
||||||
var u = track + " " + artist + " official video";
|
var u = track + " " + artist + " official video";
|
||||||
const videos = await yt.search(u);
|
const videos = await yt.search(u);
|
||||||
|
@ -258,7 +305,29 @@ const CiderBase = {
|
||||||
|
|
||||||
return win
|
return win
|
||||||
},
|
},
|
||||||
|
VerifyFiles() {
|
||||||
|
const expectedDirectories = [
|
||||||
|
"CiderCache"
|
||||||
|
]
|
||||||
|
const expectedFiles = [
|
||||||
|
"library-songs.json",
|
||||||
|
"library-artists.json",
|
||||||
|
"library-albums.json",
|
||||||
|
"library-playlists.json",
|
||||||
|
"library-recentlyAdded.json",
|
||||||
|
]
|
||||||
|
for (let i = 0; i < expectedDirectories.length; i++) {
|
||||||
|
if (!existsSync(path.join(app.getPath("userData"), expectedDirectories[i]))) {
|
||||||
|
mkdirSync(path.join(app.getPath("userData"), expectedDirectories[i]))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (let i = 0; i < expectedFiles.length; i++) {
|
||||||
|
const file = path.join(app.paths.ciderCache, expectedFiles[i])
|
||||||
|
if (!existsSync(file)) {
|
||||||
|
writeFileSync(file, JSON.stringify([]))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
EnvironmentVariables: {
|
EnvironmentVariables: {
|
||||||
"env": {
|
"env": {
|
||||||
platform: os.platform(),
|
platform: os.platform(),
|
||||||
|
|
|
@ -103,10 +103,10 @@ Array.prototype.limit = function (n) {
|
||||||
const store = new Vuex.Store({
|
const store = new Vuex.Store({
|
||||||
state: {
|
state: {
|
||||||
library: {
|
library: {
|
||||||
songs: [],
|
songs: ipcRenderer.sendSync("get-library-songs"),
|
||||||
albums: [],
|
albums: ipcRenderer.sendSync("get-library-albums"),
|
||||||
recentlyAdded: [],
|
recentlyAdded: ipcRenderer.sendSync("get-library-recentlyAdded"),
|
||||||
playlists: []
|
playlists: ipcRenderer.sendSync("get-library-playlists")
|
||||||
},
|
},
|
||||||
artwork: {
|
artwork: {
|
||||||
playerLCD: ""
|
playerLCD: ""
|
||||||
|
@ -2856,6 +2856,7 @@ const app = new Vue({
|
||||||
menus.normal.items = menus.normal.items.concat(this.contextExt.normal)
|
menus.normal.items = menus.normal.items.concat(this.contextExt.normal)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// isLibrary = await app.inLibrary([this.mk.nowPlayingItem])
|
// isLibrary = await app.inLibrary([this.mk.nowPlayingItem])
|
||||||
// console.warn(isLibrary)
|
// console.warn(isLibrary)
|
||||||
// if(isLibrary.length != 0) {
|
// if(isLibrary.length != 0) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue