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-09-20 18:22:39 +00:00
|
|
|
import FtFlexBox from './components/ft-flex-box/ft-flex-box.vue'
|
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-09-20 18:22:39 +00:00
|
|
|
import FtNotificationBanner from './components/ft-notification-banner/ft-notification-banner.vue'
|
|
|
|
import FtPrompt from './components/ft-prompt/ft-prompt.vue'
|
|
|
|
import FtButton from './components/ft-button/ft-button.vue'
|
2020-06-14 21:13:35 +00:00
|
|
|
import FtToast from './components/ft-toast/ft-toast.vue'
|
2020-08-31 21:35:22 +00:00
|
|
|
import FtProgressBar from './components/ft-progress-bar/ft-progress-bar.vue'
|
2020-02-16 18:30:00 +00:00
|
|
|
import $ from 'jquery'
|
2020-09-20 18:22:39 +00:00
|
|
|
import { markdown } from 'markdown'
|
|
|
|
import Parser from 'rss-parser'
|
2020-03-24 13:22:29 +00:00
|
|
|
|
|
|
|
let useElectron
|
|
|
|
let shell
|
2020-10-04 20:31:07 +00:00
|
|
|
let electron
|
2020-03-24 13:22:29 +00:00
|
|
|
|
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 */
|
2020-10-04 20:31:07 +00:00
|
|
|
electron = require('electron')
|
|
|
|
shell = electron.shell
|
2020-03-24 13:22:29 +00:00
|
|
|
useElectron = true
|
|
|
|
} else {
|
|
|
|
useElectron = false
|
|
|
|
}
|
2020-02-16 18:30:00 +00:00
|
|
|
|
|
|
|
export default Vue.extend({
|
|
|
|
name: 'App',
|
|
|
|
components: {
|
2020-09-20 18:22:39 +00:00
|
|
|
FtFlexBox,
|
2020-02-16 18:30:00 +00:00
|
|
|
TopNav,
|
2020-06-14 21:13:35 +00:00
|
|
|
SideNav,
|
2020-09-20 18:22:39 +00:00
|
|
|
FtNotificationBanner,
|
|
|
|
FtPrompt,
|
|
|
|
FtButton,
|
2020-08-31 21:35:22 +00:00
|
|
|
FtToast,
|
|
|
|
FtProgressBar
|
2020-02-16 18:30:00 +00:00
|
|
|
},
|
2020-09-16 02:55:19 +00:00
|
|
|
data: function () {
|
|
|
|
return {
|
2020-09-20 18:22:39 +00:00
|
|
|
hideOutlines: true,
|
|
|
|
showUpdatesBanner: false,
|
|
|
|
showBlogBanner: false,
|
|
|
|
showReleaseNotes: false,
|
|
|
|
updateBannerMessage: '',
|
|
|
|
blogBannerMessage: '',
|
|
|
|
latestBlogUrl: '',
|
|
|
|
updateChangelog: '',
|
|
|
|
changeLogTitle: ''
|
2020-09-16 02:55:19 +00:00
|
|
|
}
|
|
|
|
},
|
2020-02-16 18:30:00 +00:00
|
|
|
computed: {
|
|
|
|
isOpen: function () {
|
|
|
|
return this.$store.getters.getIsSideNavOpen
|
2020-08-31 21:35:22 +00:00
|
|
|
},
|
|
|
|
showProgressBar: function () {
|
|
|
|
return this.$store.getters.getShowProgressBar
|
2020-09-16 13:51:26 +00:00
|
|
|
},
|
|
|
|
isRightAligned: function () {
|
|
|
|
return this.$i18n.locale === 'ar'
|
2020-09-20 18:22:39 +00:00
|
|
|
},
|
|
|
|
checkForUpdates: function () {
|
|
|
|
return this.$store.getters.getCheckForUpdates
|
|
|
|
},
|
|
|
|
checkForBlogPosts: function () {
|
|
|
|
return this.$store.getters.getCheckForBlogPosts
|
2020-10-04 20:31:07 +00:00
|
|
|
},
|
|
|
|
searchSettings: function () {
|
|
|
|
return this.$store.getters.getSearchSettings
|
2020-10-06 13:38:35 +00:00
|
|
|
},
|
|
|
|
profileList: function () {
|
|
|
|
return this.$store.getters.getProfileList
|
|
|
|
},
|
|
|
|
activeProfile: function () {
|
|
|
|
return this.$store.getters.getActiveProfile
|
|
|
|
},
|
|
|
|
defaultProfile: function () {
|
|
|
|
return this.$store.getters.getDefaultProfile
|
2020-02-16 18:30:00 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
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-08-23 19:07:29 +00:00
|
|
|
this.$store.dispatch('grabAllProfiles', this.$t('Profile.All Channels'))
|
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-10-15 13:33:25 +00:00
|
|
|
this.enableOpenUrl()
|
2020-09-20 18:54:23 +00:00
|
|
|
this.setBoundsOnClose()
|
2020-02-27 03:10:56 +00:00
|
|
|
}
|
2020-09-20 18:22:39 +00:00
|
|
|
|
|
|
|
setTimeout(() => {
|
|
|
|
this.checkForNewUpdates()
|
|
|
|
this.checkForNewBlogPosts()
|
|
|
|
}, 500)
|
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
|
|
|
},
|
|
|
|
|
2020-09-20 18:22:39 +00:00
|
|
|
checkForNewUpdates: function () {
|
|
|
|
if (this.checkForUpdates) {
|
|
|
|
const { version } = require('../../package.json')
|
2020-10-01 02:12:29 +00:00
|
|
|
const requestUrl = 'https://api.github.com/repos/freetubeapp/freetube/releases'
|
2020-09-20 18:22:39 +00:00
|
|
|
|
|
|
|
$.getJSON(requestUrl, (response) => {
|
|
|
|
const tagName = response[0].tag_name
|
|
|
|
const versionNumber = tagName.replace('v', '').replace('-beta', '')
|
|
|
|
this.updateChangelog = markdown.toHTML(response[0].body)
|
|
|
|
this.changeLogTitle = response[0].name
|
|
|
|
|
|
|
|
const message = this.$t('Version $ is now available! Click for more details')
|
|
|
|
this.updateBannerMessage = message.replace('$', versionNumber)
|
|
|
|
if (version < versionNumber) {
|
|
|
|
this.showUpdatesBanner = true
|
|
|
|
}
|
|
|
|
}).fail((xhr, textStatus, error) => {
|
|
|
|
console.log(xhr)
|
|
|
|
console.log(textStatus)
|
|
|
|
console.log(requestUrl)
|
|
|
|
console.log(error)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
checkForNewBlogPosts: function () {
|
|
|
|
if (this.checkForBlogPosts) {
|
|
|
|
const parser = new Parser()
|
|
|
|
const feedUrl = 'https://write.as/freetube/feed/'
|
|
|
|
let lastAppWasRunning = localStorage.getItem('lastAppWasRunning')
|
|
|
|
|
|
|
|
if (lastAppWasRunning !== null) {
|
|
|
|
lastAppWasRunning = new Date(lastAppWasRunning)
|
|
|
|
}
|
|
|
|
|
|
|
|
parser.parseURL(feedUrl).then((response) => {
|
|
|
|
const latestBlog = response.items[0]
|
|
|
|
const latestPubDate = new Date(latestBlog.pubDate)
|
|
|
|
|
|
|
|
if (lastAppWasRunning === null || latestPubDate > lastAppWasRunning) {
|
|
|
|
const message = this.$t('A new blog is now available, $. Click to view more')
|
|
|
|
this.blogBannerMessage = message.replace('$', latestBlog.title)
|
|
|
|
this.latestBlogUrl = latestBlog.link
|
|
|
|
this.showBlogBanner = true
|
|
|
|
}
|
|
|
|
|
|
|
|
localStorage.setItem('lastAppWasRunning', new Date())
|
|
|
|
})
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
handleUpdateBannerClick: function (response) {
|
|
|
|
if (response !== false) {
|
|
|
|
this.showReleaseNotes = true
|
|
|
|
} else {
|
|
|
|
this.showUpdatesBanner = false
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
handleNewBlogBannerClick: function (response) {
|
|
|
|
if (response) {
|
|
|
|
shell.openExternal(this.latestBlogUrl)
|
|
|
|
}
|
|
|
|
|
|
|
|
this.showBlogBanner = false
|
|
|
|
},
|
|
|
|
|
|
|
|
openDownloadsPage: function () {
|
|
|
|
const url = 'https://freetubeapp.io#download'
|
|
|
|
shell.openExternal(url)
|
|
|
|
this.showReleaseNotes = false
|
|
|
|
this.showUpdatesBanner = false
|
|
|
|
},
|
|
|
|
|
2020-06-01 02:10:29 +00:00
|
|
|
activateKeyboardShortcuts: function () {
|
|
|
|
$(document).on('keydown', this.handleKeyboardShortcuts)
|
2020-09-16 02:55:19 +00:00
|
|
|
$(document).on('mousedown', () => {
|
|
|
|
this.hideOutlines = true
|
|
|
|
})
|
2020-06-01 02:10:29 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
handleKeyboardShortcuts: function (event) {
|
|
|
|
if (event.altKey) {
|
|
|
|
switch (event.code) {
|
|
|
|
case 'ArrowRight':
|
|
|
|
window.history.forward()
|
|
|
|
break
|
|
|
|
case 'ArrowLeft':
|
|
|
|
window.history.back()
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
2020-09-16 02:55:19 +00:00
|
|
|
switch (event.code) {
|
|
|
|
case 'Tab':
|
|
|
|
this.hideOutlines = false
|
|
|
|
break
|
|
|
|
}
|
2020-06-01 02:10:29 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
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-09-20 18:54:23 +00:00
|
|
|
},
|
|
|
|
|
2020-10-15 13:33:25 +00:00
|
|
|
enableOpenUrl: function () {
|
2020-10-04 20:31:07 +00:00
|
|
|
const v = this
|
2020-10-15 13:33:25 +00:00
|
|
|
electron.ipcRenderer.on('openUrl', function (event, url) {
|
2020-10-04 20:31:07 +00:00
|
|
|
if (url) {
|
|
|
|
v.$store.dispatch('getVideoIdFromUrl', url).then((result) => {
|
|
|
|
if (result) {
|
|
|
|
v.$router.push({
|
|
|
|
path: `/watch/${result}`
|
|
|
|
})
|
|
|
|
} else {
|
|
|
|
v.$router.push({
|
|
|
|
path: `/search/${encodeURIComponent(url)}`,
|
|
|
|
query: {
|
|
|
|
sortBy: v.searchSettings.sortBy,
|
|
|
|
time: v.searchSettings.time,
|
|
|
|
type: v.searchSettings.type,
|
|
|
|
duration: v.searchSettings.duration
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
electron.ipcRenderer.send('appReady')
|
|
|
|
},
|
|
|
|
|
2020-09-20 18:54:23 +00:00
|
|
|
setBoundsOnClose: function () {
|
|
|
|
window.onbeforeunload = (e) => {
|
|
|
|
electron.ipcRenderer.send('setBounds')
|
|
|
|
}
|
2020-02-27 03:10:56 +00:00
|
|
|
}
|
2020-02-16 18:30:00 +00:00
|
|
|
}
|
|
|
|
})
|