-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from matiastucci/v2
V2
- Loading branch information
Showing
6 changed files
with
144 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
} |