Skip to content

Commit

Permalink
added logFile variable to methods for testing
Browse files Browse the repository at this point in the history
  • Loading branch information
Plastikmensch committed Jan 19, 2020
1 parent 32c3bcd commit 2091f79
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions src/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ else {
app = require('electron').remote.app
}

const logFile = path.join(app.getPath('userData'), 'tweelectron.log')
//const logFile = path.join(app.getPath('userData'), 'tweelectron.log')

const Settings = [
[undefined, '"use-tor" :'], //useTor
Expand All @@ -32,19 +32,21 @@ function SettingsFile () {
return path.join(app.getPath('exe').slice(0, app.getPath('exe').lastIndexOf(path.sep)), 'settings.json')
}
}

/*
app.on('ready', () => {
if (app.hasSingleInstanceLock() && fs.existsSync(logFile)) {
fs.renameSync(logFile, logFile + '.backup')
}
})
*/
var methods = {
readSettings: function () {
if (fs.existsSync(settingsFile)) {
const settingsData = fs.readFileSync(settingsFile, 'utf8')
//Redo this mess
for (let i = 0; i < Settings.length; i++) {
if (settingsData.search('=') === -1) {
//slice from start of key + length of key to end of the current line and trim the sliced part to remove whitespaces
Settings[i][0] = settingsData.slice(settingsData.search(Settings[i][1]) + Settings[i][1].length, settingsData.indexOf('\n', settingsData.search(Settings[i][1]))).trim()
}
else {
Expand All @@ -70,7 +72,7 @@ var methods = {
else if (Settings[i][0].search('"') !== -1) {
Settings[i][0] = Settings[i][0].slice(1, Settings[i][0].lastIndexOf('"'))
}
//this.log(`${Settings[i][1]} ${Settings[i][0]}`)
this.log(`${Settings[i][1]} ${Settings[i][0]}`)
}
}
return Settings
Expand All @@ -94,10 +96,11 @@ var methods = {
this.log('Settings saved')
},
log: function (message) {
fs.appendFileSync(logFile, message + '\n')
fs.appendFileSync(this.logFile, message + '\n')
console.log(message)
},
themeDir: path.join(app.getPath('userData'), 'themes'),
appDir: app.getPath('exe').slice(0, app.getPath('exe').lastIndexOf(path.sep))
appDir: app.getPath('exe').slice(0, app.getPath('exe').lastIndexOf(path.sep)),
logFile: path.join(app.getPath('userData'), 'tweelectron.log')
}
module.exports = methods

0 comments on commit 2091f79

Please sign in to comment.