2020-02-16 18:30:00 +00:00
|
|
|
import Vue from 'vue'
|
2020-08-24 19:50:03 +00:00
|
|
|
import { ObserveVisibility } from 'vue-observe-visibility'
|
2020-02-16 18:30:00 +00:00
|
|
|
import TopNav from './components/top-nav/top-nav.vue'
|
|
|
|
import SideNav from './components/side-nav/side-nav.vue'
|
2020-06-14 21:13:35 +00:00
|
|
|
import FtToast from './components/ft-toast/ft-toast.vue'
|
2020-02-16 18:30:00 +00:00
|
|
|
import $ from 'jquery'
|
2020-03-24 13:22:29 +00:00
|
|
|
|
|
|
|
let useElectron
|
|
|
|
let shell
|
|
|
|
|
2020-08-24 19:50:03 +00:00
|
|
|
Vue.directive('observe-visibility', ObserveVisibility)
|
|
|
|
|
2020-03-24 13:22:29 +00:00
|
|
|
if (window && window.process && window.process.type === 'renderer') {
|
|
|
|
/* eslint-disable-next-line */
|
|
|
|
shell = require('electron').shell
|
|
|
|
useElectron = true
|
|
|
|
} else {
|
|
|
|
useElectron = false
|
|
|
|
}
|
2020-02-16 18:30:00 +00:00
|
|
|
|
|
|
|
export default Vue.extend({
|
|
|
|
name: 'App',
|
|
|
|
components: {
|
|
|
|
TopNav,
|
2020-06-14 21:13:35 +00:00
|
|
|
SideNav,
|
2020-08-05 02:18:39 +00:00
|
|
|
FtToast
|
2020-02-16 18:30:00 +00:00
|
|
|
},
|
|
|
|
computed: {
|
|
|
|
isOpen: function () {
|
|
|
|
return this.$store.getters.getIsSideNavOpen
|
|
|
|
}
|
|
|
|
},
|
|
|
|
mounted: function () {
|
2020-02-27 03:10:56 +00:00
|
|
|
this.$store.dispatch('grabUserSettings')
|
2020-08-20 02:39:44 +00:00
|
|
|
this.$store.dispatch('grabHistory')
|
2020-04-18 03:17:45 +00:00
|
|
|
this.$store.commit('setUsingElectron', useElectron)
|
2020-06-01 02:10:29 +00:00
|
|
|
this.checkThemeSettings()
|
2020-08-11 22:17:09 +00:00
|
|
|
this.checkLocale()
|
2020-02-27 03:10:56 +00:00
|
|
|
|
2020-06-01 02:10:29 +00:00
|
|
|
if (useElectron) {
|
|
|
|
console.log('User is using Electron')
|
|
|
|
this.activateKeyboardShortcuts()
|
|
|
|
this.openAllLinksExternally()
|
2020-02-27 03:10:56 +00:00
|
|
|
}
|
2020-08-06 03:39:00 +00:00
|
|
|
|
2020-08-21 01:20:22 +00:00
|
|
|
// try {
|
|
|
|
// const doc = yaml.safeLoad(fs.readFileSync('./static/locales/en-US.yaml'))
|
|
|
|
// console.log(doc)
|
|
|
|
// } catch (e) {
|
|
|
|
// console.log(e)
|
|
|
|
// }
|
2020-06-01 02:10:29 +00:00
|
|
|
},
|
|
|
|
methods: {
|
2020-08-11 22:17:09 +00:00
|
|
|
checkLocale: function () {
|
|
|
|
const locale = localStorage.getItem('locale')
|
|
|
|
|
|
|
|
if (locale === null) {
|
|
|
|
// TODO: Get User default locale
|
|
|
|
this.$i18n.locale = 'en-US'
|
|
|
|
} else {
|
|
|
|
this.$i18n.locale = locale
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2020-06-01 02:10:29 +00:00
|
|
|
checkThemeSettings: function () {
|
|
|
|
let baseTheme = localStorage.getItem('baseTheme')
|
|
|
|
let mainColor = localStorage.getItem('mainColor')
|
|
|
|
let secColor = localStorage.getItem('secColor')
|
2020-02-27 03:10:56 +00:00
|
|
|
|
2020-06-01 02:10:29 +00:00
|
|
|
if (baseTheme === null) {
|
|
|
|
baseTheme = 'light'
|
|
|
|
}
|
2020-03-01 03:37:02 +00:00
|
|
|
|
2020-06-01 02:10:29 +00:00
|
|
|
if (mainColor === null) {
|
|
|
|
mainColor = 'mainRed'
|
|
|
|
}
|
2020-03-01 03:37:02 +00:00
|
|
|
|
2020-06-01 02:10:29 +00:00
|
|
|
if (secColor === null) {
|
|
|
|
secColor = 'secBlue'
|
|
|
|
}
|
2020-03-01 03:37:02 +00:00
|
|
|
|
2020-06-01 02:10:29 +00:00
|
|
|
const theme = {
|
|
|
|
baseTheme: baseTheme,
|
|
|
|
mainColor: mainColor,
|
|
|
|
secColor: secColor
|
|
|
|
}
|
2020-03-01 03:37:02 +00:00
|
|
|
|
2020-06-01 02:10:29 +00:00
|
|
|
this.updateTheme(theme)
|
|
|
|
},
|
2020-03-24 13:22:29 +00:00
|
|
|
|
2020-02-27 03:10:56 +00:00
|
|
|
updateTheme: function (theme) {
|
|
|
|
console.log(theme)
|
2020-03-01 03:37:02 +00:00
|
|
|
const className = `${theme.baseTheme} ${theme.mainColor} ${theme.secColor}`
|
2020-02-27 03:10:56 +00:00
|
|
|
const body = document.getElementsByTagName('body')[0]
|
2020-03-01 03:37:02 +00:00
|
|
|
body.className = className
|
|
|
|
localStorage.setItem('baseTheme', theme.baseTheme)
|
|
|
|
localStorage.setItem('mainColor', theme.mainColor)
|
|
|
|
localStorage.setItem('secColor', theme.secColor)
|
2020-06-01 02:10:29 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
activateKeyboardShortcuts: function () {
|
|
|
|
$(document).on('keydown', this.handleKeyboardShortcuts)
|
|
|
|
},
|
|
|
|
|
|
|
|
handleKeyboardShortcuts: function (event) {
|
|
|
|
if (event.altKey) {
|
|
|
|
switch (event.code) {
|
|
|
|
case 'ArrowRight':
|
|
|
|
window.history.forward()
|
|
|
|
break
|
|
|
|
case 'ArrowLeft':
|
|
|
|
window.history.back()
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
openAllLinksExternally: function () {
|
|
|
|
// Open links externally by default
|
|
|
|
$(document).on('click', 'a[href^="http"]', (event) => {
|
|
|
|
const el = event.currentTarget
|
|
|
|
console.log(useElectron)
|
|
|
|
console.log(el)
|
|
|
|
if (typeof (shell) !== 'undefined') {
|
|
|
|
event.preventDefault()
|
|
|
|
shell.openExternal(el.href)
|
|
|
|
}
|
|
|
|
})
|
2020-02-27 03:10:56 +00:00
|
|
|
}
|
2020-02-16 18:30:00 +00:00
|
|
|
}
|
|
|
|
})
|