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@19 #159

Closed
wants to merge 5 commits into from
Closed
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
64 changes: 36 additions & 28 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: build
on:
push:
# enable next line to limit branches to run
branches: [ "master" ]
branches: ["master"]
pull_request:
# enable next line to limit branches to run
# branches: [ "master" ]
Expand All @@ -12,32 +12,40 @@ jobs:
build:
strategy:
matrix:
node-version: [14.x, 16.x, 18.x, 20.x]
ShaMan123 marked this conversation as resolved.
Show resolved Hide resolved
os: [windows-2022, ubuntu-22.04]
node-version: [16.x, 18.x, 20.x]
os: [windows-2022, ubuntu-24.04]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v3
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

avoid changes like this. See, me currently close-to-sleep, superdizzy. Possibly an autoformatter did it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a git checkout action. I don't see a problem with the bump. If you insist I will downgrade

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a benefit (enhanced caching) of using newer versions:

Run actions/setup-node@v4
Found in cache @ /opt/hostedtoolcache/node/20.18.1/x6[4](https://github.com/deepnest-io/Deepnest/actions/runs/12189545706/job/34004910615?pr=159#step:4:4)
Environment details

with:
submodules: recursive

# not needed currently, but leaving here for future use
# - uses: actions/setup-python@v4
# with:
# python-version: '2.7.18'

- name: boost
if: startsWith(matrix.os,'ubuntu')
run: sudo apt-get update && sudo apt-get install -yq libboost-dev

- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}

- name: Build
run: |
npm install
npm run build
- name: Package
run: |
npm run dist
- uses: actions/checkout@v4
with:
submodules: recursive

# not needed currently, but leaving here for future use
# - uses: actions/setup-python@v4
# with:
# python-version: '2.7.18'

- name: boost
if: startsWith(matrix.os, 'ubuntu')
run: sudo apt-get update && sudo apt-get install -yq libboost-dev

- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}

- name: Build
run: |
npm ci
npm run build

- name: Package
run: |
npm run dist

- name: Upload
uses: actions/upload-artifact@v4
with:
name: dist-${{ matrix.os }}
path: dist/
retention-days: 1
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
/bin
/minkowski
/deepnest-*win32-x64
package-lock.json
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the same as your comment against using ubuntu-latest. Without package.json you are trusting the ci machine and npm/node to do an exact install of node modules without actually specifying that is what you want. Extremely undesirable. That is the whole reason of the cmd npm ci - install in accordance to lock file on ci.

git_token.rtf
.idea
*.zip
Expand Down
42 changes: 25 additions & 17 deletions main.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,13 @@
const electron = require('electron')
const { Menu, ipcMain } = electron
const { app, ipcMain, BrowserWindow, screen } = require('electron')
const fs = require('graceful-fs');
const path = require('path')
const os = require('os')
const url = require('url')

// Module to control application life.
const app = electron.app
require('@electron/remote/main').initialize()

app.commandLine.appendSwitch('--enable-precise-memory-info');

// Module to create native browser window.
const BrowserWindow = electron.BrowserWindow

const path = require('path')
const os = require('os')
const url = require('url')
/*
// main menu for mac
const template = [
Expand Down Expand Up @@ -83,7 +78,7 @@ if (!gotTheLock) {
function createMainWindow() {

// Create the browser window.
const {width, height} = electron.screen.getPrimaryDisplay().workAreaSize;
const {width, height} = screen.getPrimaryDisplay().workAreaSize;

var frameless = process.platform == 'darwin';
//var frameless = true;
Expand All @@ -96,10 +91,13 @@ function createMainWindow() {
webPreferences: {
contextIsolation: false,
enableRemoteModule: true,
nodeIntegration: true
nodeIntegration: true,
nativeWindowOpen: true
}
})

require('@electron/remote/main').enable(mainWindow.webContents)

// and load the index.html of the app.
mainWindow.loadURL(url.format({
pathname: path.join(__dirname, './main/index.html'),
Expand Down Expand Up @@ -142,9 +140,12 @@ function createBackgroundWindows() {
webPreferences: {
contextIsolation: false,
enableRemoteModule: true,
nodeIntegration: true
nodeIntegration: true,
nativeWindowOpen: true
}
});

require('@electron/remote/main').enable(back.webContents)

if (process.env["deepnest_debug"] === '1')
back.webContents.openDevTools();
Expand All @@ -169,8 +170,6 @@ function createBackgroundWindows() {
// initialization and is ready to create browser windows.
// Some APIs can only be used after this event occurs.
app.on('ready', () => {
// https://www.electronjs.org/docs/latest/breaking-changes#planned-breaking-api-changes-90
app.allowRendererProcessReuse = false;
createMainWindow();
mainWindow.once('ready-to-show', () => {
mainWindow.show();
Expand Down Expand Up @@ -256,6 +255,15 @@ ipcMain.on('background-stop', function(event){
console.log('stopped!', backgroundWindows);
});

// Backward compat with https://electron-settings.js.org/index.html#configure
const configPath = path.resolve(app.getPath('userData'), 'settings.json');
ipcMain.handle('read-config', () => {
return fs.existsSync(configPath) ? JSON.parse(fs.readFileSync(configPath).toString()) : {};
});
ipcMain.handle('write-config', (event, stringifiedConfig) => {
fs.writeFileSync(configPath, stringifiedConfig);
});

ipcMain.on('login-success', function(event, payload){
mainWindow.webContents.send('login-success', payload);
});
Expand All @@ -266,8 +274,8 @@ ipcMain.on('purchase-success', function(event){

ipcMain.on("setPlacements", (event, payload) => {
global.exportedPlacements = payload;
} );
});

ipcMain.on("test", (event, payload) => {
global.test = payload;
} );
});
16 changes: 5 additions & 11 deletions main/deepnest.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,9 @@
(function(root){
'use strict';

const { ipcRenderer } = require('electron');
const path = require('path')
const url = require('url')
root.DeepNest = new DeepNest(require('electron').ipcRenderer);

root.DeepNest = new DeepNest();

function DeepNest(){
var self = this;

function DeepNest(eventEmitter){
var svg = null;

var config = {
Expand Down Expand Up @@ -1021,8 +1015,8 @@
}
}

ipcRenderer.on('background-response', (event, payload) => {
ipcRenderer.send("setPlacements", payload);
eventEmitter.on('background-response', (event, payload) => {
eventEmitter.send("setPlacements", payload);
console.log('ipc response',payload);
if(!GA){
// user might have quit while we're away
Expand Down Expand Up @@ -1158,7 +1152,7 @@
filenames[j] = filename;
}

ipcRenderer.send('background-start', {index: i, sheets: sheets, sheetids: sheetids, sheetsources: sheetsources, sheetchildren: sheetchildren, individual: GA.population[i], config: config, ids: ids, sources: sources, children: children, filenames: filenames});
eventEmitter.send('background-start', {index: i, sheets: sheets, sheetids: sheetids, sheetsources: sheetsources, sheetchildren: sheetchildren, individual: GA.population[i], config: config, ids: ids, sources: sources, children: children, filenames: filenames});
running++;
}
}
Expand Down
62 changes: 30 additions & 32 deletions main/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,15 @@
}
}

const { ipcRenderer, remote } = require('electron');
const { ipcRenderer } = require('electron');
const remote = require('@electron/remote');
const { dialog } = remote;
const fs = require('graceful-fs');
const request = require('request');
const http = require('http');
const path = require('path');

ready(function(){
ready(async function(){
// main navigation
var tabs = document.querySelectorAll('#sidenav li');

Expand Down Expand Up @@ -66,8 +68,9 @@
});

// config form
const config = require('electron-settings');
window.config = config;


const defaultConversionServer = 'http://convert.deepnest.io';

var defaultconfig = {
units: 'inch',
Expand All @@ -85,18 +88,29 @@
dxfImportScale: "1",
dxfExportScale: "72",
endpointTolerance: 0.36,
conversionServer: 'http://convert.deepnest.io'
conversionServer: defaultConversionServer
};

//config.defaults(defaultconfig);

const defaultConversionServer = 'http://convert.deepnest.io';

// set to default if not set (for people with old configs stored)
for (var key in defaultconfig) {
if(typeof config.getSync(key) === 'undefined'){
config.setSync(key, defaultconfig[key]);
}

// Removed `electron-settings` while keeping the same interface to minimize changes
const config = window.config = {
...defaultconfig,
...(await ipcRenderer.invoke('read-config')),
getSync(k){
return typeof k==='undefined'? this: this[k];
},
setSync(arg0, v){
if(typeof arg0 === 'object') {
for (const key in arg0) {
this[key] = arg0[key];
}
} else if(typeof arg0 === 'string'){
this[arg0] = v;
}
ipcRenderer.invoke('write-config', JSON.stringify(this, null, 2));
},
resetToDefaultsSync(){
this.setSync(defaultconfig);
}
}

var cfgvalues = config.getSync();
Expand Down Expand Up @@ -559,9 +573,6 @@
}

// file import
var electron = require('electron');
var app = electron.remote;
var fs = require('fs');

var files = fs.readdirSync(remote.getGlobal('NEST_DIRECTORY'));
var svgs = files.map(file => file.includes('.svg') ? file : undefined).filter(file => file !== undefined).sort();
Expand All @@ -578,7 +589,6 @@

importbutton.className = 'button import disabled';

var dialog = app.dialog;
dialog.showOpenDialog({ filters: [

{ name: 'CAD formats', extensions: ['svg', 'dxf', 'cdr'] }
Expand Down Expand Up @@ -732,7 +742,7 @@
// add sheet
document.querySelector('#addsheet').onclick = function(){
var tools = document.querySelector('#partstools');
var dialog = document.querySelector('#sheetdialog');
// var dialog = document.querySelector('#sheetdialog');

tools.className = 'active';
};
Expand Down Expand Up @@ -800,7 +810,6 @@
nestwindow.setAlwaysOnTop(true);
nestwindow.open();*/

//const remote = require('electron').remote;

/*window.nestwindow = new BrowserWindow({width: window.outerWidth*0.8, height: window.outerHeight*0.8, frame: true});

Expand Down Expand Up @@ -904,7 +913,6 @@


for(var i=0; i<DeepNest.parts.length; i++){
console.log(DeepNest.parts);
if(DeepNest.parts[i].sheet){
// need at least one sheet
document.querySelector('#main').className = '';
Expand Down Expand Up @@ -1015,7 +1023,6 @@
var exportsvg = document.querySelector('#exportsvg');
exportsvg.onclick = function(){

var dialog = app.dialog;
var fileName = dialog.showSaveDialogSync({title: 'Export Deepnest SVG'});

if(fileName === undefined){
Expand Down Expand Up @@ -1043,9 +1050,6 @@

var exportdxf = document.querySelector('#exportdxf');
exportdxf.onclick = function(){
// var electron = require('electron');
// var app = electron.remote;
var dialog = app.dialog;
var fileName = dialog.showSaveDialogSync({
title: 'Export Deepnest DXF'
})
Expand Down Expand Up @@ -1101,7 +1105,6 @@
/*
var exportgcode = document.querySelector('#exportgcode');
exportgcode.onclick = function(){
var dialog = app.dialog;
dialog.showSaveDialog({title: 'Export Deepnest Gcode'}, function (fileName) {
if(fileName === undefined){
console.log("No file selected");
Expand Down Expand Up @@ -1472,11 +1475,6 @@
document.body.ondrop = (ev) => {
ev.preventDefault();
}

var windowManager = app.require('electron-window-manager');

const BrowserWindow = app.BrowserWindow;
const url = require('url');

window.loginWindow = null;
});
Expand Down
4 changes: 2 additions & 2 deletions main/svgparser.js
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@
var lastCommand = merged.pathSegList.getItem(merged.pathSegList.numberOfItems-1).pathSegTypeAsLetter;
if(lastCommand != 'z' && lastCommand != 'Z'){
// endpoints are actually far apart
console.log(merged);
// console.log(merged);
merged.pathSegList.appendItem(merged.createSVGPathSegClosePath());
}

Expand Down Expand Up @@ -544,7 +544,7 @@
else if(path.tagName == 'path'){
this.pathToAbsolute(path);
var split = this.splitPathSegments(path);
console.log(split);
// console.log(split);
split.forEach(function(e){
root.appendChild(e);
});
Expand Down
Loading
Loading