From 3fe0839f07244501417b4299ae96fae445c074f8 Mon Sep 17 00:00:00 2001 From: UKDTOM Date: Sun, 7 Jun 2020 21:56:56 +0200 Subject: [PATCH] refactoring wtutils, and added more stuff to it --- src/components/Language.vue | 4 ++-- src/main.js | 4 ++-- src/menubar.js | 17 ++++++++++------- src/wtutils.js | 34 +++++++++++++++++++++++----------- 4 files changed, 37 insertions(+), 22 deletions(-) diff --git a/src/components/Language.vue b/src/components/Language.vue index 1c416a4..2f8621a 100644 --- a/src/components/Language.vue +++ b/src/components/Language.vue @@ -26,8 +26,8 @@ export default { return { langs: [] } }, mounted() { - var LangDir = wtutils.GetHome + '/locales'; - console.log('Ged LangDir: ' + LangDir) + var LangDir = wtutils.Home + '/locales'; + console.log('Ged LangDir: ' + LangDir) var fs = require('fs'); fs.readdir(LangDir, function(err, items) { console.log('Ged files: ' + items) diff --git a/src/main.js b/src/main.js index b810d61..148183a 100644 --- a/src/main.js +++ b/src/main.js @@ -26,10 +26,10 @@ Vue.use(Buefy); const log = require('electron-log'); log.transports.file.level = 'info'; log.transports.console.level = 'verbose'; -log.transports.file.fileName = wtutils.GetAppName; +log.transports.file.fileName = wtutils.AppName; console.log = log.log; log.info('*********************************') -log.info('Starting ' + wtutils.GetAppName + ' Version:' + wtutils.GetAppVersion); +log.info('Starting ' + wtutils.AppName + ' Version:' + wtutils.AppVersion); // Logging ended wtutils.MoveToHome('./public/locales'); diff --git a/src/menubar.js b/src/menubar.js index 5fb3aed..e211a5d 100644 --- a/src/menubar.js +++ b/src/menubar.js @@ -1,17 +1,20 @@ import i18n from './i18n' import { shell } from 'electron' +import { wtutils} from './wtutils'; +//import { wtconfig } from './wtutils'; + const isDev = require('electron-is-dev'); var appName = require('electron').remote.app.getName(); var appHome = require('electron').remote.app.getPath('home') -var logLinux = appHome + '/.config/' + appName + '/logs' +var logLinux = wtutils.Home + '/.config/' + wtutils.AppName + '/logs' var logWin = appHome + '\\AppData\\Roaming\\' + appName + '\\logs' var logMac = appHome + '/Library/Logs/' + appName -const isMac = process.platform === 'darwin' -const isLinux = process.platform === 'linux' -const isWindows = process.platform === 'win32' +//const isMac = process.platform === 'darwin' +//const isLinux = process.platform === 'linux' +//const isWindows = process.platform === 'win32' // Menu template const menuTemplate = [ @@ -20,18 +23,18 @@ const menuTemplate = [ label: i18n.t("Common.Menu.File.menuFile"), submenu: [ - isMac ? + wtutils.isMac ? { label: i18n.t("Common.Menu.File.menuOpenLogDir"), click: () => { shell.openItem(logMac) } } : { - ...isLinux ? + ...wtutils.isLinux ? { label: i18n.t("Common.Menu.File.menuOpenLogDir"), click: () => { shell.openItem(logLinux) } } : { - ...isWindows ? + ...wtutils.isWindows ? { label: i18n.t("Common.Menu.File.menuOpenLogDir"), click: () => { shell.openItem(logWin) } diff --git a/src/wtutils.js b/src/wtutils.js index 766e830..42e6402 100644 --- a/src/wtutils.js +++ b/src/wtutils.js @@ -10,24 +10,36 @@ const electron = require('electron'); const Store = require('electron-store'); const wtconfig = new Store({name: require('electron').remote.app.getName()}); -const isMac = process.platform === 'darwin' -const isLinux = process.platform === 'linux' -const isWindows = process.platform === 'win32' - const wtutils = new class WTUtils { constructor() { } + + get isDev() { + return require('electron-is-dev'); + } + + get isMac() { + return process.platform === 'darwin' + } + + get isLinux() { + return process.platform === 'linux' + } + + get isWindows() { + return process.platform === 'win32' + } - get GetHome() { + get Home() { return (electron.app || electron.remote.app).getPath('userData'); } - get GetAppName() { + get AppName() { return (electron.app || electron.remote.app).getName(); } - get GetAppVersion() { + get AppVersion() { return (electron.app || electron.remote.app).getVersion(); } @@ -35,12 +47,12 @@ const wtutils = new class WTUtils { MoveToHome(SourceDir) { var last = wtconfig.get('general.transfilescopied', "0") - if (!(last == wtutils.GetAppVersion)) + if (!(last == wtutils.AppVersion)) { console.log('We need to copy translation strings over') var fs = require('fs'); // Check if userdata/locales exists, and create if not - var TargetDir = wtutils.GetHome + '/locales'; + var TargetDir = wtutils.Home + '/locales'; if (!fs.existsSync(TargetDir)){ fs.mkdirSync(TargetDir); } @@ -53,7 +65,7 @@ const wtutils = new class WTUtils { }); } }); - wtconfig.set('general.transfilescopied', wtutils.GetAppVersion) + wtconfig.set('general.transfilescopied', wtutils.AppVersion) } } @@ -71,4 +83,4 @@ const wtutils = new class WTUtils { -export {wtutils, wtconfig, isLinux, isMac, isWindows}; \ No newline at end of file +export {wtutils, wtconfig}; \ No newline at end of file