2018-09-22 12:28:50 +00:00
|
|
|
'use strict'
|
|
|
|
|
2019-02-01 18:56:46 +00:00
|
|
|
const ipcRenderer = require('@electron/internal/renderer/ipc-renderer-internal')
|
|
|
|
const ipcRendererUtils = require('@electron/internal/renderer/ipc-renderer-internal-utils')
|
2018-12-05 18:07:32 +00:00
|
|
|
|
2016-03-25 19:57:17 +00:00
|
|
|
window.onload = function () {
|
2016-01-14 18:35:29 +00:00
|
|
|
// Use menu API to show context menu.
|
2016-03-30 21:56:30 +00:00
|
|
|
window.InspectorFrontendHost.showContextMenuAtPoint = createMenu
|
2016-01-12 02:40:23 +00:00
|
|
|
|
2018-10-25 15:36:48 +00:00
|
|
|
// correct for Chromium returning undefined for filesystem
|
|
|
|
window.Persistence.FileSystemWorkspaceBinding.completeURL = completeURL
|
|
|
|
|
2016-01-14 18:35:29 +00:00
|
|
|
// Use dialog API to override file chooser dialog.
|
2018-10-14 06:30:49 +00:00
|
|
|
window.UI.createFileSelectorElement = createFileSelectorElement
|
2016-03-25 19:57:17 +00:00
|
|
|
}
|
2016-01-12 02:40:23 +00:00
|
|
|
|
2018-10-25 15:36:48 +00:00
|
|
|
// Extra / is needed as a result of MacOS requiring absolute paths
|
|
|
|
function completeURL (project, path) {
|
|
|
|
project = 'file:///'
|
|
|
|
return `${project}${path}`
|
|
|
|
}
|
|
|
|
|
2016-11-27 19:38:48 +00:00
|
|
|
window.confirm = function (message, title) {
|
2019-02-01 18:56:46 +00:00
|
|
|
return ipcRendererUtils.invokeSync('ELECTRON_INSPECTOR_CONFIRM', message, title)
|
2016-03-25 19:57:17 +00:00
|
|
|
}
|
2016-01-12 02:40:23 +00:00
|
|
|
|
2019-02-01 18:56:46 +00:00
|
|
|
ipcRenderer.on('ELECTRON_INSPECTOR_CONTEXT_MENU_CLICK', function (event, id) {
|
|
|
|
window.DevToolsAPI.contextMenuItemSelected(id)
|
|
|
|
})
|
2016-01-12 02:40:23 +00:00
|
|
|
|
2019-02-01 18:56:46 +00:00
|
|
|
ipcRenderer.on('ELECTRON_INSPECTOR_CONTEXT_MENU_CLOSE', function () {
|
|
|
|
window.DevToolsAPI.contextMenuCleared()
|
|
|
|
})
|
2016-01-12 02:40:23 +00:00
|
|
|
|
2016-07-12 18:54:45 +00:00
|
|
|
const useEditMenuItems = function (x, y, items) {
|
|
|
|
return items.length === 0 && document.elementsFromPoint(x, y).some(function (element) {
|
|
|
|
return element.nodeName === 'INPUT' || element.nodeName === 'TEXTAREA' || element.isContentEditable
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2019-02-01 18:56:46 +00:00
|
|
|
const createMenu = function (x, y, items) {
|
|
|
|
const isEditMenu = useEditMenuItems(x, y, items)
|
|
|
|
ipcRendererUtils.invoke('ELECTRON_INSPECTOR_CONTEXT_MENU', items, isEditMenu)
|
2016-07-12 18:54:45 +00:00
|
|
|
}
|
|
|
|
|
2016-07-12 18:31:40 +00:00
|
|
|
const showFileChooserDialog = function (callback) {
|
2019-02-01 18:56:46 +00:00
|
|
|
ipcRendererUtils.invoke('ELECTRON_INSPECTOR_SELECT_FILE').then(([path, data]) => {
|
|
|
|
if (path && data) {
|
|
|
|
callback(dataToHtml5FileObject(path, data))
|
|
|
|
}
|
|
|
|
})
|
2016-03-25 19:57:17 +00:00
|
|
|
}
|
2016-01-12 02:40:23 +00:00
|
|
|
|
2019-02-01 18:56:46 +00:00
|
|
|
const dataToHtml5FileObject = function (path, data) {
|
|
|
|
const blob = new Blob([data])
|
2016-03-25 19:57:17 +00:00
|
|
|
blob.name = path
|
|
|
|
return blob
|
|
|
|
}
|
2016-01-12 02:40:23 +00:00
|
|
|
|
2016-07-12 18:31:40 +00:00
|
|
|
const createFileSelectorElement = function (callback) {
|
|
|
|
const fileSelectorElement = document.createElement('span')
|
2016-03-25 19:57:17 +00:00
|
|
|
fileSelectorElement.style.display = 'none'
|
|
|
|
fileSelectorElement.click = showFileChooserDialog.bind(this, callback)
|
|
|
|
return fileSelectorElement
|
|
|
|
}
|