Skip to content

Commit

Permalink
add icon
Browse files Browse the repository at this point in the history
  • Loading branch information
max-mapper committed Mar 21, 2016
1 parent 5eedddc commit ddebe13
Show file tree
Hide file tree
Showing 6 changed files with 11,464 additions and 10 deletions.
Binary file added Icon.icns
Binary file not shown.
15 changes: 15 additions & 0 deletions error.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<style type="text/css">
div {
width: 300px;
height: 30px;
position: absolute;
top:0;
bottom: 0;
left: 0;
right: 0;
margin: auto;
}
</style>
<div><pre>
There was an error loading your page.
</pre></div>
2 changes: 0 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,8 @@ electron.app.on('ready', function () {
var size = electronScreen.getPrimaryDisplay().workAreaSize
var win = new electron.BrowserWindow({width: size.width, height: size.height, fullscreen: true})
win.loadURL('file://' + __dirname + '/index.html')

var canClose = true
win.on('close', function (e) {
console.log('close?', canClose)
if (!canClose) e.preventDefault()
})
electron.ipcMain.on('tab-change', function (event, tabCount) {
Expand Down
9 changes: 7 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"main": "index.js",
"scripts": {
"start": "electron index.js",
"test": "standard"
"test": "standard",
"build": "electron-packager . Tabby --platform=darwin --arch=x64 --version=0.37.2 --prune --icon=Icon.icns"
},
"standard": {
"ignore": [
Expand All @@ -16,10 +17,14 @@
"author": "",
"license": "ISC",
"dependencies": {
"csjs-inject": "^1.0.0",
"rainbow-load": "0.0.6",
"vkey": "^1.0.0"
"tld": "0.0.2",
"vkey": "^1.0.0",
"yo-yo": "^1.1.1"
},
"devDependencies": {
"electron-prebuilt": "^0.37.2",
"standard": "^6.0.8"
}
}
54 changes: 48 additions & 6 deletions renderer.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,48 @@
var url = require('url')
var dns = require('dns')
var electron = require('electron')
var remote = require('remote')
var yo = require('yo-yo')
var load = require('rainbow-load')
var vkey = require('vkey')
var url = require('url')
var tld = require('tld')
tld.defaultFile = __dirname + '/tlds.dat'
var Menu = require('./menu.js')

var errPage = 'file://' + __dirname + '/error.html'

module.exports = function () {
var menu = Menu(function onNewURL (href) {
var original = href
var tab = currentTab()
if (href.indexOf(' ') > -1) return search(original)
var parsed = url.parse(href)
if (!parsed.protocol) href = 'http://' + href
currentTab().setAttribute('src', href)
if (!parsed.protocol) {
href = 'http://' + href
parsed = url.parse(href)
}
var validTld = tld.registered(parsed.hostname)
if (validTld && href.indexOf('.') > -1) return tab.setAttribute('src', href)

var queryFinished = false
setTimeout(function () {
if (queryFinished) return
queryFinished = true
search(original)
}, 250)

dns.lookup(parsed.hostname, function (err, address) {
console.log('dns', err, address)
if (queryFinished) return
queryFinished = true
if (err) return search(original)
else tab.setAttribute('src', href)
})

function search (href) {
href = 'https://duckduckgo.com/?q=' + href.split(' ').join('+')
return tab.setAttribute('src', href)
}
})
var tabs = []
initShortcuts()
Expand All @@ -27,11 +59,21 @@ module.exports = function () {
tabs.push(tab)
showTab(tab)
tab.addEventListener('did-start-loading', function () {
if (tab.getAttribute('src') === errPage) return
delete tab.__GOT_RESPONSE
load.show()
})
tab.addEventListener('did-stop-loading', function () {
if (tab.getAttribute('src') === errPage) return
menu.input.value = tab.getAttribute('src')
load.hide()
if (!tab.__GOT_RESPONSE) {
tab.setAttribute('src', errPage)
console.error('Error loading')
}
})
tab.addEventListener('did-get-response-details', function () {
tab.__GOT_RESPONSE = true
})

var content = document.querySelector('.tabs')
Expand All @@ -41,7 +83,7 @@ module.exports = function () {

function currentTab () {
for (var i = 0; i < tabs.length; i++) {
if (tabs[i].getAttribute('style').match('block')) return tabs[i]
if (tabs[i].getAttribute('style').match('flex')) return tabs[i]
}
}

Expand All @@ -50,7 +92,7 @@ module.exports = function () {
if (idx === -1) return
for (var i = 0; i < tabs.length; i++) {
if (i === idx) {
tabs[i].setAttribute('style', 'display: block')
tabs[i].setAttribute('style', 'display: flex')
menu.input.value = tabs[i].getAttribute('src')
} else {
tabs[i].setAttribute('style', 'display: none')
Expand All @@ -60,7 +102,7 @@ module.exports = function () {

function changeTab (num) {
for (var i = 0; i < tabs.length; i++) {
if (tabs[i].getAttribute('style').match('block')) {
if (tabs[i].getAttribute('style').match('flex')) {
var next = i + num
if (next >= tabs.length) next = 0
if (next === -1) next = tabs.length - 1
Expand Down
Loading

0 comments on commit ddebe13

Please sign in to comment.