diff --git a/main.js b/main.js
index 89887e635..069ec0125 100644
--- a/main.js
+++ b/main.js
@@ -14,7 +14,6 @@ const {
shell,
} = require('electron')
const path = require('path')
-const fs = require('fs')
const scrobblerProvider = require('./providers/scrobblerProvider')
const __ = require('./providers/translateProvider')
const { statusBarMenu } = require('./providers/templateProvider')
@@ -30,14 +29,13 @@ const discordRPC = require('./providers/discordRpcProvider')
app.commandLine.appendSwitch('disable-features', 'MediaSessionService') //This keeps chromium from trying to launch up it's own mpris service, hence stopping the double service.
const mprisProvider = require('./providers/mprisProvider')
const { checkWindowPosition, doBehavior } = require('./utils/window')
+const fileSystem = require('./utils/fileSystem')
const electronLocalshortcut = require('electron-localshortcut')
-const themePath = path.join(app.getAppPath(), '/assets/custom-theme.css')
-
-if (!themePath) {
- fs.writeFileSync(themePath, `/** \n * Custom Theme \n */`, { flag: 'w+' })
-}
+createDocumentsAppDir()
+createCustomThemeSubDir()
+createCustomThemeFile()
if (settingsProvider.get('settings-companion-server')) {
companionServer.start()
@@ -939,13 +937,18 @@ function createWindow() {
}
function loadCustomTheme() {
+ const customThemeFile = path.join(
+ fileSystem.getAppDocumentsPath(app),
+ '/custom-theme/styles.css'
+ )
+
if (settingsProvider.get('settings-custom-theme')) {
- if (fs.existsSync(themePath)) {
+ if (fileSystem.checkIfExists(customThemeFile)) {
if (customThemeCSSKey) {
removeCustomTheme()
}
view.webContents
- .insertCSS(fs.readFileSync(themePath).toString())
+ .insertCSS(fileSystem.readFile(customThemeFile).toString())
.then(key => {
customThemeCSSKey = key
})
@@ -1197,6 +1200,34 @@ function bytesToSize(bytes) {
return Math.round(bytes / Math.pow(1024, i), 2) + ' ' + sizes[i]
}
+function createDocumentsAppDir() {
+ if (!fileSystem.checkIfExists(fileSystem.getAppDocumentsPath(app))) {
+ fileSystem.createDir(fileSystem.getAppDocumentsPath(app))
+ }
+}
+
+function createCustomThemeSubDir() {
+ const dirCustomTheme = path.join(
+ fileSystem.getAppDocumentsPath(app),
+ '/custom-theme'
+ )
+
+ if (!fileSystem.checkIfExists(dirCustomTheme)) {
+ fileSystem.createDir(dirCustomTheme, { recursive: true })
+ }
+}
+
+function createCustomThemeFile() {
+ const customThemeFile = path.join(
+ fileSystem.getAppDocumentsPath(app),
+ '/custom-theme/styles.css'
+ )
+
+ if (!fileSystem.checkIfExists(customThemeFile)) {
+ fileSystem.writeFile(customThemeFile, `/** \n * Custom Theme \n */`)
+ }
+}
+
// In this file you can include the rest of your app's specific main process
// code. You can also put them in separate files and require them here.
const mediaControl = require('./providers/mediaProvider')
diff --git a/package.json b/package.json
index f486110ea..48a3ec061 100644
--- a/package.json
+++ b/package.json
@@ -60,7 +60,7 @@
"ws": "^7.2.1"
},
"optionalDependencies": {
- "@nodert-win10/windows.media.playback": "^0.2.95",
+ "@nodert-win10/windows.media.playback": "^0.2.96",
"mpris-service": "^2.1.0"
}
}
diff --git a/pages/editor/editor.js b/pages/editor/editor.js
index efb77b72c..fea0734fb 100644
--- a/pages/editor/editor.js
+++ b/pages/editor/editor.js
@@ -1,23 +1,31 @@
const { ipcRenderer } = require('electron')
+const app = require('electron').remote.app
const path = require('electron').remote.require('path')
-const fs = require('electron').remote.require('fs')
+
const __ = require('../../providers/translateProvider')
-const themePath = path.join(__dirname, '../../assets/custom-theme.css')
-var editor
+const fileSystem = require('../../utils/fileSystem')
+
+const themePath = path.join(
+ fileSystem.getAppDocumentsPath(app),
+ '/custom-theme'
+)
+const file = path.join(themePath, 'styles.css')
const textEditor = document.getElementById('editor')
const btnSave = document.getElementById('btn-save')
+var editor
+
__.loadi18n()
-if (fs.existsSync(themePath)) {
- textEditor.innerHTML = fs.readFileSync(themePath).toString()
+if (fileSystem.checkIfExists(themePath)) {
+ textEditor.innerHTML = fileSystem.readFile(file).toString()
}
if (btnSave) {
btnSave.addEventListener('click', function() {
var code = editor.getValue()
- fs.writeFileSync(themePath, code, { flag: 'w+' })
+ fileSystem.writeFile(file, code)
ipcRenderer.send('update-custom-theme')
})
}
diff --git a/pages/settings/settings.html b/pages/settings/settings.html
index 18fad63ad..4c2d9ea4c 100644
--- a/pages/settings/settings.html
+++ b/pages/settings/settings.html
@@ -439,7 +439,7 @@
id="btn-editor-custom-theme"
>
settingsedit