Updated astielectron deps
This commit is contained in:
parent
5e7a8bf51a
commit
02f2ed2318
|
@ -1,13 +1,50 @@
|
|||
'use strict'
|
||||
|
||||
const electron = require('electron')
|
||||
const {app, BrowserWindow, ipcMain, Menu, MenuItem, Tray} = electron
|
||||
const {app, BrowserWindow, ipcMain, Menu, MenuItem, Tray, dialog, Notification} = electron
|
||||
const consts = require('./src/consts.js')
|
||||
const client = require('./src/client.js').init()
|
||||
const rl = require('readline').createInterface({input: client.socket})
|
||||
|
||||
let elements = {}
|
||||
let menus = {}
|
||||
let callbacks = {};
|
||||
let counters = {};
|
||||
let elements = {};
|
||||
let menus = {};
|
||||
let quittingApp = false;
|
||||
|
||||
// Single instance
|
||||
let lastWindow = null;
|
||||
if (process.argv[3] === "true") {
|
||||
// Lock
|
||||
const singlesInstanceLock = app.requestSingleInstanceLock();
|
||||
if (!singlesInstanceLock) {
|
||||
app.quit();
|
||||
return;
|
||||
}
|
||||
|
||||
// Someone tried to run a second instance, we should focus our window.
|
||||
app.on('second-instance', (event, commandLine, workingDirectory) => {
|
||||
if (lastWindow) {
|
||||
if (lastWindow.isMinimized()) lastWindow.restore();
|
||||
lastWindow.focus();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Command line switches
|
||||
let idx = 4;
|
||||
for (let i = idx; i < process.argv.length; i++) {
|
||||
let s = process.argv[i].replace(/^[\-]+/g,"");
|
||||
let v;
|
||||
if (typeof process.argv[i+1] !== "undefined" && !process.argv[i+1].startsWith("-")) {
|
||||
v = process.argv[i+1];
|
||||
i++;
|
||||
}
|
||||
app.commandLine.appendSwitch(s, v);
|
||||
}
|
||||
|
||||
// App is quitting
|
||||
app.on('before-quit', () => quittingApp = true);
|
||||
|
||||
// App is ready
|
||||
app.on('ready',() => {
|
||||
|
@ -17,27 +54,85 @@ app.on('ready',() => {
|
|||
|
||||
// Listen to screen events
|
||||
screen.on('display-added', function() {
|
||||
client.write(consts.mainTargetID, consts.eventNames.displayEventAdded, {displays: {all: screen.getAllDisplays(), primary: screen.getPrimaryDisplay()}})
|
||||
client.write(consts.targetIds.app, consts.eventNames.displayEventAdded, {displays: {all: screen.getAllDisplays(), primary: screen.getPrimaryDisplay()}})
|
||||
})
|
||||
screen.on('display-metrics-changed', function() {
|
||||
client.write(consts.mainTargetID, consts.eventNames.displayEventMetricsChanged, {displays: {all: screen.getAllDisplays(), primary: screen.getPrimaryDisplay()}})
|
||||
client.write(consts.targetIds.app, consts.eventNames.displayEventMetricsChanged, {displays: {all: screen.getAllDisplays(), primary: screen.getPrimaryDisplay()}})
|
||||
})
|
||||
screen.on('display-removed', function() {
|
||||
client.write(consts.mainTargetID, consts.eventNames.displayEventRemoved, {displays: {all: screen.getAllDisplays(), primary: screen.getPrimaryDisplay()}})
|
||||
client.write(consts.targetIds.app, consts.eventNames.displayEventRemoved, {displays: {all: screen.getAllDisplays(), primary: screen.getPrimaryDisplay()}})
|
||||
})
|
||||
|
||||
// Listen on main ipcMain
|
||||
ipcMain.on(consts.eventNames.ipcWindowMessage, (event, arg) => {
|
||||
client.write(arg.targetID, consts.eventNames.windowEventMessage, {message: arg.message})
|
||||
})
|
||||
ipcMain.on(consts.eventNames.ipcEventMessage, (event, arg) => {
|
||||
let payload = {message: arg.message};
|
||||
if (typeof arg.callbackId !== "undefined") payload.callbackId = arg.callbackId;
|
||||
client.write(arg.targetID, consts.eventNames.windowEventMessage, payload)
|
||||
});
|
||||
ipcMain.on(consts.eventNames.ipcEventMessageCallback, (event, arg) => {
|
||||
let payload = {message: arg.message};
|
||||
if (typeof arg.callbackId !== "undefined") payload.callbackId = arg.callbackId;
|
||||
client.write(arg.targetID, consts.eventNames.windowEventMessageCallback, payload)
|
||||
});
|
||||
|
||||
// Read from client
|
||||
rl.on('line', function(line){
|
||||
// Parse the JSON
|
||||
var json = JSON.parse(line)
|
||||
let json = JSON.parse(line)
|
||||
|
||||
// Switch on event name
|
||||
let window;
|
||||
switch (json.name) {
|
||||
// App
|
||||
case consts.eventNames.appCmdQuit:
|
||||
app.quit();
|
||||
break;
|
||||
|
||||
// Dock
|
||||
case consts.eventNames.dockCmdBounce:
|
||||
let id = 0;
|
||||
if (typeof app.dock !== "undefined") {
|
||||
id = app.dock.bounce(json.bounceType);
|
||||
}
|
||||
client.write(consts.targetIds.dock, consts.eventNames.dockEventBouncing, {id: id});
|
||||
break;
|
||||
case consts.eventNames.dockCmdBounceDownloads:
|
||||
if (typeof app.dock !== "undefined") {
|
||||
app.dock.downloadFinished(json.filePath);
|
||||
}
|
||||
client.write(consts.targetIds.dock, consts.eventNames.dockEventDownloadsBouncing);
|
||||
break;
|
||||
case consts.eventNames.dockCmdCancelBounce:
|
||||
if (typeof app.dock !== "undefined") {
|
||||
app.dock.cancelBounce(json.id);
|
||||
}
|
||||
client.write(consts.targetIds.dock, consts.eventNames.dockEventBouncingCancelled);
|
||||
break;
|
||||
case consts.eventNames.dockCmdHide:
|
||||
if (typeof app.dock !== "undefined") {
|
||||
app.dock.hide();
|
||||
}
|
||||
client.write(consts.targetIds.dock, consts.eventNames.dockEventHidden);
|
||||
break;
|
||||
case consts.eventNames.dockCmdSetBadge:
|
||||
if (typeof app.dock !== "undefined") {
|
||||
app.dock.setBadge(json.badge);
|
||||
}
|
||||
client.write(consts.targetIds.dock, consts.eventNames.dockEventBadgeSet);
|
||||
break;
|
||||
case consts.eventNames.dockCmdSetIcon:
|
||||
if (typeof app.dock !== "undefined") {
|
||||
app.dock.setIcon(json.image);
|
||||
}
|
||||
client.write(consts.targetIds.dock, consts.eventNames.dockEventIconSet);
|
||||
break;
|
||||
case consts.eventNames.dockCmdShow:
|
||||
if (typeof app.dock !== "undefined") {
|
||||
app.dock.show();
|
||||
}
|
||||
client.write(consts.targetIds.dock, consts.eventNames.dockEventShown);
|
||||
break;
|
||||
|
||||
// Menu
|
||||
case consts.eventNames.menuCmdCreate:
|
||||
menuCreate(json.menu)
|
||||
|
@ -47,7 +142,7 @@ app.on('ready',() => {
|
|||
break;
|
||||
case consts.eventNames.menuCmdDestroy:
|
||||
elements[json.targetID] = null
|
||||
if (menus[json.menu.rootId] == json.targetID) {
|
||||
if (menus[json.menu.rootId] === json.targetID) {
|
||||
menus[json.menu.rootId] = null
|
||||
setMenu(json.menu.rootId)
|
||||
}
|
||||
|
@ -72,6 +167,23 @@ app.on('ready',() => {
|
|||
client.write(json.targetID, consts.eventNames.menuItemEventVisibleSet)
|
||||
break;
|
||||
|
||||
// Notification
|
||||
case consts.eventNames.notificationCmdCreate:
|
||||
notificationCreate(json);
|
||||
break;
|
||||
case consts.eventNames.notificationCmdShow:
|
||||
if (Notification.isSupported()) {
|
||||
elements[json.targetID].show();
|
||||
}
|
||||
break;
|
||||
|
||||
// Session
|
||||
case consts.eventNames.sessionCmdClearCache:
|
||||
elements[json.targetID].clearCache(function() {
|
||||
client.write(json.targetID, consts.eventNames.sessionEventClearedCache)
|
||||
})
|
||||
break;
|
||||
|
||||
// Sub menu
|
||||
case consts.eventNames.subMenuCmdAppend:
|
||||
elements[json.targetID].append(menuItemCreate(json.menuItem))
|
||||
|
@ -79,7 +191,7 @@ app.on('ready',() => {
|
|||
client.write(json.targetID, consts.eventNames.subMenuEventAppended)
|
||||
break;
|
||||
case consts.eventNames.subMenuCmdClosePopup:
|
||||
var window = null
|
||||
window = null
|
||||
if (typeof json.windowId !== "undefined") {
|
||||
window = elements[json.windowId]
|
||||
}
|
||||
|
@ -92,7 +204,7 @@ app.on('ready',() => {
|
|||
client.write(json.targetID, consts.eventNames.subMenuEventInserted)
|
||||
break;
|
||||
case consts.eventNames.subMenuCmdPopup:
|
||||
var window = null
|
||||
window = null
|
||||
if (typeof json.windowId !== "undefined") {
|
||||
window = elements[json.windowId]
|
||||
}
|
||||
|
@ -103,20 +215,22 @@ app.on('ready',() => {
|
|||
|
||||
// Tray
|
||||
case consts.eventNames.trayCmdCreate:
|
||||
elements[json.targetID] = new Tray(json.trayOptions.image)
|
||||
if (typeof json.menuId !== "undefined") {
|
||||
elements[json.targetID].setContextMenu(elements[json.menuId]);
|
||||
}
|
||||
if (typeof json.trayOptions.tooltip !== "undefined") {
|
||||
elements[json.targetID].setToolTip(json.trayOptions.tooltip);
|
||||
}
|
||||
client.write(json.targetID, consts.eventNames.trayEventCreated)
|
||||
trayCreate(json)
|
||||
break;
|
||||
case consts.eventNames.trayCmdDestroy:
|
||||
elements[json.targetID].destroy()
|
||||
elements[json.targetID] = null
|
||||
client.write(json.targetID, consts.eventNames.trayEventDestroyed)
|
||||
break;
|
||||
case consts.eventNames.trayCmdSetImage:
|
||||
elements[json.targetID].setImage(json.image);
|
||||
client.write(json.targetID, consts.eventNames.trayEventImageSet)
|
||||
break;
|
||||
|
||||
// Web contents
|
||||
case consts.eventNames.webContentsEventLoginCallback:
|
||||
executeCallback(consts.callbackNames.webContentsLogin, json, [json.username, json.password]);
|
||||
break;
|
||||
|
||||
// Window
|
||||
case consts.eventNames.windowCmdBlur:
|
||||
|
@ -141,11 +255,17 @@ app.on('ready',() => {
|
|||
case consts.eventNames.windowCmdHide:
|
||||
elements[json.targetID].hide()
|
||||
break;
|
||||
case consts.eventNames.windowCmdLog:
|
||||
elements[json.targetID].webContents.send(consts.eventNames.ipcCmdLog, json.message)
|
||||
break;
|
||||
case consts.eventNames.windowCmdMaximize:
|
||||
elements[json.targetID].maximize()
|
||||
break;
|
||||
case consts.eventNames.windowCmdMessage:
|
||||
elements[json.targetID].webContents.send(consts.eventNames.ipcWindowMessage, json.message)
|
||||
case consts.eventNames.windowCmdMessageCallback:
|
||||
let m = {message: json.message}
|
||||
if (typeof json.callbackId !== "undefined") m.callbackId = json.callbackId
|
||||
elements[json.targetID].webContents.send(json.name === consts.eventNames.windowCmdMessageCallback ? consts.eventNames.ipcCmdMessageCallback : consts.eventNames.ipcCmdMessage, m)
|
||||
break;
|
||||
case consts.eventNames.windowCmdMinimize:
|
||||
elements[json.targetID].minimize()
|
||||
|
@ -172,17 +292,25 @@ app.on('ready',() => {
|
|||
elements[json.targetID].unmaximize()
|
||||
break;
|
||||
}
|
||||
})
|
||||
});
|
||||
|
||||
// Send electron.ready event
|
||||
client.write(consts.mainTargetID, consts.eventNames.appEventReady, {displays: {all: screen.getAllDisplays(), primary: screen.getPrimaryDisplay()}})
|
||||
})
|
||||
client.write(consts.targetIds.app, consts.eventNames.appEventReady, {
|
||||
displays: {
|
||||
all: screen.getAllDisplays(),
|
||||
primary: screen.getPrimaryDisplay()
|
||||
},
|
||||
supported: {
|
||||
notification: Notification.isSupported()
|
||||
}
|
||||
})
|
||||
});
|
||||
|
||||
// menuCreate creates a new menu
|
||||
function menuCreate(menu) {
|
||||
if (typeof menu !== "undefined") {
|
||||
elements[menu.id] = new Menu()
|
||||
for(var i = 0; i < menu.items.length; i++) {
|
||||
for(let i = 0; i < menu.items.length; i++) {
|
||||
elements[menu.id].append(menuItemCreate(menu.items[i]))
|
||||
}
|
||||
return elements[menu.id]
|
||||
|
@ -216,19 +344,83 @@ function menuItemToJSON(menuItem) {
|
|||
|
||||
// setMenu sets a menu
|
||||
function setMenu(rootId) {
|
||||
var menu = null
|
||||
let menu = null
|
||||
if (typeof menus[rootId] !== "undefined" && typeof elements[menus[rootId]] !== "undefined") {
|
||||
menu = elements[menus[rootId]]
|
||||
}
|
||||
rootId == consts.mainTargetID ? Menu.setApplicationMenu(menu) : elements[rootId].setMenu(menu)
|
||||
if (rootId === consts.targetIds.app) {
|
||||
Menu.setApplicationMenu(menu)
|
||||
} else if (rootId === consts.targetIds.dock && typeof app.dock !== "undefined") {
|
||||
app.dock.setMenu(menu)
|
||||
} else if (elements[rootId].constructor === Tray) {
|
||||
elements[rootId].setContextMenu(menu);
|
||||
} else {
|
||||
elements[rootId].setMenu(menu);
|
||||
}
|
||||
}
|
||||
|
||||
// notificationCreate creates a notification
|
||||
function notificationCreate(json) {
|
||||
if (Notification.isSupported()) {
|
||||
elements[json.targetID] = new Notification(json.notificationOptions);
|
||||
elements[json.targetID].on('action', (event, index) => { client.write(json.targetID, consts.eventNames.notificationEventActioned, {index: index}) })
|
||||
elements[json.targetID].on('click', () => { client.write(json.targetID, consts.eventNames.notificationEventClicked) })
|
||||
elements[json.targetID].on('close', () => { client.write(json.targetID, consts.eventNames.notificationEventClosed) })
|
||||
elements[json.targetID].on('reply', (event, reply) => { client.write(json.targetID, consts.eventNames.notificationEventReplied, {reply: reply}) })
|
||||
elements[json.targetID].on('show', () => { client.write(json.targetID, consts.eventNames.notificationEventShown) })
|
||||
}
|
||||
client.write(json.targetID, consts.eventNames.notificationEventCreated)
|
||||
}
|
||||
|
||||
// trayCreate creates a tray
|
||||
function trayCreate(json) {
|
||||
elements[json.targetID] = new Tray(json.trayOptions.image);
|
||||
if (typeof json.trayOptions.tooltip !== "undefined") {
|
||||
elements[json.targetID].setToolTip(json.trayOptions.tooltip);
|
||||
}
|
||||
elements[json.targetID].on('click', (index, event) => { client.write(json.targetID, consts.eventNames.trayEventClicked, {"bounds":{x:event.x, y:event.y,width:event.width,height:event.height}})})
|
||||
elements[json.targetID].on('double-click', (index, event) => { client.write(json.targetID, consts.eventNames.trayEventDoubleClicked, {"bounds":{x:event.x, y:event.y,width:event.width,height:event.height}})})
|
||||
elements[json.targetID].on('right-click', (index, event) => { client.write(json.targetID, consts.eventNames.trayEventRightClicked, {"bounds":{x:event.x, y:event.y,width:event.width,height:event.height}})})
|
||||
client.write(json.targetID, consts.eventNames.trayEventCreated)
|
||||
}
|
||||
|
||||
// windowCreate creates a new window
|
||||
function windowCreate(json) {
|
||||
elements[json.targetID] = new BrowserWindow(json.windowOptions)
|
||||
if (typeof json.windowOptions.proxy !== "undefined") {
|
||||
elements[json.targetID].webContents.session.setProxy(json.windowOptions.proxy, function() {
|
||||
windowCreateFinish(json)
|
||||
})
|
||||
} else {
|
||||
windowCreateFinish(json)
|
||||
}
|
||||
}
|
||||
|
||||
// windowCreateFinish finishes creating a new window
|
||||
function windowCreateFinish(json) {
|
||||
elements[json.targetID].setMenu(null)
|
||||
elements[json.targetID].loadURL(json.url);
|
||||
elements[json.targetID].loadURL(json.url, (typeof json.windowOptions.load !== "undefined" ? json.windowOptions.load : {}));
|
||||
elements[json.targetID].on('blur', () => { client.write(json.targetID, consts.eventNames.windowEventBlur) })
|
||||
elements[json.targetID].on('close', (e) => {
|
||||
if (typeof json.windowOptions.custom !== "undefined") {
|
||||
if (typeof json.windowOptions.custom.messageBoxOnClose !== "undefined") {
|
||||
let buttonId = dialog.showMessageBox(null, json.windowOptions.custom.messageBoxOnClose)
|
||||
if (typeof json.windowOptions.custom.messageBoxOnClose.confirmId !== "undefined" && json.windowOptions.custom.messageBoxOnClose.confirmId !== buttonId) {
|
||||
e.preventDefault()
|
||||
return
|
||||
}
|
||||
}
|
||||
if (!quittingApp) {
|
||||
if (json.windowOptions.custom.minimizeOnClose) {
|
||||
e.preventDefault();
|
||||
elements[json.targetID].minimize();
|
||||
} else if (json.windowOptions.custom.hideOnClose) {
|
||||
e.preventDefault();
|
||||
elements[json.targetID].hide();
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
elements[json.targetID].on('closed', () => {
|
||||
client.write(json.targetID, consts.eventNames.windowEventClosed)
|
||||
delete elements[json.targetID]
|
||||
|
@ -249,13 +441,44 @@ function windowCreate(json) {
|
|||
`const {ipcRenderer} = require('electron')
|
||||
const {dialog} = require('electron').remote
|
||||
var astilectron = {
|
||||
listen: function(callback) {
|
||||
ipcRenderer.on('`+ consts.eventNames.ipcWindowMessage +`', function(event, message) {
|
||||
callback(message)
|
||||
onMessageOnce: false,
|
||||
onMessage: function(callback) {
|
||||
if (astilectron.onMessageOnce) {
|
||||
return
|
||||
}
|
||||
ipcRenderer.on('`+ consts.eventNames.ipcCmdMessage +`', function(event, message) {
|
||||
let v = callback(message.message)
|
||||
if (typeof message.callbackId !== "undefined") {
|
||||
let e = {callbackId: message.callbackId, targetID: '`+ json.targetID +`'}
|
||||
if (typeof v !== "undefined") e.message = v
|
||||
ipcRenderer.send('`+ consts.eventNames.ipcEventMessageCallback +`', e)
|
||||
}
|
||||
})
|
||||
astilectron.onMessageOnce = true
|
||||
},
|
||||
send: function(message) {
|
||||
ipcRenderer.send('`+ consts.eventNames.ipcWindowMessage +`', {message: message, targetID: '`+ json.targetID +`'})
|
||||
callbacks: {},
|
||||
counters: {},
|
||||
registerCallback: function(k, e, c, n) {
|
||||
e.targetID = '`+ json.targetID +`';
|
||||
if (typeof c !== "undefined") {
|
||||
if (typeof astilectron.counters[k] === "undefined") {
|
||||
astilectron.counters[k] = 1;
|
||||
}
|
||||
e.callbackId = String(astilectron.counters[k]++);
|
||||
if (typeof astilectron.callbacks[k] === "undefined") {
|
||||
astilectron.callbacks[k] = {};
|
||||
}
|
||||
astilectron.callbacks[k][e.callbackId] = c;
|
||||
}
|
||||
ipcRenderer.send(n, e);
|
||||
},
|
||||
executeCallback: function(k, message, args) {
|
||||
if (typeof astilectron.callbacks[k][message.callbackId] !== "undefined") {
|
||||
astilectron.callbacks[k][message.callbackId].apply(null, args);
|
||||
}
|
||||
},
|
||||
sendMessage: function(message, callback) {
|
||||
astilectron.registerCallback('` + consts.callbackNames.webContentsMessage + `', {message: message}, callback, '`+ consts.eventNames.ipcEventMessage +`');
|
||||
},
|
||||
showErrorBox: function(title, content) {
|
||||
dialog.showErrorBox(title, content)
|
||||
|
@ -269,9 +492,56 @@ function windowCreate(json) {
|
|||
showSaveDialog: function(options, callback) {
|
||||
dialog.showSaveDialog(null, options, callback)
|
||||
}
|
||||
}
|
||||
};
|
||||
ipcRenderer.on('`+ consts.eventNames.ipcCmdMessageCallback +`', function(event, message) {
|
||||
astilectron.executeCallback('` + consts.callbackNames.webContentsMessage + `', message, [message.message]);
|
||||
});
|
||||
ipcRenderer.on('`+ consts.eventNames.ipcCmdLog+`', function(event, message) {
|
||||
console.log(message)
|
||||
});
|
||||
` + (typeof json.windowOptions.custom !== "undefined" && typeof json.windowOptions.custom.script !== "undefined" ? json.windowOptions.custom.script : "") + `
|
||||
document.dispatchEvent(new Event('astilectron-ready'))`
|
||||
)
|
||||
sessionCreate(elements[json.targetID].webContents, json.sessionId)
|
||||
client.write(json.targetID, consts.eventNames.windowEventDidFinishLoad)
|
||||
})
|
||||
elements[json.targetID].webContents.on('did-get-redirect-request', (event, oldUrl, newUrl) => {
|
||||
client.write(json.targetID, consts.eventNames.windowEventDidGetRedirectRequest, {
|
||||
newUrl: newUrl,
|
||||
oldUrl: oldUrl
|
||||
})
|
||||
})
|
||||
elements[json.targetID].webContents.on('login', (event, request, authInfo, callback) => {
|
||||
event.preventDefault();
|
||||
registerCallback(json, consts.callbackNames.webContentsLogin, {authInfo: authInfo, request: request}, consts.eventNames.webContentsEventLogin, callback);
|
||||
})
|
||||
elements[json.targetID].webContents.on('will-navigate', (event, url) => {
|
||||
client.write(json.targetID, consts.eventNames.windowEventWillNavigate, {
|
||||
url: url
|
||||
})
|
||||
})
|
||||
lastWindow = elements[json.targetID]
|
||||
}
|
||||
|
||||
function registerCallback(json, k, e, n, c) {
|
||||
if (typeof counters[k] === "undefined") {
|
||||
counters[k] = 1;
|
||||
}
|
||||
e.callbackId = String(counters[k]++);
|
||||
if (typeof callbacks[k] === "undefined") {
|
||||
callbacks[k] = {};
|
||||
}
|
||||
callbacks[k][e.callbackId] = c;
|
||||
client.write(json.targetID, n, e);
|
||||
}
|
||||
|
||||
function executeCallback(k, json, args) {
|
||||
if (typeof callbacks[k][json.callbackId] !== "undefined") {
|
||||
callbacks[k][json.callbackId].apply(null, args);
|
||||
}
|
||||
}
|
||||
|
||||
function sessionCreate(webContents, sessionId) {
|
||||
elements[sessionId] = webContents.session
|
||||
elements[sessionId].on('will-download', () => { client.write(sessionId, consts.eventNames.sessionEventWillDownload) })
|
||||
}
|
||||
|
|
|
@ -2,6 +2,6 @@
|
|||
"name": "Astilectron",
|
||||
"description": "Electron-based cross-language application framework",
|
||||
"devDependencies": {
|
||||
"electron": "1.6.5"
|
||||
"electron": "1.8.1"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,7 +7,7 @@ const url = require('url');
|
|||
class Client {
|
||||
// init initializes the Client
|
||||
init() {
|
||||
var u = url.parse("tcp://" + process.argv[2], false, false)
|
||||
let u = url.parse("tcp://" + process.argv[2], false, false)
|
||||
this.socket = new net.Socket()
|
||||
this.socket.connect(u.port, u.hostname, function() {});
|
||||
this.socket.on('close', function() {
|
||||
|
@ -18,8 +18,8 @@ class Client {
|
|||
|
||||
// write writes an event to the server
|
||||
write(targetID, eventName, payload) {
|
||||
var data = {name: eventName, targetID: targetID}
|
||||
if (typeof payload != "undefined") Object.assign(data, payload)
|
||||
let data = {name: eventName, targetID: targetID}
|
||||
if (typeof payload !== "undefined") Object.assign(data, payload)
|
||||
this.socket.write(JSON.stringify(data) + "\n")
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,12 +1,35 @@
|
|||
'use strict'
|
||||
|
||||
module.exports = {
|
||||
callbackNames: {
|
||||
webContentsLogin: "web.contents.login",
|
||||
webContentsMessage: "web.contents.message",
|
||||
},
|
||||
eventNames: {
|
||||
appCmdQuit: "app.cmd.quit",
|
||||
appEventReady: "app.event.ready",
|
||||
displayEventAdded: "display.event.added",
|
||||
displayEventMetricsChanged: "display.event.metrics.changed",
|
||||
displayEventRemoved: "display.event.removed",
|
||||
ipcWindowMessage: "ipc.window.message",
|
||||
dockCmdBounce: "dock.cmd.bounce",
|
||||
dockCmdBounceDownloads: "dock.cmd.bounce.downloads",
|
||||
dockCmdCancelBounce: "dock.cmd.cancel.bounce",
|
||||
dockCmdHide: "dock.cmd.hide",
|
||||
dockCmdSetBadge: "dock.cmd.set.badge",
|
||||
dockCmdSetIcon: "dock.cmd.set.icon",
|
||||
dockCmdShow: "dock.cmd.show",
|
||||
dockEventBadgeSet: "dock.event.badge.set",
|
||||
dockEventBouncing: "dock.event.bouncing",
|
||||
dockEventBouncingCancelled: "dock.event.bouncing.cancelled",
|
||||
dockEventDownloadsBouncing: "dock.event.download.bouncing",
|
||||
dockEventHidden: "dock.event.hidden",
|
||||
dockEventIconSet: "dock.event.icon.set",
|
||||
dockEventShown: "dock.event.shown",
|
||||
ipcCmdLog: "ipc.cmd.log",
|
||||
ipcCmdMessage: "ipc.cmd.message",
|
||||
ipcCmdMessageCallback: "ipc.cmd.message.callback",
|
||||
ipcEventMessage: "ipc.event.message",
|
||||
ipcEventMessageCallback: "ipc.event.message.callback",
|
||||
menuCmdCreate: "menu.cmd.create",
|
||||
menuCmdDestroy: "menu.cmd.destroy",
|
||||
menuEventCreated: "menu.event.created",
|
||||
|
@ -20,6 +43,17 @@ module.exports = {
|
|||
menuItemEventEnabledSet: "menu.item.event.enabled.set",
|
||||
menuItemEventLabelSet: "menu.item.event.label.set",
|
||||
menuItemEventVisibleSet: "menu.item.event.visible.set",
|
||||
notificationCmdCreate: "notification.cmd.create",
|
||||
notificationCmdShow: "notification.cmd.show",
|
||||
notificationEventActioned: "notification.event.actioned",
|
||||
notificationEventClicked: "notification.event.clicked",
|
||||
notificationEventClosed: "notification.event.closed",
|
||||
notificationEventCreated: "notification.event.created",
|
||||
notificationEventReplied: "notification.event.replied",
|
||||
notificationEventShown: "notification.event.shown",
|
||||
sessionCmdClearCache: "session.cmd.clear.cache",
|
||||
sessionEventClearedCache: "session.event.cleared.cache",
|
||||
sessionEventWillDownload: "session.event.will.download",
|
||||
subMenuCmdAppend: "sub.menu.cmd.append",
|
||||
subMenuCmdClosePopup: "sub.menu.cmd.close.popup",
|
||||
subMenuCmdInsert: "sub.menu.cmd.insert",
|
||||
|
@ -30,8 +64,15 @@ module.exports = {
|
|||
subMenuEventPoppedUp: "sub.menu.event.popped.up",
|
||||
trayCmdCreate: "tray.cmd.create",
|
||||
trayCmdDestroy: "tray.cmd.destroy",
|
||||
trayCmdSetImage: "tray.cmd.set.image",
|
||||
trayEventClicked: "tray.event.clicked",
|
||||
trayEventCreated: "tray.event.created",
|
||||
trayEventDestroyed: "tray.event.destroyed",
|
||||
trayEventDoubleClicked: "tray.event.double.clicked",
|
||||
trayEventImageSet: "tray.event.image.set",
|
||||
trayEventRightClicked: "tray.event.right.clicked",
|
||||
webContentsEventLogin: "web.contents.event.login",
|
||||
webContentsEventLoginCallback: "web.contents.event.login.callback",
|
||||
windowCmdBlur: "window.cmd.blur",
|
||||
windowCmdCenter: "window.cmd.center",
|
||||
windowCmdClose: "window.cmd.close",
|
||||
|
@ -39,8 +80,10 @@ module.exports = {
|
|||
windowCmdDestroy: "window.cmd.destroy",
|
||||
windowCmdFocus: "window.cmd.focus",
|
||||
windowCmdHide: "window.cmd.hide",
|
||||
windowCmdLog: "window.cmd.log",
|
||||
windowCmdMaximize: "window.cmd.maximize",
|
||||
windowCmdMessage: "window.cmd.message",
|
||||
windowCmdMessageCallback: "window.cmd.message.callback",
|
||||
windowCmdMinimize: "window.cmd.minimize",
|
||||
windowCmdMove: "window.cmd.move",
|
||||
windowCmdResize: "window.cmd.resize",
|
||||
|
@ -52,10 +95,13 @@ module.exports = {
|
|||
windowEventBlur: "window.event.blur",
|
||||
windowEventClosed: "window.event.closed",
|
||||
windowEventDidFinishLoad: "window.event.did.finish.load",
|
||||
windowEventDidGetRedirectRequest: "window.event.did.get.redirect.request",
|
||||
windowEventWillNavigate: "window.event.will.navigate",
|
||||
windowEventFocus: "window.event.focus",
|
||||
windowEventHide: "window.event.hide",
|
||||
windowEventMaximize: "window.event.maximize",
|
||||
windowEventMessage: "window.event.message",
|
||||
windowEventMessageCallback: "window.event.message.callback",
|
||||
windowEventMinimize: "window.event.minimize",
|
||||
windowEventMove: "window.event.move",
|
||||
windowEventReadyToShow: "window.event.ready.to.show",
|
||||
|
@ -63,7 +109,10 @@ module.exports = {
|
|||
windowEventRestore: "window.event.restore",
|
||||
windowEventShow: "window.event.show",
|
||||
windowEventUnmaximize: "window.event.unmaximize",
|
||||
windowEventUnresponsive: "window.event.unresponsive",
|
||||
windowEventUnresponsive: "window.event.unresponsive"
|
||||
},
|
||||
mainTargetID: 'main'
|
||||
targetIds: {
|
||||
app: 'app',
|
||||
dock: 'dock'
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1 +1 @@
|
|||
{"astilectron":{"version":"0.6.0"},"electron":{"version":"1.6.5"}}
|
||||
{"astilectron":{"version":"0.30.0"},"electron":{"linux-amd64":{"version":"4.0.1"},"version":{"version":""}}}
|
||||
|
|
Loading…
Reference in New Issue