Skip to content
This repository has been archived by the owner on Jul 5, 2022. It is now read-only.

Commit

Permalink
menu save,save as,load implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
dewiweb committed Jun 21, 2020
1 parent 0800ee3 commit a45c15c
Show file tree
Hide file tree
Showing 6 changed files with 380 additions and 30 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ Based on https://github.com/nrkno/tv-automation-emberplus-connection
"WORK-IN-PROGRESS!"
![Screenshot](MCxOSC_v0.0.4-alpha.png)
# ToDo
- [ ] Enable data persistency
- [X] Enable data persistency
- [ ] Enable frame free window
- [ ] Add Menu Bar
- [ ] Add Menu (Load,Save As,Save)
- [X] Add Menu Bar
- [X] Add Menu (Load,Save As,Save)
- [ ] Build for other platform
and much, much more...
32 changes: 23 additions & 9 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<html>
<head>
<meta charset="UTF-8">
<title>MCxOSC</title>
<title>MCxOSC - unsaved.session</title>
<script script type="text/javascript" src="renderer.js"></script>
<link rel="stylesheet" type="text/css" href="style.css">
<meta http-equiv="Content-Security-Policy" content="script-src 'self' 'unsafe-inline';" />
Expand All @@ -11,7 +11,13 @@
<div id="header" style="text-align: center;">
<img src="./assets/MxOSC-dark-bann.png" alt="" style=" max-width: 25%; height: auto;" class="center"/>
</div>


<div id="menu" class="center" style="font-weight: bold; padding-left: 2%;">Yes, You can &#8674; &ensp;
<button class="button loadBtn" id="loadBtn" onclick="load(this.id)">Load Session</button>
<button class="button saveAsBtn" id="saveAsBtn" onclick="saveAs(this.id)">Save Session as...</button>
<button class="button saveBtn" id="saveBtn" onclick="save(this.id)">Update Session</button>
</div>
<br>
<div id="Network_Settings">
<div class="form">
<form id="form1">
Expand Down Expand Up @@ -149,18 +155,21 @@
<th></th>
</tr>
<tr>
<td>Path</td>
<td>Value</td>
<td>&harr;</td>
<td>Value</td>
<td>Address</td>
<td>PATH</td>
<td class="little">Ember+Value</td>
<td class="little">Factor</td>
<td class="little">OSC value</td>
<td>ADDRESS</td>
<td></td>
<td>type</td>
<td>Min</td>
<td>Max</td>
<td class="hiddenTd"></td>
<td class="little">Min</td>
<td class="hiddenTd"></td>
<td class="little">Max</td>
</tr>

</table>

</div>

<script>
Expand All @@ -169,4 +178,9 @@
form5.addEventListener('submit', modifyOscAddr)
</script>
</body>
<footer class="little">
<p>path to actual file :
<span id="filepath"></span>
</p>
</footer>
</html>
74 changes: 72 additions & 2 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@ const nativeTheme = electron.nativeTheme;
nativeTheme.themeSource = 'dark';
const { app, BrowserWindow } = require('electron');
const mainFunctions = require('./mainFunctions');
//var remote = require('remote');
const {dialog} = require('electron')
const fs = require('fs');
const { openFile } = require('./mainFunctions');
const recOptions = {
defaultPath: app.getPath('documents') + '/MySession.session',
}


function createWindow () {
Expand All @@ -22,13 +29,71 @@ function createWindow () {
},
icon: `${__dirname}/assets/icons/64x64.png`
})

// et charger le fichier index.html de l'application.
win.loadFile('index.html')

// Ouvre les DevTools.
//win = null


//Menu//
ipcMain.on('sendSaveAs', function(event, content){
console.log(content);
//var content = JSON.stringify(content)
// var content = "Some text to save into the file";
filename = dialog.showSaveDialog(null, recOptions,{}
).then(result => {
filename = result.filePath;
if (filename === undefined) {
console.log('the user clicked the btn but didn\'t created a file');

}
fs.writeFile(filename, content, (err) => {
if (err) {
console.log('an error ocurred with file creation ' + err.message);
}
console.log('WE CREATED YOUR FILE SUCCESFULLY');
win.webContents.send('sendFilename', filename);
})
})
})

ipcMain.on('sendSave', function(event, content, rSfilename){
console.log("sendsave filepath", rSfilename);
console.log("sendsave content", content);

if (rSfilename === undefined) {
console.log('the user clicked the btn but didn\'t created a file');

}
fs.writeFile(rSfilename, content, (err) => {
if (err) {
console.log('an error ocurred with file creation ' + err.message);
}
console.log('WE CREATED YOUR FILE SUCCESFULLY');
//win.webContents.send('sendFilename', filename);
})
})

ipcMain.on('openFile', function (event) {
filename = dialog.showOpenDialog({properties: ['openFile', 'multiSelections']})
.then(result =>{
filename = result.filePaths;
console.log(filename);
const file = filename[0];
console.log(file);

const content = fs.readFileSync(file, 'utf-8');
console.log(content);
var sendedContent = JSON.stringify(content);
console.log('sendedContent:', sendedContent);
win.webContents.send("sendFileContent", sendedContent)
win.webContents.send('sendFilename', file)
})
})
////////////////////////

//Setup du port UDP de reception OSC
ipcMain.on('sendUDPport', function(event, oUDPport) {
console.log('Port de reception OSC:', oUDPport);
Expand Down Expand Up @@ -142,11 +207,16 @@ function createWindow () {

})
})
// win.setAutoHideMenuBar(true)
win.autoHideMenuBar = "true"
win.menuBarVisible = "false"
win.w
//end of create window
}


app.whenReady().then(createWindow)

//console.log('voilà cest pret')
// Quitter si toutes les fenêtres ont été fermées.
app.on('window-all-closed', () => {
Expand Down
5 changes: 5 additions & 0 deletions mainFunctions.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
const {dialog} = require('electron');
const fs = require('fs');

function oscToEmber(oscBundle) {
let oscArgs = JSON.stringify(oscBundle.args);
oscArgs = oscArgs.replace(/\s|\[|\]/g,"");
Expand Down Expand Up @@ -32,4 +35,6 @@ function addressToPath (address){
return path
}



module.exports = { oscToEmber, embChPath, embFadLevPath, pathToAddress, addressToPath }
Loading

0 comments on commit a45c15c

Please sign in to comment.