@@ -4,6 +4,9 @@ const ipc = require('electron').ipcMain;
44const path = require ( 'path' ) ;
55const util = require ( 'util' ) ;
66const exec = require ( 'child_process' ) . exec ;
7+
8+ // console.log('loading functions-rpc.js');
9+
710// const spawn = require('child_process').spawn;
811
912global . filename = undefined ;
@@ -165,6 +168,14 @@ function save(){
165168 mainWindow . webContents . send ( 'save' ) ;
166169}
167170
171+ function getCurrentWorkingFile ( callback ) {
172+ mainWindow . webContents . send ( 'currentWorkingFile' )
173+ ipc . once ( 'getCurrentWorkingFile' , function ( event , filename ) {
174+ // console.log(filename);
175+ callback ( filename ) ;
176+ } )
177+ }
178+
168179function copyTemplate ( filepath ) {
169180 // console.log(path.join(getUserDataPath(), 'templates', path.basename(filepath).split('.')[1] + '.template'));
170181 if ( fs . existsSync ( path . join ( getUserDataPath ( ) , 'templates' , path . basename ( filepath ) . split ( '.' ) [ 1 ] + '.template' ) ) ) {
@@ -373,7 +384,11 @@ function getUserDataPath(){
373384 "styleActiveLine" : true ,
374385 "tabSize" : 4 ,
375386 "indentUnit" : 4
376- }
387+ } ,
388+ "discord" :{
389+ "discord-rpc-enable" :false ,
390+ "discord-status" :"I am new to colon"
391+ }
377392 }
378393 settings_default = JSON . stringify ( settings_default , null , 2 ) ;
379394 if ( ! fs . existsSync ( path . join ( userDataPath , 'settings.json' ) ) ) {
@@ -403,6 +418,15 @@ ipc.on('saveEditorSettings', function(event, editor_settings){
403418 mainWindow . webContents . send ( 'editorSettingsSaved' ) ;
404419} )
405420
421+ ipc . on ( 'saveDiscordSettings' , function ( event , discord_settings ) {
422+ let settings_file = fs . readFileSync ( path . join ( getUserDataPath ( ) , 'settings.json' ) ) ;
423+ settings_file = JSON . parse ( settings_file ) ;
424+ settings_file . discord = discord_settings ;
425+ settings_file = JSON . stringify ( settings_file , null , 2 )
426+ fs . writeFileSync ( path . join ( getUserDataPath ( ) , 'settings.json' ) , settings_file ) ;
427+ mainWindow . webContents . send ( 'discordSettingsSaved' ) ;
428+ } )
429+
406430
407431function createTemplate ( file_ext ) {
408432 mainWindow . webContents . send ( 'openFile' , '' , path . join ( getUserDataPath ( ) , 'templates' , file_ext + '.template' ) ) ;
@@ -638,5 +662,6 @@ module.exports = {
638662 openAbout : openAbout ,
639663 createTemplate : createTemplate ,
640664 getUserDataPath : getUserDataPath ,
641- openTemplate : openTemplate
665+ openTemplate : openTemplate ,
666+ getCurrentWorkingFile : getCurrentWorkingFile
642667}
0 commit comments