Step
diff --git a/electron.js b/electron.js
index 57c7f7de..ed4f23e1 100644
--- a/electron.js
+++ b/electron.js
@@ -24,33 +24,44 @@ function showError(msg, detail) {
// file watcher
class Workspace {
- constructor(directory, meta, wnd) {
+ constructor(directory, meta) {
this.directory = directory;
this.mainfile = meta.mainfile;
this.platform = meta.platform;
if (!this.mainfile) throw new Error(`The "mainfile" key is missing in ${WSMETA_FILENAME}.`)
if (!this.platform) throw new Error(`The "platform" key is missing in ${WSMETA_FILENAME}.`)
- var mainfilepath = modpath.join(directory, this.mainfile);
+ var mainfilepath = this.getMainFilePath();
if (!fs.existsSync(mainfilepath)) throw new Error(`The file "${mainfilepath}" is missing.`);
- this.watcher = chokidar.watch(mainfilepath);
+ console.log("workspace opened", this.directory, this.mainfile);
+ }
+ getMainFilePath() {
+ return modpath.join(this.directory, this.mainfile);
+ }
+ close() {
+ this.unwatch();
+ console.log("workspace closed", this.directory, this.mainfile);
+ }
+ watch(wnd) {
+ this.watcher = chokidar.watch(this.directory, {
+ awaitWriteFinish: false
+ });
this.watcher.on('all', (event, path) => {
- console.log(event, path);
switch (event) {
- case 'add':
case 'change':
+ console.log(event, path);
wnd.webContents.send('fileChanged', {
path: modpath.relative(this.directory, path),
});
break;
}
});
- console.log("workspace opened", this.directory, this.mainfile);
+ console.log("watching workspace");
}
- close() {
+ unwatch() {
if (this.watcher) {
this.watcher.close();
this.watcher = null;
- console.log("workspace closed", this.directory, this.mainfile);
+ console.log("un-watching workspace");
}
}
}
@@ -105,6 +116,11 @@ function openWorkspace(wnd, ws) {
});
}
+function getActiveWorkspace() {
+ var wnd = BrowserWindow.getFocusedWindow();
+ return wnd && wnd.workspace;
+}
+
// TODO: doesn't work if browser window reloads itself
function reloadCurrentWindow() {
var wnd = BrowserWindow.getFocusedWindow();
@@ -167,7 +183,7 @@ function openWorkspaceWindow(wspath) {
}
} else {
console.log(meta);
- var ws = new Workspace(wspath, meta, wnd);
+ var ws = new Workspace(wspath, meta);
openWorkspace(wnd, ws);
app.addRecentDocument(wspath);
}
@@ -228,7 +244,7 @@ function buildMenu() {
submenu: [
{
label: 'New Playground',
- click: openDefaultWorkspace,
+ click: createWindow,
accelerator: 'CmdOrCtrl+N',
},
{
@@ -395,6 +411,16 @@ app.on('activate', () => {
}
})
+app.on('browser-window-focus', (e) => {
+ var ws = e.sender.workspace;
+ if (ws) ws.unwatch();
+})
+
+app.on('browser-window-blur', (e) => {
+ var ws = e.sender.workspace;
+ if (ws) ws.watch(e.sender);
+})
+
app.on('open-file', (event, path) => {
openWorkspaceWindow(path);
})
diff --git a/index.html b/index.html
index de9a1934..d53ce5ce 100644
--- a/index.html
+++ b/index.html
@@ -309,7 +309,7 @@ if (window.location.host.endsWith('8bitworkshop.com')) {
-
+
-
+
Step
diff --git a/meta/electron.diff b/meta/electron.diff
index 6ffdc7d5..556216d3 100644
--- a/meta/electron.diff
+++ b/meta/electron.diff
@@ -1,5 +1,5 @@
---- index.html 2020-08-29 13:22:47.000000000 -0500
-+++ electron.html 2020-08-29 13:22:40.000000000 -0500
+--- index.html 2020-08-29 17:52:46.000000000 -0500
++++ electron.html 2020-08-29 17:54:08.000000000 -0500
@@ -3,18 +3,7 @@
@@ -193,7 +193,7 @@
8bitworkshop
-@@ -479,73 +367,6 @@
+@@ -478,73 +366,6 @@
diff --git a/src/ide/project.ts b/src/ide/project.ts
index 36b79b7e..b97401ae 100644
--- a/src/ide/project.ts
+++ b/src/ide/project.ts
@@ -298,6 +298,7 @@ export class CodeProject {
}
updateFile(path:string, text:FileData) {
+ if (this.filedata[path] == text) return; // unchanged, don't update
this.updateFileInStore(path, text); // TODO: isBinary
this.filedata[path] = text;
if (this.okToSend() && this.mainPath) {
diff --git a/src/ide/ui.ts b/src/ide/ui.ts
index 27423a81..1a1431e4 100644
--- a/src/ide/ui.ts
+++ b/src/ide/ui.ts
@@ -2280,8 +2280,11 @@ export function getElectronFile(url:string, success:(text:string|Uint8Array)=>vo
}
}
export function reloadWorkspaceFile(path: string) {
- var datatype = typeof current_project.filedata[path] == 'string' ? 'text' : 'arraybuffer';
- projectWindows.updateFile(path, getWorkspaceFile(path, datatype));
+ var oldval = current_project.filedata[path];
+ if (oldval != null) {
+ var datatype = typeof oldval == 'string' ? 'text' : 'arraybuffer';
+ projectWindows.updateFile(path, getWorkspaceFile(path, datatype));
+ }
}
function writeOutputROMFile() {
if (isElectronWorkspace && current_output instanceof Uint8Array) {
diff --git a/src/ide/views.ts b/src/ide/views.ts
index 7424e08b..fef939a8 100644
--- a/src/ide/views.ts
+++ b/src/ide/views.ts
@@ -183,11 +183,14 @@ export class SourceEditor implements ProjectView {
var i,j;
var oldtext = this.editor.getValue();
if (oldtext != text) {
+ this.editor.setValue(text);
+ /*
// find minimum range to undo
for (i=0; i
ProjectView;