FreeTube/src/renderer/App.js

147 lines
3.7 KiB
JavaScript
Raw Normal View History

2020-02-16 19:30:00 +01:00
import Vue from 'vue'
import { ObserveVisibility } from 'vue-observe-visibility'
2020-02-16 19:30:00 +01:00
import TopNav from './components/top-nav/top-nav.vue'
import SideNav from './components/side-nav/side-nav.vue'
2020-06-14 23:13:35 +02:00
import FtToast from './components/ft-toast/ft-toast.vue'
import FtProgressBar from './components/ft-progress-bar/ft-progress-bar.vue'
2020-02-16 19:30:00 +01:00
import $ from 'jquery'
let useElectron
let shell
Vue.directive('observe-visibility', ObserveVisibility)
if (window && window.process && window.process.type === 'renderer') {
/* eslint-disable-next-line */
shell = require('electron').shell
useElectron = true
} else {
useElectron = false
}
2020-02-16 19:30:00 +01:00
export default Vue.extend({
name: 'App',
components: {
TopNav,
2020-06-14 23:13:35 +02:00
SideNav,
FtToast,
FtProgressBar
2020-02-16 19:30:00 +01:00
},
2020-09-16 04:55:19 +02:00
data: function () {
return {
hideOutlines: true
}
},
2020-02-16 19:30:00 +01:00
computed: {
isOpen: function () {
return this.$store.getters.getIsSideNavOpen
},
showProgressBar: function () {
return this.$store.getters.getShowProgressBar
},
isRightAligned: function () {
return this.$i18n.locale === 'ar'
2020-02-16 19:30:00 +01:00
}
},
mounted: function () {
this.$store.dispatch('grabUserSettings')
this.$store.dispatch('grabHistory')
2020-08-23 21:07:29 +02:00
this.$store.dispatch('grabAllProfiles', this.$t('Profile.All Channels'))
this.$store.commit('setUsingElectron', useElectron)
this.checkThemeSettings()
this.checkLocale()
if (useElectron) {
console.log('User is using Electron')
this.activateKeyboardShortcuts()
this.openAllLinksExternally()
}
},
methods: {
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
}
},
checkThemeSettings: function () {
let baseTheme = localStorage.getItem('baseTheme')
let mainColor = localStorage.getItem('mainColor')
let secColor = localStorage.getItem('secColor')
if (baseTheme === null) {
baseTheme = 'light'
}
if (mainColor === null) {
mainColor = 'mainRed'
}
if (secColor === null) {
secColor = 'secBlue'
}
const theme = {
baseTheme: baseTheme,
mainColor: mainColor,
secColor: secColor
}
this.updateTheme(theme)
},
updateTheme: function (theme) {
console.log(theme)
const className = `${theme.baseTheme} ${theme.mainColor} ${theme.secColor}`
const body = document.getElementsByTagName('body')[0]
body.className = className
localStorage.setItem('baseTheme', theme.baseTheme)
localStorage.setItem('mainColor', theme.mainColor)
localStorage.setItem('secColor', theme.secColor)
},
activateKeyboardShortcuts: function () {
$(document).on('keydown', this.handleKeyboardShortcuts)
2020-09-16 04:55:19 +02:00
$(document).on('mousedown', () => {
this.hideOutlines = true
})
},
handleKeyboardShortcuts: function (event) {
if (event.altKey) {
switch (event.code) {
case 'ArrowRight':
window.history.forward()
break
case 'ArrowLeft':
window.history.back()
break
}
}
2020-09-16 04:55:19 +02:00
switch (event.code) {
case 'Tab':
this.hideOutlines = false
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-16 19:30:00 +01:00
}
})