Skip to content
This repository was archived by the owner on Feb 16, 2024. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 70 additions & 1 deletion main.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
'use strict'

const electron = require('electron')
const {app, BrowserWindow, ipcMain, Menu, MenuItem, Tray, dialog, Notification} = electron
const path = require('path')
const {app, BrowserWindow, ipcMain, Menu, MenuItem, Tray, dialog, Notification, protocol} = electron
const consts = require('./src/consts.js')
const client = require('./src/client.js').init()
const rl = require('readline').createInterface({input: client.socket})
Expand Down Expand Up @@ -86,6 +87,15 @@ app.on('ready',() => {
// App
case consts.eventNames.appCmdQuit:
app.quit();

case consts.eventNames.appCmdGetPath:
client.write(
consts.targetIds.app,
consts.eventNames.appEventGetPathResult,
{
pathName: (json.pathName) ? app.getPath(json.pathName) : ''
}
);
break;

// Dock
Expand Down Expand Up @@ -232,6 +242,12 @@ app.on('ready',() => {
executeCallback(consts.callbackNames.webContentsLogin, json, [json.username, json.password]);
break;

// Protocol
case consts.eventNames.protocolCmdRegisterAppProtocol:
registerAppProtocol(client, json)
break;


// Window
case consts.eventNames.windowCmdBlur:
elements[json.targetID].blur()
Expand Down Expand Up @@ -309,6 +325,11 @@ app.on('ready',() => {
})
});

app.on('open-url', function (event, url) {
event.preventDefault();
console.log('open-url event: ', url);
});

// menuCreate creates a new menu
function menuCreate(menu) {
if (typeof menu !== "undefined") {
Expand Down Expand Up @@ -553,3 +574,51 @@ function sessionCreate(webContents, sessionId) {
elements[sessionId] = webContents.session
elements[sessionId].on('will-download', () => { client.write(sessionId, consts.eventNames.sessionEventWillDownload) })
}

function registerAppProtocol(client, json) {

const scheme = 'com.logtransformer.app';

console.log('Registering app protocol "' + scheme +'"...');

const ret = app.setAsDefaultProtocolClient(scheme);
console.log('setAsDefaultProtocolClient() returned:: ', JSON.stringify(ret));

protocol.registerFileProtocol(scheme, (request, callback) => {
console.log('Received request to ' + scheme + ':: ', request.url);

// get value before "?" - for some reason electron cant
// find the file if ?search value is passed as part of the path.
const parts = request.url.split('?');

// string after "<scheme>:///""
// - 1 to account for 0-index
// + 3 to account for "://"
const url = parts[0].substr((scheme.length - 1) + 3);

const finalPath = path.normalize(`${json.filePath}/${url}`);

const navinfo = {
path: finalPath
};

client.write(
consts.targetIds.app,
consts.eventNames.registerAppProtocolCallback,
navinfo
);

callback(navinfo);

}, (error) => {

client.write(
consts.targetIds.app,
consts.eventNames.registerAppProtocolCompletion,
{
error: (error) ? error.message : '',
workingDir: json.filePath
}
);
});
}
5 changes: 5 additions & 0 deletions src/consts.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ module.exports = {
},
eventNames: {
appCmdQuit: "app.cmd.quit",
appCmdGetPath: "app.cmd.get.path",
appEventGetPathResult: "app.event.get.path.result",
appEventReady: "app.event.ready",
displayEventAdded: "display.event.added",
displayEventMetricsChanged: "display.event.metrics.changed",
Expand Down Expand Up @@ -51,6 +53,9 @@ module.exports = {
notificationEventCreated: "notification.event.created",
notificationEventReplied: "notification.event.replied",
notificationEventShown: "notification.event.shown",
protocolCmdRegisterAppProtocol: "protocol.cmd.register.app",
registerAppProtocolCallback: 'protocol.register.callback',
registerAppProtocolCompletion: 'protocol.event.register.completion',
sessionCmdClearCache: "session.cmd.clear.cache",
sessionEventClearedCache: "session.event.cleared.cache",
sessionEventWillDownload: "session.event.will.download",
Expand Down