Skip to content

Commit

Permalink
Prompt save file
Browse files Browse the repository at this point in the history
  • Loading branch information
MacaylaMarvelous81 committed Aug 20, 2024
1 parent dc06552 commit 95658b0
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 1 deletion.
11 changes: 10 additions & 1 deletion app.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import getPort, { portNumbers } from 'get-port';
import { WebSocketServer } from 'ws';
import { BrowserWindow, app, ipcMain } from 'electron';
import { BrowserWindow, app, ipcMain, dialog } from 'electron';
import path from 'node:path'
import { Client } from './websocket/client.js';
import fs from 'node:fs/promises';

const port = await getPort({
port: portNumbers(49152, 65535)
Expand Down Expand Up @@ -65,4 +66,12 @@ app.whenReady().then(() => {
});

ipcMain.handle('request-port', (event) => port);

ipcMain.handle('save-file-user', async (event, data) => {
const result = await dialog.showSaveDialog(window, {
title: 'Save To'
});

if (result.canceled) return;
});
});
4 changes: 4 additions & 0 deletions preload.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
const { contextBridge, ipcRenderer } = require('electron');

contextBridge.exposeInMainWorld('system', {
saveFileUser: (data) => ipcRenderer.invoke('save-file-user', data)
});

contextBridge.exposeInMainWorld('wsserver', {
getPort: () => ipcRenderer.invoke('request-port'),
onConnection: (callback) => ipcRenderer.on('connection', (event) => callback())
Expand Down
2 changes: 2 additions & 0 deletions wwwsrc/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
<div id="blockly"></div>
<div class="controls">
<button id="run-button">Connect!</button>
<button id="save-button">Save as</button>
<button id="open-button">Open</button>
</div>
</body>
</html>
8 changes: 8 additions & 0 deletions wwwsrc/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,14 @@ if (localStorage.getItem('workspace-default')) {
}
}

let dirty = false;

workspace.addChangeListener(Blockly.Events.disableOrphans);
workspace.addChangeListener((event) => {
if (event.isUiEvent) return;

localStorage.setItem('workspace-default', JSON.stringify(Blockly.serialization.workspaces.save(workspace)));
dirty = true;
});

const runButton = document.getElementById('run-button');
Expand Down Expand Up @@ -95,4 +98,9 @@ ${ genCode }\

interpreter.run(code);
});
});

const saveButton = document.getElementById('save-button');
saveButton.addEventListener('click', (event) => {
system.saveFileUser();
});

0 comments on commit 95658b0

Please sign in to comment.