Skip to content
Permalink
Browse files

Merge branch 'master' into electron5

  • Loading branch information...
pfrazee committed Apr 26, 2019
2 parents 303f3a0 + ca18809 commit 31911aa0d54e13ccb3ecea0d6fd3e374a057d9ce
@@ -99,8 +99,8 @@ export function reposition (parentWindow) {
win.setBounds({
x: parentBounds.x + win.boundsOpt.right - 320,
y: parentBounds.y + win.boundsOpt.top,
width: 320,
height: 88
width: 350,
height: 90
})
} else if (win.menuId === 'local-path') {
win.setBounds({
@@ -1,4 +1,4 @@
import { app, dialog, BrowserView, BrowserWindow, Menu, clipboard } from 'electron'
import { app, dialog, BrowserView, BrowserWindow, Menu, clipboard, ipcMain } from 'electron'
import * as beakerCore from '@beaker/core'
import errorPage from '@beaker/core/lib/error-page'
import path from 'path'
@@ -94,6 +94,7 @@ var activeViews = {} // map of {[win.id]: Array<View>}
var closedURLs = {} // map of {[win.id]: Array<string>}
var windowEvents = {} // mapof {[win.id]: Events}
var noRedirectHostnames = new Set() // set of hostnames which have dat-redirection disabled
var nextViewIsScriptCloseable = false // will the next view created be "script closable"?

// classes
// =
@@ -131,6 +132,7 @@ class View {
this.isInpageFindActive = false // is the inpage-finder UI active?
this.currentInpageFindString = undefined // what's the current inpage-finder query string?
this.currentInpageFindResults = undefined // what's the current inpage-finder query results?
this.isScriptClosable = takeIsScriptClosable() // can this view be closed by `window.close` ?

// helper state
this.peers = 0 // how many peers does the site have?
@@ -149,6 +151,7 @@ class View {
this.webContents.on('did-stop-loading', this.onDidStopLoading.bind(this))
this.webContents.on('did-fail-load', this.onDidFailLoad.bind(this))
this.webContents.on('update-target-url', this.onUpdateTargetUrl.bind(this))
this.webContents.on('page-title-updated', this.onPageTitleUpdated.bind(this)) // NOTE page-title-updated isn't documented on webContents but it is supported
this.webContents.on('page-favicon-updated', this.onPageFaviconUpdated.bind(this))
this.webContents.on('new-window', this.onNewWindow.bind(this))
this.webContents.on('media-started-playing', this.onMediaChange.bind(this))
@@ -219,6 +222,13 @@ class View {
this.browserView.webContents.loadURL(url)
}

resize () {
const win = this.browserWindow
var {width, height} = win.getContentBounds()
this.browserView.setBounds({x: 0, y: Y_POSITION, width, height: height - Y_POSITION})
this.browserView.setAutoResize({width: true, height: true})
}

activate () {
this.isActive = true

@@ -227,10 +237,7 @@ class View {
permPrompt.show(this.browserView)
modals.show(this.browserView)

var {width, height} = win.getBounds()
this.browserView.setBounds({x: 0, y: Y_POSITION, width, height: height - Y_POSITION})
this.browserView.setAutoResize({width: true, height: true})

this.resize()
this.webContents.focus()
}

@@ -414,7 +421,9 @@ class View {
.markdown code { padding: 3px 5px; }
.markdown pre > code { display: block; }
`)
this.webContents.executeJavaScript(await fs.readFile(path.join(app.getAppPath(), 'markdown-renderer.build.js'), 'utf8'))
let mdpath = path.join(app.getAppPath(), 'markdown-renderer.build.js')
mdpath = mdpath.replace('app.asar', 'app.asar.unpacked') // fetch from unpacked dir
this.webContents.executeJavaScript(await fs.readFile(mdpath, 'utf8'))
}

// json rendering
@@ -446,7 +455,9 @@ class View {
background: #ddd;
}
`)
this.webContents.executeJavaScript(await fs.readFile(path.join(app.getAppPath(), 'json-renderer.build.js'), 'utf8'))
let jsonpath = path.join(app.getAppPath(), 'json-renderer.build.js')
jsonpath = jsonpath.replace('app.asar', 'app.asar.unpacked') // fetch from unpacked dir
this.webContents.executeJavaScript(await fs.readFile(jsonpath, 'utf8'))
}
}

@@ -501,6 +512,7 @@ class View {
// update state
this.isLoading = true
this.loadingURL = null
this.favicons = null
this.isReceivingAssets = false
this.wasDatTimeout = false

@@ -592,6 +604,10 @@ class View {
statusBar.set(this.browserWindow, url)
}

onPageTitleUpdated (e, title) {
this.emitUpdateState()
}

onPageFaviconUpdated (e, favicons) {
this.favicons = favicons && favicons[0] ? favicons : null
this.emitUpdateState()
@@ -625,6 +641,24 @@ class View {
// =

export function setup () {
// listen for webContents messages
ipcMain.on('BEAKER_MARK_NEXT_VIEW_SCRIPTCLOSEABLE', e => {
nextViewIsScriptCloseable = true
e.returnValue = true
})
ipcMain.on('BEAKER_SCRIPTCLOSE_SELF', e => {
var browserView = BrowserView.fromWebContents(e.sender)
if (browserView) {
var view = findView(browserView)
if (view && view.isScriptClosable) {
remove(view.browserWindow, view)
e.returnValue = true
return
}
}
e.returnValue = false
})

// track peer-counts
beakerCore.dat.library.createEventStream().on('data', ([evt, {details}]) => {
if (evt !== 'network-changed') return
@@ -670,10 +704,20 @@ export function getActive (win) {
return getAll(win).find(view => view.isActive)
}

export function findContainingWindow (view) {
export function findView (browserView) {
for (let winId in activeViews) {
for (let v of activeViews[winId]) {
if (v.browserView === browserView) {
return v
}
}
}
}

export function findContainingWindow (browserView) {
for (let winId in activeViews) {
for (let v of activeViews[winId]) {
if (v.browserView === view) {
if (v.browserView === browserView) {
return v.browserWindow
}
}
@@ -798,6 +842,11 @@ export function setActive (win, view) {
emitReplaceState(win)
}

export function resize (win) {
var active = getActive(win)
if (active) active.resize()
}

export function initializeFromSnapshot (win, snapshot) {
win = getTopWindow(win)
for (let url of snapshot) {
@@ -840,9 +889,7 @@ export async function loadPins (win) {
win = getTopWindow(win)
var json = await settingsDb.get('pinned_tabs')
try { JSON.parse(json).forEach(url => create(win, url, {isPinned: true})) }
catch (e) {
console.log('Failed to load pins', e)
}
catch (e) {}
}

export function reopenLastRemoved (win) {
@@ -1174,7 +1221,7 @@ function addToNoRedirects (url) {

async function fireBeforeUnloadEvent (wc) {
try {
if (wc.isWaitingForResponse()) {
if (wc.isLoading() || wc.isWaitingForResponse()) {
return // dont bother
}
return await wc.executeJavaScript(`
@@ -1187,4 +1234,12 @@ async function fireBeforeUnloadEvent (wc) {
} catch (e) {
// ignore
}
}

// `nextViewIsScriptCloseable` is set by a message received prior to window.open() being called
// we capture the state of the flag on the next created view, then reset it
function takeIsScriptClosable () {
var b = nextViewIsScriptCloseable
nextViewIsScriptCloseable = false
return b
}
@@ -225,14 +225,19 @@ export function createShellWindow (windowState) {
registerGlobalKeybinding(win, 'CmdOrCtrl+[', onGoBack(win))
registerGlobalKeybinding(win, 'CmdOrCtrl+]', onGoForward(win))
registerGlobalKeybinding(win, 'Alt+D', onFocusLocation(win))
registerGlobalKeybinding(win, 'F5', onReload(win))
registerGlobalKeybinding(win, 'F6', onFocusLocation(win))

// register event handlers
win.on('browser-backward', onGoBack(win))
win.on('browser-forward', onGoForward(win))
win.on('scroll-touch-begin', sendScrollTouchBegin)
win.on('scroll-touch-end', sendToWebContents('scroll-touch-end'))
win.on('focus', sendToWebContents('focus'))
win.on('blur', sendToWebContents('blur'))
win.on('blur', e => {
statusBarSubwindow.set(win, false) // hide the statusbar on blur
sendToWebContents('blur')(e)
})
win.on('app-command', (e, cmd) => { onAppCommand(win, e, cmd) })
win.on('enter-full-screen', e => {
// update UI
@@ -251,6 +256,7 @@ export function createShellWindow (windowState) {
// sendToWebContents('leave-full-screen')(e)
})
win.on('resize', () => {
viewManager.resize(win)
for (let k in subwindows) {
subwindows[k].reposition(win)
}
@@ -402,6 +408,10 @@ function onGoForward (win) {
return () => viewManager.getActive(win).webContents.goForward()
}

function onReload (win) {
return () => viewManager.getActive(win).webContents.reload()
}

function onFocusLocation (win) {
return () => win.webContents.send('command', 'focus-location')
}
@@ -342,6 +342,14 @@ async function gotoFileEditor (filePath) {
onOpenFileEditor()
}

function resolvePaymentLink (archiveUrl, paymentLink) {
if (paymentLink.indexOf('://') === -1) {
const shouldAddSlash = !archiveUrl.endsWith('/') && !paymentLink.startsWith('/')
return `${archiveUrl}${shouldAddSlash ? '/' : ''}${paymentLink}`
}
return paymentLink
}

// rendering
// =

@@ -835,6 +843,11 @@ function renderReadmeHint () {
</div>`
}

function renderDonationLink (archiveUrl, paymentLink) {
const url = resolvePaymentLink(archiveUrl, paymentLink)
return yo`<a href=${url}>${url}</a>`
}

function renderSettingsView () {
const isOwner = _get(archive, 'info.isOwner')

@@ -1013,13 +1026,13 @@ function renderSettingsView () {
? yo`
<p>
Enter a link to your donation page and Beaker will show
a <span class="fa fa-heart"></span> icon in your page's URL bar.
a <span class="fa fa-donate"></span> icon in your page's URL bar.
${renderSettingsField({key: 'paymentLink', value: paymentLink, placeholder: 'Example: https://opencollective.com/beaker', onUpdate: setManifestValue})}
</p>
`
: paymentLink
? yo`<p><a href=${paymentLink}>${paymentLink}</a></p>`
? yo`<p>${renderDonationLink(archive.url, paymentLink)}</p>`
: yo`<p><em>No link provided.</em></p>`
}
</div>
@@ -1156,7 +1169,7 @@ function renderNetworkView () {
</div>`
] : yo`
<div class="hint">
<i class="far fa-heart"></i>
<i class="fa fa-hand-holding-heart"></i>
<strong>Give back!</strong> Seed this project${"'"}s files to help keep them online.
<a href="https://beakerbrowser.com/docs/how-beaker-works/peer-to-peer-websites#keeping-a-peer-to-peer-website-online" target="_blank" class="learn-more-link">Learn more</a>
</div>`
@@ -6,6 +6,10 @@ process.on('uncaughtException', (err) => {
console.error('Uncaught exception:', err)
})

process.on('disconnect', () => {
process.exit()
})

process.once('message', firstMsg => {
beakerCoreDatDaemon.setup({
rpcAPI,
@@ -39,6 +39,9 @@ if (!document.querySelector('main')) {
var navReq = await fetch('/nav.md')
if (!navReq.ok) return
var navMD = await navReq.text()
if (navMD.includes('<!doctype') || navMD.includes('<html')) {
return // dont render if we get HTML - this can indicate a 404 page
}
navHTML = md.render(navMD)
document.querySelector('nav').innerHTML = navHTML
} catch (e) {
@@ -225,7 +225,7 @@ class NavbarLocation extends LitElement {
var cls = classMap({donate: true, pressed: this.isDonateMenuOpen})
return html`
<button class="${cls}" @click=${this.onClickDonateMenu}>
<i class="far fa-heart"></i>
<i class="fa fa-donate"></i>
</button>
`
}
@@ -240,7 +240,7 @@ ${spinnerCSS}
}
.tab.pinned {
width: 45px;
flex: 0 0 45px;
}
.tab-favicon {
@@ -3,7 +3,7 @@
"productName": "Beaker Browser",
"description": "An Experimental Peer-to-Peer Web Browser.",
"homepage": "https://beakerbrowser.com/",
"version": "0.8.6",
"version": "0.8.8",
"author": "Paul Frazee <pfrazee@gmail.com>",
"copyright": "© 2019, Blue Link Labs",
"main": "background-process.build.js",
@@ -167,7 +167,7 @@ class BrowserMenu extends LitElement {
</div>
<div class="menu-item" @click=${e => this.onOpenPage(e, 'https://opencollective.com/beaker')}>
<i class="far fa-heart"></i>
<i class="fa fa-donate"></i>
<span class="label">Support Beaker</span>
</div>
</div>
Oops, something went wrong.

0 comments on commit 31911aa

Please sign in to comment.
You can’t perform that action at this time.