better hot reloading for themes
This commit is contained in:
parent
558b35f4fd
commit
919fed493b
2 changed files with 74 additions and 30 deletions
|
@ -1,18 +1,18 @@
|
||||||
import {join} from "path";
|
import { join } from "path";
|
||||||
import {app, BrowserWindow as bw, ipcMain, ShareMenu, shell} from "electron";
|
import { app, BrowserWindow as bw, ipcMain, ShareMenu, shell } from "electron";
|
||||||
import * as windowStateKeeper from "electron-window-state";
|
import * as windowStateKeeper from "electron-window-state";
|
||||||
import * as express from "express";
|
import * as express from "express";
|
||||||
import * as getPort from "get-port";
|
import * as getPort from "get-port";
|
||||||
import {search} from "youtube-search-without-api-key";
|
import { search } from "youtube-search-without-api-key";
|
||||||
import {existsSync, mkdirSync, readdirSync, readFileSync, writeFileSync, statSync} from "fs";
|
import { existsSync, mkdirSync, readdirSync, readFileSync, writeFileSync, statSync } from "fs";
|
||||||
import {Stream} from "stream";
|
import { Stream } from "stream";
|
||||||
import {networkInterfaces} from "os";
|
import { networkInterfaces } from "os";
|
||||||
import * as mm from 'music-metadata';
|
import * as mm from 'music-metadata';
|
||||||
import fetch from 'electron-fetch'
|
import fetch from 'electron-fetch'
|
||||||
import {wsapi} from "./wsapi";
|
import { wsapi } from "./wsapi";
|
||||||
import {AppImageUpdater, NsisUpdater} from "electron-updater";
|
import { AppImageUpdater, NsisUpdater } from "electron-updater";
|
||||||
import {utils} from './utils';
|
import { utils } from './utils';
|
||||||
|
const fileWatcher = require('chokidar');
|
||||||
const AdmZip = require("adm-zip");
|
const AdmZip = require("adm-zip");
|
||||||
|
|
||||||
|
|
||||||
|
@ -22,7 +22,7 @@ export class BrowserWindow {
|
||||||
|
|
||||||
private audioStream: any = new Stream.PassThrough();
|
private audioStream: any = new Stream.PassThrough();
|
||||||
private headerSent: any = false;
|
private headerSent: any = false;
|
||||||
private chromecastIP : any = [];
|
private chromecastIP: any = [];
|
||||||
private clientPort: number = 0;
|
private clientPort: number = 0;
|
||||||
private remotePort: number = 6942;
|
private remotePort: number = 6942;
|
||||||
private EnvironmentVariables: object = {
|
private EnvironmentVariables: object = {
|
||||||
|
@ -179,7 +179,7 @@ export class BrowserWindow {
|
||||||
page: "themes-github",
|
page: "themes-github",
|
||||||
component: `<themes-github></themes-github>`,
|
component: `<themes-github></themes-github>`,
|
||||||
condition: `page == 'themes-github'`
|
condition: `page == 'themes-github'`
|
||||||
},{
|
}, {
|
||||||
page: "plugins-github",
|
page: "plugins-github",
|
||||||
component: `<plugins-github></plugins-github>`,
|
component: `<plugins-github></plugins-github>`,
|
||||||
condition: `page == 'plugins-github'`
|
condition: `page == 'plugins-github'`
|
||||||
|
@ -219,7 +219,7 @@ export class BrowserWindow {
|
||||||
show: false,
|
show: false,
|
||||||
// backgroundColor: "#1E1E1E",
|
// backgroundColor: "#1E1E1E",
|
||||||
titleBarStyle: 'hidden',
|
titleBarStyle: 'hidden',
|
||||||
trafficLightPosition: {x: 15, y: 20},
|
trafficLightPosition: { x: 15, y: 20 },
|
||||||
webPreferences: {
|
webPreferences: {
|
||||||
experimentalFeatures: true,
|
experimentalFeatures: true,
|
||||||
nodeIntegration: true,
|
nodeIntegration: true,
|
||||||
|
@ -233,13 +233,52 @@ export class BrowserWindow {
|
||||||
preload: join(utils.getPath('srcPath'), "./preload/cider-preload.js"),
|
preload: join(utils.getPath('srcPath'), "./preload/cider-preload.js"),
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
StartWatcher(path: string) {
|
||||||
|
var chokidar = require("chokidar");
|
||||||
|
|
||||||
|
var watcher = chokidar.watch(path, {
|
||||||
|
ignored: /[\/\\]\./,
|
||||||
|
persistent: true
|
||||||
|
});
|
||||||
|
|
||||||
|
function onWatcherReady() {
|
||||||
|
console.info('From here can you check for real changes, the initial scan has been completed.');
|
||||||
|
}
|
||||||
|
|
||||||
|
// Declare the listeners of the watcher
|
||||||
|
watcher
|
||||||
|
.on('add', function (path: string) {
|
||||||
|
// console.log('File', path, 'has been added');
|
||||||
|
})
|
||||||
|
.on('addDir', function (path: string) {
|
||||||
|
// console.log('Directory', path, 'has been added');
|
||||||
|
})
|
||||||
|
.on('change', function (path: string) {
|
||||||
|
console.log('File', path, 'has been changed');
|
||||||
|
BrowserWindow.win.webContents.send("theme-update", "")
|
||||||
|
})
|
||||||
|
.on('unlink', function (path: string) {
|
||||||
|
// console.log('File', path, 'has been removed');
|
||||||
|
})
|
||||||
|
.on('unlinkDir', function (path: string) {
|
||||||
|
// console.log('Directory', path, 'has been removed');
|
||||||
|
})
|
||||||
|
.on('error', function (error: string) {
|
||||||
|
// console.log('Error happened', error);
|
||||||
|
})
|
||||||
|
.on('ready', onWatcherReady)
|
||||||
|
.on('raw', function (event: any, path: any, details: any) {
|
||||||
|
// This event should be triggered everytime something happens.
|
||||||
|
// console.log('Raw event info:', event, path, details);
|
||||||
|
});
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* Creates the browser window
|
* Creates the browser window
|
||||||
*/
|
*/
|
||||||
async createWindow(): Promise<Electron.BrowserWindow> {
|
async createWindow(): Promise<Electron.BrowserWindow> {
|
||||||
this.clientPort = await getPort({port: 9000});
|
this.clientPort = await getPort({ port: 9000 });
|
||||||
BrowserWindow.verifyFiles();
|
BrowserWindow.verifyFiles();
|
||||||
|
this.StartWatcher(utils.getPath('themes'));
|
||||||
|
|
||||||
// Load the previous state with fallback to defaults
|
// Load the previous state with fallback to defaults
|
||||||
const windowState = windowStateKeeper({
|
const windowState = windowStateKeeper({
|
||||||
|
@ -458,7 +497,7 @@ export class BrowserWindow {
|
||||||
remote.use(express.static(join(utils.getPath('srcPath'), "./web-remote/")))
|
remote.use(express.static(join(utils.getPath('srcPath'), "./web-remote/")))
|
||||||
remote.set("views", join(utils.getPath('srcPath'), "./web-remote/views"));
|
remote.set("views", join(utils.getPath('srcPath'), "./web-remote/views"));
|
||||||
remote.set("view engine", "ejs");
|
remote.set("view engine", "ejs");
|
||||||
getPort({port: 6942}).then((port) => {
|
getPort({ port: 6942 }).then((port) => {
|
||||||
this.remotePort = port;
|
this.remotePort = port;
|
||||||
// Start Remote Discovery
|
// Start Remote Discovery
|
||||||
this.broadcastRemote()
|
this.broadcastRemote()
|
||||||
|
@ -511,7 +550,7 @@ export class BrowserWindow {
|
||||||
if (itspod != null)
|
if (itspod != null)
|
||||||
details.requestHeaders["Cookie"] = `itspod=${itspod}`;
|
details.requestHeaders["Cookie"] = `itspod=${itspod}`;
|
||||||
}
|
}
|
||||||
callback({requestHeaders: details.requestHeaders});
|
callback({ requestHeaders: details.requestHeaders });
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -771,7 +810,7 @@ export class BrowserWindow {
|
||||||
})
|
})
|
||||||
//Fullscreen
|
//Fullscreen
|
||||||
ipcMain.on('detachDT', (_event, _) => {
|
ipcMain.on('detachDT', (_event, _) => {
|
||||||
BrowserWindow.win.webContents.openDevTools({mode: 'detach'});
|
BrowserWindow.win.webContents.openDevTools({ mode: 'detach' });
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
|
@ -1044,10 +1083,10 @@ export class BrowserWindow {
|
||||||
// Set window Handler
|
// Set window Handler
|
||||||
BrowserWindow.win.webContents.setWindowOpenHandler((x: any) => {
|
BrowserWindow.win.webContents.setWindowOpenHandler((x: any) => {
|
||||||
if (x.url.includes("apple") || x.url.includes("localhost")) {
|
if (x.url.includes("apple") || x.url.includes("localhost")) {
|
||||||
return {action: "allow"};
|
return { action: "allow" };
|
||||||
}
|
}
|
||||||
shell.openExternal(x.url).catch(console.error);
|
shell.openExternal(x.url).catch(console.error);
|
||||||
return {action: "deny"};
|
return { action: "deny" };
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1096,7 +1135,7 @@ export class BrowserWindow {
|
||||||
"CtlN": "Cider",
|
"CtlN": "Cider",
|
||||||
"iV": "196623"
|
"iV": "196623"
|
||||||
};
|
};
|
||||||
let server2 = mdns.createAdvertisement(x, `${await getPort({port: 3839})}`, {
|
let server2 = mdns.createAdvertisement(x, `${await getPort({ port: 3839 })}`, {
|
||||||
name: encoded,
|
name: encoded,
|
||||||
txt: txt_record
|
txt: txt_record
|
||||||
});
|
});
|
||||||
|
|
|
@ -779,6 +779,10 @@ const app = new Vue({
|
||||||
|
|
||||||
MusicKit.getInstance().videoContainerElement = document.getElementById("apple-music-video-player")
|
MusicKit.getInstance().videoContainerElement = document.getElementById("apple-music-video-player")
|
||||||
|
|
||||||
|
ipcRenderer.on('theme-update', (event, arg) => {
|
||||||
|
less.refresh(true, true, true)
|
||||||
|
})
|
||||||
|
|
||||||
ipcRenderer.on('SoundCheckTag', (event, tag) => {
|
ipcRenderer.on('SoundCheckTag', (event, tag) => {
|
||||||
let replaygain = self.parseSCTagToRG(tag)
|
let replaygain = self.parseSCTagToRG(tag)
|
||||||
try {
|
try {
|
||||||
|
@ -906,6 +910,7 @@ const app = new Vue({
|
||||||
if (theme == "") {
|
if (theme == "") {
|
||||||
theme = this.cfg.visual.theme
|
theme = this.cfg.visual.theme
|
||||||
} else {
|
} else {
|
||||||
|
this.cfg.visual.theme = ""
|
||||||
this.cfg.visual.theme = theme
|
this.cfg.visual.theme = theme
|
||||||
}
|
}
|
||||||
this.chrome.appliedTheme.info = await (await fetch("themes/" + app.cfg.visual.theme.replace("index.less", "theme.json"))).json()
|
this.chrome.appliedTheme.info = await (await fetch("themes/" + app.cfg.visual.theme.replace("index.less", "theme.json"))).json()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue