Skip to content

Commit

Permalink
Merge pull request #3 from matiastucci/v2
Browse files Browse the repository at this point in the history
V2
  • Loading branch information
matiastucci authored Dec 26, 2016
2 parents 6e84c9e + 2b6bec5 commit 9f8ea1c
Show file tree
Hide file tree
Showing 6 changed files with 144 additions and 44 deletions.
30 changes: 23 additions & 7 deletions app/electron.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@ if (process.env.NODE_ENV === 'development') {
}

function createWindow () {
/**
* Initial window options
*/
mainWindow = new BrowserWindow({
width: 350,
height: 350,
Expand Down Expand Up @@ -53,14 +50,33 @@ function createWindow () {
mainWindow.webContents.on('did-finish-load', () => {
const platform = os.platform() + '_' + os.arch()
const version = app.getVersion()

mainWindow.webContents.send('ping', `App version: ${version}`)

autoUpdater.setFeedURL(`https://easysubs-autoupdater.herokuapp.com/update/${platform}/${version}`)
console.log(`https://easysubs-autoupdater.herokuapp.com/update/${platform}/${version}`)
autoUpdater.checkForUpdates()

autoUpdater.on('error', (ev, err) => {
console.log(err)
mainWindow.webContents.send('ping', 'update-error')
mainWindow.webContents.send('ping', err)
});

autoUpdater.on('checking-for-update', (ev, err) => {
mainWindow.webContents.send('ping', 'checking-for-update')
});
})

console.log('mainWindow opened')
autoUpdater.on('update-available', (ev, err) => {
mainWindow.webContents.send('ping', 'update-available')
});

autoUpdater.on('update-not-available', (ev, err) => {
mainWindow.webContents.send('ping', 'update-not-available')
});

autoUpdater.on('update-downloaded', (ev, err) => {
mainWindow.webContents.send('ping', 'update-downloaded')
});
})
}

app.on('ready', createWindow)
Expand Down
29 changes: 0 additions & 29 deletions app/index.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -6,35 +6,6 @@
</head>
<body>
<div id="app"></div>
<script>
// TODO: move this to a separate file
(function () {
const shell = require('electron').shell
const supportExternalLinks = function (e) {
let href
let isExternal = false
const checkDomElement = function (element) {
if (element.nodeName === 'A') {
href = element.getAttribute('href')
}
if (element.classList.contains('js-external-link')) {
isExternal = true
}
if (href && isExternal) {
shell.openExternal(href)
e.preventDefault()
} else if (element.parentElement) {
checkDomElement(element.parentElement)
}
}
checkDomElement(e.target)
}
document.addEventListener('click', supportExternalLinks, false)
}())
</script>
<!-- webpack builds are automatically injected -->
</body>
</html>
48 changes: 48 additions & 0 deletions app/src/App.vue
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
<script>
import Videos from 'services/videos'
import Helpers from 'services/helpers'
export default {
name: 'App',
data() {
return {
updateDownloading: false,
updateExists: false,
updateDownloaded: false,
}
},
mounted() {
this.$nextTick(() => {
this.$el.addEventListener('drop', event => {
Expand All @@ -14,13 +23,33 @@
event.preventDefault()
})
})
Helpers.bus.$on('update-available', () => {
this.updateExists = true
})
Helpers.bus.$on('update-downloaded', () => {
this.updateExists = false
this.updateDownloading = false
this.updateDownloaded = true
})
Helpers.bus.$on('update-error', () => {
this.updateExists = false
this.updateDownloaded = false
this.updateDownloading = false
})
},
methods: {
clearVideos() {
Videos.clear()
this.$router.push('home')
},
setDownloading() {
this.updateExists = false
this.updateDownloading = true
},
quitAndInstall() {
Helpers.quitAndInstall()
},
},
}
Expand All @@ -34,6 +63,14 @@

footer.toolbar.toolbar-footer
.toolbar-actions
a.btn.btn-primary(v-if='updateExists' @click='setDownloading()') Update
.btn.spinner(v-if='updateDownloading')
.bounce1
.bounce2
.bounce3
p (this may take a while)
a.btn.btn-primary(v-if='updateDownloaded' @click='quitAndInstall()') Restart

.btn-group.pull-right
a.btn.btn-default(@click='clearVideos' v-if='$route.name === \'videos\'')
span.icon.icon-trash
Expand All @@ -47,4 +84,15 @@

<style lang="scss">
@import "../styles/app.scss";
.toolbar-actions {
.spinner {
&.btn {
box-shadow: none;
}
p {
display: inline;
margin-left: 10px;
}
}
}
</style>
15 changes: 7 additions & 8 deletions app/src/components/Info.vue
Original file line number Diff line number Diff line change
@@ -1,22 +1,21 @@
<script>
export default {
name: 'Info',
data() {
return {
import Helpers from 'services/helpers'
}
},
export default {
name: 'Info',
methods: {
toggleDevTools() {
Helpers.toggleDevTools()
},
},
}
</script>

<template lang="pug">
#info.padded-more
h5 What's this?
h5(@click='toggleDevTools()') What's this?
p Easysubs is an open source app that allows you to download subtitles from
a.js-external-link(href='http://www.opensubtitles.org') &nbsp;OpenSubtitles&nbsp;
| in a very fast way.
Expand Down
5 changes: 5 additions & 0 deletions app/src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import Router from 'vue-router'
import App from './App'
import routes from './routes'

import Helpers from 'services/helpers'

Vue.use(Router)
Vue.config.debug = true

Expand All @@ -17,3 +19,6 @@ new Vue({
router,
...App,
}).$mount('#app')

Helpers.setupExternalLinks()
Helpers.listenToPing()
61 changes: 61 additions & 0 deletions app/src/services/helpers/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import Vue from 'vue'
const bus = new Vue()

const electron = require('electron')
const shell = electron.shell
const ipcRenderer = electron.ipcRenderer
const autoUpdater = electron.remote.autoUpdater

function setupExternalLinks() {
const supportExternalLinks = function (e) {
let href
let isExternal = false
const checkDomElement = function (element) {
if (element.nodeName === 'A') {
href = element.getAttribute('href')
}
if (element.classList.contains('js-external-link')) {
isExternal = true
}
if (href && isExternal) {
shell.openExternal(href)
e.preventDefault()
} else if (element.parentElement) {
checkDomElement(element.parentElement)
}
}
checkDomElement(e.target)
}
document.addEventListener('click', supportExternalLinks, false)
}

function listenToPing() {
ipcRenderer.on('ping', (event, message) => {
console.log('ping: ', message)
switch (message) {
case 'update-available':
case 'update-downloaded':
case 'update-error':
bus.$emit(message)
break
default:
break
}
})
}

function toggleDevTools() {
electron.remote.getCurrentWindow().toggleDevTools()
}

function quitAndInstall() {
autoUpdater.quitAndInstall()
}

export default {
setupExternalLinks,
listenToPing,
toggleDevTools,
quitAndInstall,
bus,
}

0 comments on commit 9f8ea1c

Please sign in to comment.