Skip to content

Commit

Permalink
Merge commit 'f7c6cc14592f6af21d8922ae7a477e871a88c91e' into release
Browse files Browse the repository at this point in the history
  • Loading branch information
davidjgraph committed Jun 18, 2023
2 parents 113a6f4 + f7c6cc1 commit 421d9d1
Show file tree
Hide file tree
Showing 7 changed files with 2,548 additions and 6 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "draw.io",
"version": "21.4.1",
"description": "draw.io desktop",
"main": "./drawio/src/main/webapp/electron.js",
"main": "src/main/electron.js",
"scripts": {
"start": "electron .",
"sync": "node ./sync.js",
Expand Down
6 changes: 6 additions & 0 deletions src/main/disableUpdate.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module.exports = {
disableUpdate: function()
{
return false;
}
}
79 changes: 79 additions & 0 deletions src/main/electron-preload.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
const {
contextBridge,
ipcRenderer
} = require("electron");

let reqId = 1;
let reqInfo = {};
let fileChangedListeners = {};

ipcRenderer.on('mainResp', (event, resp) =>
{
var callbacks = reqInfo[resp.reqId];

if (resp.error)
{
callbacks.error(resp.msg, resp.e);
}
else
{
callbacks.callback(resp.data);
}

delete reqInfo[resp.reqId];
});

ipcRenderer.on('fileChanged', (event, resp) =>
{
var listener = fileChangedListeners[resp.path];

if (listener)
{
listener(resp.curr, resp.prev);
}
});

contextBridge.exposeInMainWorld(
'electron', {
request: (msg, callback, error) =>
{
msg.reqId = reqId++;
reqInfo[msg.reqId] = {callback: callback, error: error};

//TODO Maybe a special function for this better than this hack?
//File watch special case where the callback is called multiple times
if (msg.action == 'watchFile')
{
fileChangedListeners[msg.path] = msg.listener;
delete msg.listener;
}

ipcRenderer.send('rendererReq', msg);
},
registerMsgListener: function(action, callback)
{
ipcRenderer.on(action, function(event, args)
{
callback(args);
});
},
sendMessage: function(action, args)
{
ipcRenderer.send(action, args);
},
listenOnce: function(action, callback)
{
ipcRenderer.once(action, function(event, args)
{
callback(args);
});
}
}
);

contextBridge.exposeInMainWorld(
'process', {
type: process.type,
versions: process.versions
}
);
Loading

0 comments on commit 421d9d1

Please sign in to comment.