Skip to content

Commit

Permalink
add in ipc comms for store update to refresh beaker pages
Browse files Browse the repository at this point in the history
  • Loading branch information
joshuef committed Nov 13, 2016
1 parent 820233e commit f12a66b
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 30 deletions.
15 changes: 1 addition & 14 deletions app/background-process.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// It doesn't have any windows which you can see on screen, but we can open
// window from here.

import { app, Menu } from 'electron'
import { app, Menu, ipcMain } from 'electron'
import log from 'loglevel'
import env from './env'

Expand Down Expand Up @@ -50,11 +50,6 @@ plugins.registerStandardSchemes()
app.on('ready', function () {


store.subscribe( e =>
{
saveStore();
})

const app =
{
//TODO: pull from package.json
Expand All @@ -67,14 +62,6 @@ app.on('ready', function () {

let token = auth.authorise( app ).then( tok =>
{
// TODO: Trigger save should be automatic not on every instance.
// NOTHING should be saved until a store is gotten. Or failed.
// Only then do we do createOrUpdateFile....
// setting for sync interval

//get store can optionally have a token passed?


getStore( tok.token )
.then( json =>
{
Expand Down
2 changes: 1 addition & 1 deletion app/background-process/safe-storage/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export function set (key, value)
{
let setter = {};
setter[key] = value;
store.dispatch( updateSetting( setter ) )
store.dispatch( updateSettings( setter ) )
})
}

Expand Down
13 changes: 11 additions & 2 deletions app/background-process/ui/windows.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ import * as downloads from './downloads'
import * as permissions from './permissions'
import log from '../../log'
import url from 'url'

import store, { saveStore } from '../safe-storage/store';

// globals
// =
var userDataDir
Expand Down Expand Up @@ -71,9 +74,15 @@ export function createShellWindow () {

}
});




store.subscribe( e =>
{
saveStore();
win.webContents.send('safeStore-updated', 'boom');

})



downloads.registerListener(win)
Expand Down
2 changes: 0 additions & 2 deletions app/builtin-pages/views/history.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,9 @@ function fetchMore (cb) {
if (isAtEnd)
return cb()

console.log( "beaker history page" );
isFetching = true
beakerHistory.getVisitHistory({ offset: visits.length, limit: 100 }).then(rows => {

console.log( "GOTTEN THE HISTORYYYY", rows );
if (rows.length == 0)
isAtEnd = true
else
Expand Down
5 changes: 5 additions & 0 deletions app/shell-window/command-handlers.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ import * as navbar from './ui/navbar'
import permsPrompt from './ui/prompts/permission'

export function setup () {
ipcRenderer.on('safeStore-updated', (e, type) => {
return pages.handleSafeStoreChange();
})


ipcRenderer.on('command', function (event, type, arg1, arg2, arg3) {
var page = pages.getActive()
switch (type) {
Expand Down
17 changes: 6 additions & 11 deletions app/shell-window/pages.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import * as promptbar from './ui/promptbar'
import * as statusBar from './ui/statusbar'
import { urlToData } from '../lib/fg/img'
import errorPage from '../lib/error-page'
import _ from 'lodash';
// import store from '../background-process/safe-storage/store/safe-store';

// constants
Expand Down Expand Up @@ -205,32 +206,26 @@ export function create (opts) {
if (!activePage)
setActive(page)

//for safe status page.
// if( url === DEFAULT_URL )
// {
// //and here we'd filter???
// let unsubscribe = store.subscribe( handleChange );
// }

return page
}


function handleChange() {

function handleStoreChange() {
var page = getAll();

// TODO: filter for settings pages?? Or just all beaker pages....
pages.forEach( page =>
{
if( page.isWebviewReady && page.getURL() === DEFAULT_URL )
if( page.isWebviewReady && page.getURL().includes('beaker:') )
{
page.reload()
}
})
}


export const handleSafeStoreChange = _.debounce( handleStoreChange, 200 );



export function remove (page) {
// find
Expand Down

0 comments on commit f12a66b

Please sign in to comment.