Skip to content

Commit

Permalink
Merge branch 'master' into i190
Browse files Browse the repository at this point in the history
  • Loading branch information
abebeos authored Dec 25, 2024
2 parents 57b6721 + 05df0bf commit aae125b
Show file tree
Hide file tree
Showing 8 changed files with 96 additions and 84 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
build:
strategy:
matrix:
node-version: [14.x, 16.x, 18.x, 20.x]
node-version: [16.x, 18.x, 20.x]
os: [windows-2022, ubuntu-22.04]
runs-on: ${{ matrix.os }}
steps:
Expand Down
3 changes: 3 additions & 0 deletions binding.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
'cflags!': [ '-fno-exceptions', "-m64" ],
"ldflags": [ "-m elf_i386" ],
'cflags_cc!': [ '-fno-exceptions', '-fPIC -m64' ],
"defines": [
"NOMINMAX"
],
}
],
[
Expand Down
43 changes: 26 additions & 17 deletions main.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
const electron = require('electron')
const { Menu, ipcMain } = electron
const { app, ipcMain, BrowserWindow, screen } = require('electron')
const remote = require('@electron/remote/main')
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
remote.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 +79,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 +92,13 @@ function createMainWindow() {
webPreferences: {
contextIsolation: false,
enableRemoteModule: true,
nodeIntegration: true
nodeIntegration: true,
nativeWindowOpen: true
}
})

remote.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 +141,12 @@ function createBackgroundWindows() {
webPreferences: {
contextIsolation: false,
enableRemoteModule: true,
nodeIntegration: true
nodeIntegration: true,
nativeWindowOpen: true
}
});

remote.enable(back.webContents)

if (process.env["deepnest_debug"] === '1')
back.webContents.openDevTools();
Expand All @@ -169,8 +171,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 +256,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 +275,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
78 changes: 43 additions & 35 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('@root/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,10 +589,11 @@

importbutton.className = 'button import disabled';

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

{ name: 'CAD formats', extensions: ['svg', 'dxf', 'cdr'] }
{ name: 'CAD formats', extensions: ['svg', 'dxf', 'cdr'] },
{ name: 'SVG', extensions: ['svg'] },
{ name: 'DXF', extensions: ['dxf'] }

],
properties:['openFile', 'multiSelections']
Expand Down Expand Up @@ -732,7 +744,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 +812,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 +915,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,8 +1025,12 @@
var exportsvg = document.querySelector('#exportsvg');
exportsvg.onclick = function(){

var dialog = app.dialog;
var fileName = dialog.showSaveDialogSync({title: 'Export Deepnest SVG'});
var fileName = dialog.showSaveDialogSync({
title: 'Export Deepnest SVG',
filters: [
{ name: 'SVG', extensions: ['svg'] }
]
});

if(fileName === undefined){
console.log("No file selected");
Expand All @@ -1043,11 +1057,11 @@

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'
title: 'Export Deepnest DXF',
filters: [
{ name: 'DXF', extensions: ['dxf'] }
]
})

if(fileName === undefined){
Expand Down Expand Up @@ -1101,7 +1115,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 +1485,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
15 changes: 8 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "deepnest",
"version": "1.2.0",
"version": "1.2.2",
"description": "Deep nesting for Laser and CNC",
"main": "main.js",
"license": "MIT",
Expand All @@ -11,7 +11,7 @@
"build": "mkdir minkowski >nul 2>&1|echo . >nul && mkdir minkowski/Release >nul 2>&1|echo . >nul && electron-rebuild && npm run copy",
"clean": "rmdir /s /q build dist >nul 2>&1|echo . >nul",
"clean-all": "rmdir /s /q build dist node_modules minkowski bin >nul 2>&1|echo . >nul",
"dist": "electron-packager . deepnest-v%npm_package_version% --overwrite",
"dist": "npx @electron/packager . deepnest-v$npm_package_version --overwrite",
"dist-all": "npm run clean-all && npm install && npm run build-all && npm run dist",
"copy": "shx cp -r ./build/Release ./minkowski"
},
Expand All @@ -27,14 +27,15 @@
"email": "[email protected]"
},
"devDependencies": {
"electron": "^13.0.0",
"electron-packager": "^17.1.1",
"@electron/packager": "^18.3.6",
"@electron/rebuild": "^3.2.9",
"@types/node": "^22.10.1",
"electron": "32.2.7",
"nan": "^2.20.0",
"shx": "^0.3.4"
},
"dependencies": {
"electron-settings": "^4.0.2",
"electron-window-manager": "^1.0.6",
"@electron/remote": "^2.1.2",
"graceful-fs": "^4.2.11",
"nan": "^2.17.0",
"@root/request": "^1.9.2"
Expand All @@ -52,4 +53,4 @@
"icon": "icon.ico"
}
}
}
}
Loading

0 comments on commit aae125b

Please sign in to comment.