Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Electron proof of concept #12

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
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
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
node_modules/
.idea
.idea
out/
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
FROM node:15-alpine AS base
WORKDIR /app
RUN apk add --no-cache git python3 build-base
COPY package*.json .
COPY package*.json ./

FROM base as prod_base
RUN npm ci --production
Expand Down
7 changes: 3 additions & 4 deletions boardCache.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,11 @@ module.exports = {
if (SS_PACK) {
return Promise.resolve();
}
return db(db =>
return db((db) =>
db
.collection("_whiteboards")
.find()
.toArray()
.then(res => res.forEach(this.createWhiteboard))
.toArray((err, res) => res && res.forEach(this.createWhiteboard))
);
},
createWhiteboard(whiteboard) {
Expand All @@ -27,5 +26,5 @@ module.exports = {
boards[whiteboard].owner &&
boards[whiteboard].owner !== req.session.userId
);
}
},
};
6 changes: 3 additions & 3 deletions client/code/app/mfs.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ window.toggleMFS = function(event) {
var old = localStorage.mfs && JSON.parse(localStorage.mfs) ||
{ id: getId(), flag: false };
old.flag = !old.flag;
var mfsActive = propagatingEventsToOtherViews = old.flag;
var mfsActive = window.propagatingEventsToOtherViews = old.flag;

if (mfsActive) {
old.mapCenter = map.center();
Expand Down Expand Up @@ -181,7 +181,7 @@ if (mfsb) {

var mfsInit = localStorage.mfs && JSON.parse(localStorage.mfs);

var mfsActive = propagatingEventsToOtherViews = mfsInit && mfsInit.flag;
var mfsActive = window.propagatingEventsToOtherViews = mfsInit && mfsInit.flag;

if (mfsActive) {
mfsb.innerText = "MFS is on";
Expand Down Expand Up @@ -239,7 +239,7 @@ function handle_storage(e) {
if (e.key === "mfs") {
if (v) {
window.mfs = v;
var mfsActive = propagatingEventsToOtherViews = v.flag;
var mfsActive = window.propagatingEventsToOtherViews = v.flag;
if (mfsActive) {
activateMfs(v);
mfsb.innerText = "MFS is on";
Expand Down
6 changes: 3 additions & 3 deletions client/code/app/paperTools.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ var tool;

var path;
var onMouseDowns = window.onMouseDowns = function(event, mfs) {
if (!mfs && propagatingEventsToOtherViews) {
if (!mfs && window.propagatingEventsToOtherViews) {
localStorage.setItem(
"storage-event-down",
JSON.stringify({
Expand Down Expand Up @@ -127,7 +127,7 @@ var tool;
mfs,
realTimeObject
) {
if (!mfs && propagatingEventsToOtherViews) {
if (!mfs && window.propagatingEventsToOtherViews) {
localStorage.setItem(
"storage-event-drag",
JSON.stringify({
Expand Down Expand Up @@ -174,7 +174,7 @@ var tool;
if (!paperItem) {
return;
}
if (!mfs && propagatingEventsToOtherViews) {
if (!mfs && window.propagatingEventsToOtherViews) {
localStorage.setItem(
"storage-event-up",
JSON.stringify({
Expand Down
18 changes: 9 additions & 9 deletions client/code/app/timeMachine.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ document.addEventListener("clearCanvas", function() {
function sortedIndex(arr, value) {
var count = arr.length;
var first = 0;

while (count > 0) {
var step = count >>> 1;
var it = first + step;
Expand Down Expand Up @@ -330,9 +330,9 @@ window.drawObject = function(iwb, reRender) {
}

var layer = project.activeLayer;

var index = sortedLastIndex(layer.children, paperItem);

layer.insertChild(index, paperItem);

setVisibility(iwb, window.timestamp || false);
Expand Down Expand Up @@ -389,7 +389,7 @@ var zProd = 1;
var xSum = 0;
var ySum = 0;
window.translateChildren = function(x, y, mfs, offset) {
if (!mfs && propagatingEventsToOtherViews) {
if (!mfs && window.propagatingEventsToOtherViews) {
localStorage.setItem(
"storage-event-translate",
JSON.stringify({ id: getId(), time: new Date(), x: x, y: y })
Expand All @@ -415,7 +415,7 @@ window.translateChildren = function(x, y, mfs, offset) {
};

window.zoomChildren = function(scale, x, y, mfs) {
if (!mfs && propagatingEventsToOtherViews) {
if (!mfs && window.propagatingEventsToOtherViews) {
localStorage.setItem(
"storage-event-zoom",
JSON.stringify({
Expand Down Expand Up @@ -584,7 +584,7 @@ window.timeAnimation = function(preserveUrl, skipTrigger) {
if (length) {
var next = sortedIndex(children, t);
var prev = length;

if (prevTime) {
if (prevTime <= t) {
prev = sortedIndex(children, prevTime);
Expand All @@ -593,10 +593,10 @@ window.timeAnimation = function(preserveUrl, skipTrigger) {
prev = sortedLastIndex(children, prevTime);
}
}

var min = Math.min(prev, next);
var max = Math.max(prev, next);

for (
var i = Math.max(0, min - 1), l = Math.min(max + 1, length - 1);
i <= l;
Expand All @@ -605,7 +605,7 @@ window.timeAnimation = function(preserveUrl, skipTrigger) {
setVisibility(children[i].iwb, t);
}
}

prevTime = t;

if (!skipTrigger) {
Expand Down
2 changes: 1 addition & 1 deletion client/code/app/toolbar/whiteboards.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ var sharedBoardsListContainer = document.getElementById(
var initChat = require("./chat");
var populateAcl = require("./acl");
var chatLogs = document.getElementById("chatLogs");
var re = /(@(?:[A-Za-z0-9\-._~!$&'()*+,;=:@]|%[0-9A-Fa-f]{2})+(?:\/))?((?:[A-Za-z0-9\-._~!$&'()*+,;=:@]|%[0-9A-Fa-f]{2})+)/;
var re = /(@(?:[A-Za-z0-9\-._~!$&'()*+,;=:@]|%[0-9A-Fa-f]{2})+(?:_))?((?:[A-Za-z0-9\-._~!$&'()*+,;=:@]|%[0-9A-Fa-f]{2})+)/;
window.updateWhiteboardLists = function updateWhiteboardLists() {
sharedBoardsListContainer.innerHTML = "";
privateBoardsContainer.innerHTML = "";
Expand Down
4 changes: 2 additions & 2 deletions client/code/libs/encoding.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
'use strict';

// If we're in node require encoding-indexes and attach it to the global.
if (typeof module !== "undefined" && module.exports &&
if (typeof module !== "undefined" && typeof window === 'undefined' && module.exports &&
!global["encoding-indexes"]) {
global["encoding-indexes"] =
require("./encoding-indexes.js")["encoding-indexes"];
Expand Down Expand Up @@ -3310,4 +3310,4 @@

// For strict environments where `this` inside the global scope
// is `undefined`, take a pure object instead
}(this || {}));
}(this || {}));
4 changes: 2 additions & 2 deletions client/code/libs/uuid.js
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@
if (_global.define && define.amd) {
// Publish as AMD module
define(function() {return uuid;});
} else if (typeof(module) != 'undefined' && module.exports) {
} else if (typeof(module) != 'undefined' && module.exports && typeof window === 'undefined') {
// Publish as node.js module
module.exports = uuid;
} else {
Expand All @@ -242,4 +242,4 @@

_global.uuid = uuid;
}
}).call(this);
}).call(this);
34 changes: 20 additions & 14 deletions config.js
Original file line number Diff line number Diff line change
@@ -1,32 +1,38 @@
const { connect } = require("mongodb").MongoClient;
const isElectron = process.versions["electron"];

const { NODE_ENV, MONGODB } = process.env;
const uri = MONGODB === "true" ? "mongodb://localhost:27017/iwb" : MONGODB;

const uri =
MONGODB ||
"mongodb://localhost:27017/iwb?authMechanism=DEFAULT&authSource=admin";
let tdb;
if (!uri) {
const path = `${
isElectron ? require("electron").app.getPath("userData") : "."
}/data`;
try {
require("fs").mkdirSync(path);
} catch (e) {
console.log(e);
}
tdb = Promise.resolve(new (require("tingodb")().Db)(path, {}));
}

module.exports = {
db(work, res) {
db(work) {
let db;
return connect(uri)
return (uri ? connect(uri) : tdb)
.then((dbRef) => {
db = dbRef;
return work(db);
})
.then((result) => {
res && res(null, result);
db && db.close();
db && db.close && db.close();
return result;
})
.catch((err) => {
console.log(err);
db && db.close();
if (res) {
res(err.message);
} else {
throw err;
}
db && db.close && db.close();
throw err;
});
},
};
Expand All @@ -40,7 +46,7 @@ if (NODE_ENV === "production") {
buffer.flush();
}, 5000);
} else {
require("./scripts/enable_slave_debug");
//require("./scripts/enable_slave_debug");
process.on("uncaughtException", (e) => {
console.log(e);
});
Expand Down
39 changes: 39 additions & 0 deletions main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
const { app, BrowserWindow } = require("electron");
//const getPort = require("get-port");
const boardCache = require("./boardCache.js");
const server = require("./server");
require("electron-window-manager");

let url;
function createWindow() {
const mainWindow = new BrowserWindow({
width: 1024,
height: 768,
webPreferences: {
nodeIntegration: true,
},
});
mainWindow.webContents.openDevTools();
mainWindow.loadURL(url);
}

app.on("ready", function () {
//getPort({ port: 3000 }).then((port) => {
const port = 3000;
url = "http://localhost:" + port;
boardCache
.init()
.then(() => server(0, port))
.then(() => createWindow());
//});
});

app.on("window-all-closed", function () {
if (process.platform !== "darwin") app.quit();
});

app.on("activate", () => {
if (BrowserWindow.getAllWindows().length === 0) {
createWindow();
}
});
Loading