This repository has been archived by the owner on Dec 11, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 972
ledger backup and recovery #4396
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
const {app, BrowserWindow, session, webContents} = require('electron') | ||
const extensions = process.atomBinding('extension') | ||
const { getIndexHTML } = require('../../js/lib/appUrlUtil') | ||
|
||
let currentWebContents = {} | ||
let activeTab = null | ||
|
||
const cleanupWebContents = (tabId) => { | ||
delete currentWebContents[tabId] | ||
} | ||
|
||
const tabs = { | ||
init: () => { | ||
app.on('web-contents-created', function (event, tab) { | ||
// TODO(bridiver) - also exclude extension action windows?? | ||
if (extensions.isBackgroundPage(tab) || tab.getURL() === getIndexHTML()) { | ||
return | ||
} | ||
let tabId = tab.getId() | ||
tab.on('destroyed', cleanupWebContents.bind(null, tabId)) | ||
tab.on('crashed', cleanupWebContents.bind(null, tabId)) | ||
tab.on('close', cleanupWebContents.bind(null, tabId)) | ||
tab.on('set-active', function (evt, active) { | ||
if (active) { | ||
activeTab = tab | ||
} | ||
}) | ||
currentWebContents[tabId] = tab | ||
}) | ||
}, | ||
|
||
getWebContents: (tabId) => { | ||
return currentWebContents[tabId] | ||
}, | ||
|
||
create: (createProperties) => { | ||
return new Promise((resolve, reject) => { | ||
// TODO(bridiver) - make this available from electron | ||
var payload = {} | ||
process.emit('ELECTRON_GUEST_VIEW_MANAGER_NEXT_INSTANCE_ID', payload) | ||
var guestInstanceId = payload.returnValue | ||
|
||
let win = BrowserWindow.getFocusedWindow() | ||
let windowId = createProperties.windowId | ||
if (windowId && windowId !== -2) { | ||
win = BrowserWindow.fromId(windowId) || win | ||
} | ||
if (!win) { | ||
reject('Could not find a window for new tab') | ||
return | ||
} | ||
let opener = null | ||
let newSession = session.defaultSession | ||
let openerTabId = createProperties.openerTabId | ||
if (openerTabId) { | ||
opener = tabs.getWebContents(openerTabId) | ||
if (!opener) { | ||
reject('Opener does not exist') | ||
return | ||
} | ||
// only use the opener if it is in the same window | ||
if (opener.webContents.hostWebContents !== win.webContents) { | ||
reject('Opener must be in the same window as new tab') | ||
return | ||
} | ||
} | ||
|
||
opener = opener || activeTab | ||
if (opener) { | ||
newSession = opener.session | ||
} else { | ||
reject('Could not find an opener for new tab') | ||
return | ||
} | ||
|
||
let webPreferences = { | ||
isGuest: true, | ||
embedder: win.webContents, | ||
session: newSession, | ||
guestInstanceId, | ||
delayedLoadUrl: createProperties.url || 'about:newtab' | ||
} | ||
webPreferences = Object.assign({}, opener.getWebPreferences(), webPreferences) | ||
let guest = webContents.create(webPreferences) | ||
process.emit('ELECTRON_GUEST_VIEW_MANAGER_REGISTER_GUEST', { sender: opener }, guest, guestInstanceId) | ||
|
||
guest.once('did-finish-load', () => { | ||
resolve(guest) | ||
}) | ||
let active = createProperties.active !== false | ||
if (!active) { | ||
active = createProperties.selected !== false | ||
} | ||
let disposition = active ? 'foreground-tab' : 'background-tab' | ||
|
||
process.emit('ELECTRON_GUEST_VIEW_MANAGER_TAB_OPEN', | ||
{ sender: opener }, // event | ||
'about:blank', | ||
'', | ||
disposition, | ||
{ webPreferences: guest.getWebPreferences() }) | ||
}) | ||
} | ||
} | ||
|
||
module.exports = tabs |
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
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this callback may or may not happen asynchronously so the appActions should be called inside
setImmediate
to prevent any potential race conditions with state updates. The issue was discussed in slack, but this is how it happens: