Skip to content
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
10 changes: 10 additions & 0 deletions app/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,16 @@
</ul>
</div>

<div>
<!-- Used in Electron only -->
<button id="reloadGcodeBtnElectron19" class="ribbon-button" title="Reload the current GCODE file from disk" onclick="socket.emit('reloadFile')" disabled>
<span class="icon">
<i id="reloadIcon" class="fas fa-sync-alt fg-gray"></i>
</span>
<span class="caption">Reload<br>G-CODE</span>
</button>
</div>

<span class="title">File</span>
</div>

Expand Down
28 changes: 28 additions & 0 deletions app/js/filemanager.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
const { EventEmitter } = require('events');

class FileManager extends EventEmitter {
constructor() {
super();
this._lastFilePath = "";
}

get lastFilePath() {
return this._lastFilePath;
}

set lastFilePath(path) {
this._lastFilePath = path;
this.raiseLastFilePathChangedEvent();
}

clear(){
this._lastFilePath = "";
this.raiseLastFilePathChangedEvent();
}

raiseLastFilePathChangedEvent() {
this.emit('lastFilePathChangedEvent', this._lastFilePath);
}
}

module.exports = new FileManager();
2 changes: 2 additions & 0 deletions app/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,12 @@ $(document).ready(function() {
console.log("Native Dialog Button Enabled")
$("#openGcodeBtn").hide()
$("#openGcodeBtnElectron19").show()
$("#reloadGcodeBtnElectron19").show()
} else {
console.log("Native Dialog Button Disabled")
$("#openGcodeBtn").show()
$("#openGcodeBtnElectron19").hide()
$("#reloadGcodeBtnElectron19").hide()
}


Expand Down
16 changes: 15 additions & 1 deletion app/js/websocket.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,18 @@ function initSocket() {
}
})

socket.on('lastFilePathChangedEvent', function(data) {
console.log('File path changed:', data);

if (data.filePath) {
$("#reloadGcodeBtnElectron19").prop("disabled", false);
$("#reloadIcon").removeClass("fg-gray").addClass("fg-amber");
} else {
$("#reloadGcodeBtnElectron19").prop("disabled", true);
$("#reloadIcon").removeClass("fg-amber").addClass("fg-gray");
}
});

socket.on('gcodeupload', function(data) {
var icon = ''
var source = "api"
Expand All @@ -179,7 +191,9 @@ function initSocket() {
} else {
$('#gcodeeditortab').click()
}
jobNeedsHoming();
if(!data.isReload) { // on reload don't mention homing
jobNeedsHoming();
}
});

socket.on('gcodeupload', function(data) {
Expand Down
20 changes: 17 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,13 @@ config.posDecimals = process.env.DRO_DECIMALS || 3;
config.grblWaitTime = 0.5;


const fileManager = require('./app/js/fileManager');
fileManager.on('lastFilePathChangedEvent', function(filePath) {
io.sockets.emit('lastFilePathChangedEvent', {
filePath: filePath
});
});

var express = require("express");
var app = express();
var http = require("http").Server(app);
Expand Down Expand Up @@ -722,6 +729,11 @@ io.on("connection", function(socket) {
})
})

socket.on("reloadFile", function(data) {
var lastFilePath= fileManager.lastFilePath;
readFile(lastFilePath, true);
});

socket.on("openInterfaceDir", function(data) {
dialog.showOpenDialog(jogWindow, {
properties: ['openDirectory'],
Expand Down Expand Up @@ -2231,7 +2243,7 @@ io.on("connection", function(socket) {

});

function readFile(filePath) {
function readFile(filePath, isReload=false) {
if (filePath) {
if (filePath.length > 1) {
var filename = path.parse(filePath)
Expand All @@ -2245,9 +2257,11 @@ function readFile(filePath) {
'command': '',
'response': "ERROR: File Upload Failed"
}
fileManager.lastFilePath = "";
uploadedgcode = "";
}
if (data) {
fileManager.lastFilePath = filePath;
if (filePath.endsWith('.obc')) { // OpenBuildsCAM Workspace
uploadedworkspace = data;
const {
Expand All @@ -2257,8 +2271,8 @@ function readFile(filePath) {
} else { // GCODE
var payload = {
gcode: data,
filename: filename
}
filename: filename,
isReload: isReload, }
io.sockets.emit('gcodeupload', payload);
uploadedgcode = data;
return data
Expand Down