Skip to content

Commit

Permalink
fixing #15; upgrading to electron 11
Browse files Browse the repository at this point in the history
  • Loading branch information
tnrich committed Jan 26, 2021
1 parent 59ae001 commit 75c1a8f
Show file tree
Hide file tree
Showing 6 changed files with 438 additions and 243 deletions.
21 changes: 18 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,33 @@ This packages the open-vector-editor web app as an electron tool that can be use
yarn
yarn start
```
## To speed up trying out changes from OVE
```
cd open-vector-editor;
yarn link;
cd ove-electron;
yarn link open-vector-editor
<!-- comment in these lines in open-vector-editor nwb.config.js to speed up the build -->
esModules: console.log("commentMeBackOut") || false,
cjs: console.log("commentMeBackOut") || false
cd open-vector-editor;
yarn build; //this will now build only the UMD file that ove-electron uses
```

# Releasing
1. Bump the package.json version number
2. Commit your changes
3. Build windows and mac
3. yarn generateChangelog
4. Build windows and mac
```
yarn deploy
```
wait for it to finish

4. Go to https://github.com/tnrich/ove-electron/releases
5. Edit the most recently pushed release to publish it
5. Go to https://github.com/tnrich/ove-electron/releases
6. Edit the most recently pushed release to publish it

How auto-updating works :
https://medium.com/@johndyer24/creating-and-deploying-an-auto-updating-electron-app-for-mac-and-windows-using-electron-builder-6a3982c0cee6
46 changes: 25 additions & 21 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const createMenu = require("./src/main_utils/menu");
const windowStateKeeper = require("electron-window-state");
const { autoUpdater } = require("electron-updater");

require("@electron/remote/main").initialize();
// ************************************************************************
// this function is super handy for debugging what is happening
// in the main process from the renderer process !!
Expand Down Expand Up @@ -36,7 +37,7 @@ function getSeqJsonFromPath(_filePath) {
//open, read, handle file
if (!data) return;
const fileName = filePath.replace(/^.*[\\/]/, "");
return bioParsers.anyToJson(data, { fileName }).then(res => {
return bioParsers.anyToJson(data, { fileName }).then((res) => {
return res[0].parsedSequence;
});
}
Expand All @@ -59,20 +60,23 @@ async function createWindow(windowVars, passedWindow) {

let mainWindowState = windowStateKeeper({
defaultWidth: 1000,
defaultHeight: 800
defaultHeight: 800,
});

let newWindow = passedWindow || new BrowserWindow({
x: mainWindowState.x,
y: mainWindowState.y,
width: mainWindowState.width,
height: mainWindowState.height,
show: false,
webPreferences: {
// nodeIntegration: true, //we don't want to enable this because it is a security risk and slows down the app
preload: path.join(__dirname, "src/preload.js")
}
});
let newWindow =
passedWindow ||
new BrowserWindow({
x: mainWindowState.x,
y: mainWindowState.y,
width: mainWindowState.width,
height: mainWindowState.height,
show: false,
webPreferences: {
enableRemoteModule: true,
// nodeIntegration: true, //we don't want to enable this because it is a security risk and slows down the app
preload: path.join(__dirname, "src/preload.js"),
},
});
console.log(`newWindow being created`);
newWindow.once("ready-to-show", () => {
newWindow.show();
Expand Down Expand Up @@ -101,7 +105,7 @@ async function createWindow(windowVars, passedWindow) {
console.error(`e123421231:`, e);
}
}
Object.keys(windowVars || startupWindowVars).forEach(k => {
Object.keys(windowVars || startupWindowVars).forEach((k) => {
newWindow[k] = (windowVars || startupWindowVars)[k];
});
// if (process.argv.length >= 2) {
Expand All @@ -117,7 +121,7 @@ async function createWindow(windowVars, passedWindow) {
// newWindow.

// Emitted when the window is closed.
newWindow.on("closed", function() {
newWindow.on("closed", function () {
// Dereference the window object, usually you would store windows
// in an array if your app supports multi windows, this is the time
// when you should delete the corresponding element.
Expand Down Expand Up @@ -163,7 +167,7 @@ app.on("open-file", async (event, path) => {
console.log(`open-file:`, path);
event.preventDefault();
try {
console.log("trying to open gb file")
console.log("trying to open gb file");
const initialSeqJson = await getSeqJsonFromPath(path);
createWindow({ initialSeqJson, filePath: path });
} catch (e) {
Expand All @@ -184,13 +188,13 @@ app.on("ready", () => {
});

// Quit when all windows are closed.
app.on("window-all-closed", function() {
app.on("window-all-closed", function () {
// On macOS it is common for applications and their menu bar
// to stay active until the user quits explicitly with Cmd + Q
if (process.platform !== "darwin") app.quit();
});

app.on("activate", function() {
app.on("activate", function () {
// On macOS it's common to re-create a window in the app when the
// dock icon is clicked and there are no other windows open.
if (!windows.length) {
Expand All @@ -202,7 +206,7 @@ app.on("activate", function() {
function sendStatusToWindow(type, message) {
let browserWindows = BrowserWindow.getAllWindows();
browserWindows &&
browserWindows.forEach(win => win.webContents.send(type, message));
browserWindows.forEach((win) => win.webContents.send(type, message));
}
autoUpdater.on("update-available", () => {
sendStatusToWindow("update_available");
Expand All @@ -216,10 +220,10 @@ autoUpdater.on("checking-for-update", () => {
// autoUpdater.on("update-not-available", info => {
// sendStatusToWindow("update-not-available");
// });
autoUpdater.on("error", err => {
autoUpdater.on("error", (err) => {
sendStatusToWindow("error", err);
});
autoUpdater.on("download-progress", progressObj => {
autoUpdater.on("download-progress", (progressObj) => {
let log_message =
"Download in progress: " + Math.round(progressObj.percent) + "%";
sendStatusToWindow("download-progress", log_message);
Expand Down
15 changes: 9 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ove-electron",
"version": "0.1.10",
"version": "1.0.0",
"description": "An open source vector/plasmid editor",
"main": "main.js",
"scripts": {
Expand All @@ -11,7 +11,8 @@
"deploy": "env-cmd electron-builder --mac --windows --linux --publish always",
"deploy-win": "env-cmd electron-builder --win --publish always",
"deploy-mac": "env-cmd electron-builder --mac --publish always",
"deploy-linux": "env-cmd electron-builder --linux --publish always"
"deploy-linux": "env-cmd electron-builder --linux --publish always",
"generateChangelog": "auto-changelog -p && git add CHANGELOG.md"
},
"build": {
"productName": "Open Vector Editor",
Expand Down Expand Up @@ -70,16 +71,18 @@
"author": "tnrich",
"license": "MIT",
"devDependencies": {
"electron": "^9.1.1",
"electron-builder": "^22.8.0",
"auto-changelog": "^2.2.1",
"electron": "^11.2.1",
"electron-builder": "^22.9.1",
"electron-notarize": "^1.0.0",
"env-cmd": "^10.1.0",
"eslint": "^6.8.0",
"eslint-config-teselagen": "^5.0.5"
},
"dependencies": {
"electron-updater": "^4.3.4",
"@electron/remote": "^1.0.2",
"electron-updater": "^4.3.5",
"electron-window-state": "^5.0.3",
"open-vector-editor": "^10.1.87"
"open-vector-editor": "^13.0.2"
}
}
9 changes: 5 additions & 4 deletions src/preload.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
const electron = require("electron");
const {jsonToGenbank} = require("bio-parsers");
const { dialog } = require('electron').remote

const currentWindow = electron.remote.getCurrentWindow();
const { dialog } = require('electron')
const { ipcRenderer } = require("electron");
const remote = require("@electron/remote");

const currentWindow = remote.getCurrentWindow();
console.log(`currentWindow:`,currentWindow)
Object.assign(window, {
currentWindow,
ipcRenderer,
Expand Down
37 changes: 32 additions & 5 deletions src/renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,25 @@ const seqDataToUse = currentWindow.initialSeqJson || { circular: true };
// export default generateSequenceData()
const originalTitle = document.title;

currentWindow.webContents.session.on('will-download', (event, downloadItem, webContents) => {


const fileName = window.dialog.showSaveDialogSync({
defaultPath: "ashdfasdfasdf",
filters: [
{ name: 'Excel', extensions: ['pdf'] }]
});

if (typeof fileName == "undefined") {
downloadItem.cancel()
}
else {
downloadItem.setSavePath(fileName);
}
event.stopPropagation()
event.preventDefault()
});

setNewTitle(seqDataToUse.name);

function setNewTitle(name) {
Expand All @@ -16,10 +35,17 @@ const handleSave = isSaveAs => (
onSuccessCallback
) => {
let newFilePath;
if (isSaveAs || !window.filePath) {
console.log(`window.filePath:`,window.filePath)

// if (true || isSaveAs || !window.filePath) {
//we need to get the newFilePath
const filename = `${sequenceDataToSave.name || "Untitled_Sequence"}.gb`;
newFilePath = window.dialog.showSaveDialogSync({
filters: [
{ name: 'Genbank', extensions: ['gb'] },
{ name: 'Fasta', extensions: ['fasta'] },
{ name: 'TeselaGen', extensions: ['json'] },
],
title: filename,
defaultPath:
(window.filePath
Expand Down Expand Up @@ -48,10 +74,11 @@ const handleSave = isSaveAs => (

window.filePath = newFilePath;

} else {
//normal save
newFilePath = window.filePath;
}
// }
// else {
// //normal save
// newFilePath = window.filePath;
// }
const formattedSeqString = window.jsonToGenbank(sequenceDataToSave);
window.ipcRenderer.send("ove_onSave", {
filePath: newFilePath,
Expand Down
Loading

0 comments on commit 75c1a8f

Please sign in to comment.