From 2fb008d19969aed88841e5c9e46e32ce8fb6b0d2 Mon Sep 17 00:00:00 2001
From: Chhekur <820121223505e@gmail.com>
Date: Fri, 8 Mar 2019 22:06:34 +0530
Subject: [PATCH] fixed: remember only one unsaved file & add: remember your
last working project & fixed: auto close when all files are closed & fixed:
auto focus when create new file
---
CHANGELOG.md | 6 +-
assets/js/code_sharing.js | 118 ++++++++++++++++
assets/js/editor.js | 274 ++++++--------------------------------
assets/js/last_session.js | 123 +++++++++++++++++
main.js | 2 +-
menu/functions.js | 42 ++++--
package-lock.json | 2 +-
views/editor.html | 4 +-
8 files changed, 319 insertions(+), 252 deletions(-)
create mode 100644 assets/js/code_sharing.js
create mode 100644 assets/js/last_session.js
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 4842599..793c26d 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,3 +1,5 @@
## Changelog
-- Fixed: Now you can stop running process, in case you run infinite process
-- Improved: Buffer size increased
\ No newline at end of file
+- Fixed: Colon only able to remember one unsaved file
+- Add: Colon remember you last working project
+- Fixed: Auto close when all tabs are closed
+- Fixed: Editor will auto focus when you create a new file
\ No newline at end of file
diff --git a/assets/js/code_sharing.js b/assets/js/code_sharing.js
new file mode 100644
index 0000000..5853a98
--- /dev/null
+++ b/assets/js/code_sharing.js
@@ -0,0 +1,118 @@
+var server = require('http').createServer();
+var io = require('socket.io')(server);
+var localtunnel = require('localtunnel');
+const io_client = require('socket.io-client');
+var socket;
+var clients = [];
+
+function shareCode(){
+ if(isCurrentFileSaved()){
+ $('#code-sharing-box').html('
Waiting... ');
+ server.listen(4000, function(){
+ // console.log('listening at 4000');
+ var tunnel = localtunnel(4000, function(err, tunnel) {
+ if (err) {
+ // console.log(err);
+ $('#code-sharing-box').html(err);
+ }
+
+ // the assigned public url for your tunnel
+ // i.e. https://abcdefgjhij.localtunnel.me
+ $('#code-sharing-box').html('Share this url with whome you want to share ');
+ $('#code-sharing-box').append('' + tunnel.url + ' ');
+ $('#code-sharing-box').append('Commit Changes ');
+ $('#code-sharing-box').append('Disconnect ');
+ // console.log(tunnel.url);
+ });
+ tunnel.on('error', function(err) {
+ $('#code-sharing-box').html(err);
+ });
+ });
+ // console.log(file);
+ io.on('connection', function (socket) {
+ clients.push(socket);
+ socket.emit('file', { id: file.id, name:file.name, remote_path:file.path, data:file.editor.getValue() });
+ socket.on('commit-changes', function (data) {
+ // console.log('hello');
+ if(file.id == data.id && file.path == data.path){
+ file.editor.setValue(data.data);
+ editor.setValue(data.data);
+ }
+ files['#' + data.id].editor.setValue(data.data);
+ });
+ });
+ }
+}
+
+function connect(flag){
+ if(!flag){
+ $('#code-sharing-box').html(' Connect ');
+ }else{
+ let url = $('#url').val();
+ $('#code-sharing-box').html('Waiting... ');
+ socket = io_client(url);
+ socket.on('file', function (data) {
+ remoteFile = data;
+ // newFileCount++;
+ // newTab(undefined, newFileCount, path.basename(data.remote_path), data.data);
+ openFile(data.data, undefined, data.name, data.remote_path);
+ // console.log(data);
+ // socket.emit('my other event', { my: 'data' });
+ $('#code-sharing-box').html('Commit Changes ');
+ $('#code-sharing-box').append('Close Connection ');
+ });
+ socket.on('commit-changes', function(data){
+ // console.log('data recieved');
+ // console.log(file.remote_path, remoteFile.remote_path);
+ if(file.remote_path == remoteFile.remote_path){
+ file.editor.setValue(data.data);
+ editor.setValue(data.data);
+ // console.log('if executed');
+ }
+ // console.log('after if');
+ for(let i = 0; i < files.length; i++){
+ if(files[i].remote_path == remoteFile.remote_path){
+ // console.log('file found');
+ files[i].editor.setValue(data.data);
+ }
+ }
+ });
+ socket.on('error', function(error){
+ $('#code-sharing-box').html(error);
+ });
+ }
+}
+
+function commitChangesSender(){
+ for(let i = 0; i < clients.length; i++){
+ clients[i].emit('commit-changes', {id:file.id, name:file.name, path:file.path, data:file.editor.getValue()});
+ }
+}
+
+function commitChanges(){
+ socket.emit('commit-changes', {id:remoteFile.id, name:remoteFile.name, path:remoteFile.remote_path, data:file.editor.getValue()});
+}
+
+function backAllButtons(){
+ $('#code-sharing-box').html('Share Code Connect ');
+}
+
+function closeSocket(){
+ socket.destroy();
+ backAllButtons();
+}
+
+function disconnect(){
+ server.close();
+ backAllButtons();
+}
+
+module.exports = {
+ shareCode : shareCode,
+ connect : connect,
+ commitChangesSender : commitChangesSender,
+ commitChanges : commitChanges,
+ backAllButtons : backAllButtons,
+ closeSocket : closeSocket,
+ disconnect : disconnect
+}
\ No newline at end of file
diff --git a/assets/js/editor.js b/assets/js/editor.js
index d072c78..d9b565d 100644
--- a/assets/js/editor.js
+++ b/assets/js/editor.js
@@ -1,10 +1,5 @@
-var app = require('http').createServer();
-var io = require('socket.io')(app);
-var localtunnel = require('localtunnel');
-const io_client = require('socket.io-client');
-var socket;
-var clients = [];
-// var socket = require('socket.io-client');
+const code_sharing = require('../assets/js/code_sharing.js');
+const last_session = require('../assets/js/last_session.js');
const ipc = require('electron').ipcRenderer;
const {dialog} = require('electron').remote;
@@ -83,39 +78,10 @@ CodeMirror.modeURL = "../src/editor/mode/%N/%N.js";
// var editor = "";
// var file = "";
var editor;
-// checking is last session already there ?
-// console.log(getUserDataPath());
-let last_session = fs.readFileSync(path.join(getUserDataPath(), '/last_session/info.json'));
-last_session = JSON.parse(last_session);
-// console.log(last_session,Object.keys(last_session).length);
-if(Object.keys(last_session).length > 0){
- fs.writeFileSync(path.join(getUserDataPath() , '/last_session/info.json'), '{}');
- for (let i in last_session){
- // console.log('i - ', i);
- let data = fs.readFileSync(path.join(getUserDataPath(), last_session[i].current_path), 'utf-8');
- openFile(data, last_session[i].original_path);
- // console.log('file_id - ', '#' + file.id);
- // console.log('#' + file.id, i);
- if('#' + file.id != i){
- fs.unlinkSync(path.join(getUserDataPath(), last_session[i].current_path));
- // let temp_last_session = fs.readFileSync(path.join(getUserDataPath() , '/last_session/info.json'));
- // temp_last_session = JSON.parse(temp_last_session);
- // delete temp_last_session[i];
- // temp_last_session = JSON.stringify(temp_last_session, null, 2);
- }
- }
- // for(i in last_session){
- // let data = fs.readFileSync(path.join(getUserDataPath(), last_session[i].current_path), 'utf-8');
- // openFile(data, last_session[i].original_path);
- // }
- // fs.writeFileSync('last_session/info.json','{}');
-}else{
- newFile();
- // editor = newTab(undefined , newFileCount , 'untitled', '');
- // var file = files['#new' + newFileCount];
- // $('#filename_new1').click();
-}
+// checking is last session already there ?
+last_session.checkLastSessionProjectAndOpen()
+last_session.checkLastSessionFilesAndOpen();
// checking is last session already there end here
@@ -150,7 +116,7 @@ function newTab(filepath, filecount ,filename, data, remote_path){
// file_id = filepath;
// }
$('#code_mirror_editors').append('' + filename + ' ');
- $('#editors').append('
');
+ $('#editors').append('
');
let temp = initEditor(document.getElementById('file_' + file_id));
temp.setValue(data);
chagneEditorMode(filename,temp);
@@ -165,11 +131,7 @@ function newTab(filepath, filecount ,filename, data, remote_path){
editor: temp
}
temp.on("change", function() {
- let last_session = fs.readFileSync(path.join(getUserDataPath(), '/last_session/info.json'));
- last_session = JSON.parse(last_session);
- fs.writeFile(path.join(getUserDataPath(), last_session['#' + file.id].current_path), editor.getValue(), function(error){
- if(error) throw error;
- });
+ last_session.changeLastSessionFilesContent(file.id, editor.getValue());
closeToDot();
// // clearTimeout(delay);
// updateHtmlPreview();
@@ -235,7 +197,7 @@ ipc.on('themeChanged', function(event){
function isFileAlreadyOpened(filepath){
for(i in files){
- if(files[i].path == filepath) return true;
+ if(files[i].path == filepath && filepath != undefined) return true;
}
return false;
}
@@ -266,19 +228,8 @@ function openFile(data, filepath, filename, remote_path){
//last session
- let last_session = fs.readFileSync(path.join(getUserDataPath(), '/last_session/info.json'));
- last_session = JSON.parse(last_session);
- // console.log(last_session);
- last_session['#new' + newFileCount] = {
- original_path : filepath,
- current_path : path.join('last_session','#new' + newFileCount)
- }
- fs.writeFile(path.join(getUserDataPath(), last_session['#new' + newFileCount].current_path), data, function(error){
- if(error) throw error;
- });
- last_session = JSON.stringify(last_session, null, 2);
- fs.writeFileSync(path.join(getUserDataPath(), '/last_session/info.json'),last_session);
-
+ last_session.makeNewLastSessionFile(newFileCount, filepath, data);
+
// last session end here
$('#filename_new'+newFileCount).click();
@@ -325,17 +276,7 @@ function closeCurrentFile(file){
// delete file from last session
- let last_session = fs.readFileSync(path.join(getUserDataPath(), '/last_session/info.json'));
- last_session = JSON.parse(last_session);
- if(last_session['#new' + filecount]){
- fs.unlinkSync(path.join(getUserDataPath(), last_session['#new' + filecount].current_path));
- }
- // fs.unlinkSync(path.join(__dirname, '..', last_session['#new' + filecount].current_path), function(error){
- // if(error) throw error;
- // });
- delete last_session['#new' + filecount];
- last_session = JSON.stringify(last_session, null, 2);
- fs.writeFileSync(path.join(getUserDataPath(), '/last_session/info.json'), last_session);
+ last_session.deleteLastSessionFile(file.id);
// delete file from last session end here
@@ -352,8 +293,14 @@ function closeCurrentFile(file){
// console.log($('#filename_' + nextFile.split('#')[1]).parent());
$('#filename_' + nextFile.split('#')[1]).click();
}else{
-
- ipc.send('close-app');
+ // console.log(files['#' + file.id].filepath, files);
+ if(files['#' + file.id].path != undefined){
+ $('#file_tab_' + file.id).remove();
+ $('#'+ file.id).remove();
+ delete files['#'+file.id];
+ newFile();
+ }
+ // ipc.send('close-app');
}
// console.log(files.hasOwnProperty(nextFile));
}
@@ -379,14 +326,21 @@ function pathToId(filepath){
// open folder
-ipc.on('openFolder', function(event,structure){
- let response = '' + structure.name + ' ';
- response += makeDirectoryTree(structure.children);
- response += ' ';
+
+function openFolder(structure){
+
+ let response = '' + structure.name + ' ';
$('#project-structure').html(response);
// console.log($('#project-structure'));
$(".file-tree").filetree();
openProjectStructure(true);
+
+ last_session.openLastSessionFolders();
+ last_session.newLastSessionForProject(structure.path);
+}
+
+ipc.on('openFolder', function(event,structure){
+ openFolder(structure);
});
// create directory for specific Dirpath
@@ -402,6 +356,7 @@ function createDirectoryForSpecificDirpath(folder){
}
ipc.on('getDirectroyForSpecificDirpath', function(event, structure){
+ console.log('open')
// console.log(structure);
// console.log(structure.path);
// console.log(makeDirectoryTree(structure.children));
@@ -410,6 +365,8 @@ ipc.on('getDirectroyForSpecificDirpath', function(event, structure){
$('#' + pathToId(structure.path)).html(makeDirectoryTree(structure.children));
$('#' + pathToId(structure.path)).filetree();
+ last_session.updateOpenFolderInProjectInfo(pathToId(structure.path));
+
});
// create tree structure for opened folder
@@ -447,20 +404,7 @@ function newFile(){
// new file entry in last session
- let last_session = fs.readFileSync(path.join(getUserDataPath(), '/last_session/info.json'));
- last_session = JSON.parse(last_session);
- last_session['#new' + newFileCount] = {
- original_path : undefined,
- current_path : path.join('last_session','#new' + newFileCount)
- }
- fs.writeFile(path.join(getUserDataPath(), last_session['#new' + newFileCount].current_path), '', function(error){
- if(error) {
- console.log(error);
- throw error;
- }
- });
- last_session = JSON.stringify(last_session, null, 2);
- fs.writeFileSync(path.join(getUserDataPath(), 'last_session/info.json'), last_session);
+ last_session.makeNewLastSessionFile(newFileCount, undefined, '');
// new file entry in last session end here
@@ -479,12 +423,7 @@ ipc.on('saveAs', function(event){
// update file in last session
- let last_session = fs.readFileSync(path.join(getUserDataPath(), '/last_session/info.json'));
- last_session = JSON.parse(last_session);
- // console.log(file);
- fs.writeFile(path.join(getUserDataPath(), last_session['#' + file.id].current_path), data, function(error){
- if(error) throw error;
- });
+ last_session.changeLastSessionFilesContent(file.id, data);
//update file in last session end here
ipc.send('saveAs-data', data);
@@ -498,12 +437,7 @@ ipc.on('save', function(event){
// update file in last session
- let last_session = fs.readFileSync(path.join(getUserDataPath(), '/last_session/info.json'));
- last_session = JSON.parse(last_session);
- // console.log(file);
- fs.writeFile(path.join(getUserDataPath(), last_session['#' + file.id].current_path), data, function(error){
- if(error) throw error;
- });
+ last_session.changeLastSessionFilesContent(file.id, data);
//update file in last session end here
@@ -522,11 +456,7 @@ ipc.on('data-saved',function(event,filepath, data){
// update original path of file in last session
- let last_session = fs.readFileSync(path.join(getUserDataPath(), '/last_session/info.json'));
- last_session = JSON.parse(last_session);
- last_session['#' + file.id].original_path = file.path;
- last_session = JSON.stringify(last_session, null, 2);
- fs.writeFileSync(path.join(getUserDataPath(), 'last_session/info.json'), last_session);
+ last_session.updateLastSessionFilePath(file.id, file.path);
// update original path of file in last session end here
@@ -931,112 +861,6 @@ function isCurrentFileSaved(){
else return false;
}
-// code sharing function
-
-function shareCode(){
- if(isCurrentFileSaved()){
- $('#code-sharing-box').html('Waiting... ');
- app.listen(4000, function(){
- // console.log('listening at 4000');
- var tunnel = localtunnel(4000, function(err, tunnel) {
- if (err) {
- // console.log(err);
- $('#code-sharing-box').html(err);
- }
-
- // the assigned public url for your tunnel
- // i.e. https://abcdefgjhij.localtunnel.me
- $('#code-sharing-box').html('Share this url with whome you want to share ');
- $('#code-sharing-box').append('' + tunnel.url + ' ');
- $('#code-sharing-box').append('Commit Changes ');
- $('#code-sharing-box').append('Disconnect ');
- // console.log(tunnel.url);
- });
- tunnel.on('error', function(err) {
- $('#code-sharing-box').html(err);
- });
- });
- // console.log(file);
- io.on('connection', function (socket) {
- clients.push(socket);
- socket.emit('file', { id: file.id, name:file.name, remote_path:file.path, data:file.editor.getValue() });
- socket.on('commit-changes', function (data) {
- // console.log('hello');
- if(file.id == data.id && file.path == data.path){
- file.editor.setValue(data.data);
- editor.setValue(data.data);
- }
- files['#' + data.id].editor.setValue(data.data);
- });
- });
- }
-}
-
-function connect(flag){
- if(!flag){
- $('#code-sharing-box').html(' Connect ');
- }else{
- let url = $('#url').val();
- $('#code-sharing-box').html('Waiting... ');
- socket = io_client(url);
- socket.on('file', function (data) {
- remoteFile = data;
- // newFileCount++;
- // newTab(undefined, newFileCount, path.basename(data.remote_path), data.data);
- openFile(data.data, undefined, data.name, data.remote_path);
- // console.log(data);
- // socket.emit('my other event', { my: 'data' });
- $('#code-sharing-box').html('Commit Changes ');
- $('#code-sharing-box').append('Close Connection ');
- });
- socket.on('commit-changes', function(data){
- // console.log('data recieved');
- // console.log(file.remote_path, remoteFile.remote_path);
- if(file.remote_path == remoteFile.remote_path){
- file.editor.setValue(data.data);
- editor.setValue(data.data);
- // console.log('if executed');
- }
- // console.log('after if');
- for(let i = 0; i < files.length; i++){
- if(files[i].remote_path == remoteFile.remote_path){
- // console.log('file found');
- files[i].editor.setValue(data.data);
- }
- }
- });
- socket.on('error', function(error){
- $('#code-sharing-box').html(error);
- });
- }
-}
-
-function commitChangesSender(){
- for(let i = 0; i < clients.length; i++){
- clients[i].emit('commit-changes', {id:file.id, name:file.name, path:file.path, data:file.editor.getValue()});
- }
-}
-
-function commitChanges(){
- socket.emit('commit-changes', {id:remoteFile.id, name:remoteFile.name, path:remoteFile.remote_path, data:file.editor.getValue()});
-}
-
-function backAllButtons(){
- $('#code-sharing-box').html('Share Code Connect ');
-}
-
-function closeSocket(){
- socket.destroy();
- backAllButtons();
-}
-
-function disconnect(){
- app.close();
- backAllButtons();
-}
-
-// end here
-
// open update download section
@@ -1199,29 +1023,6 @@ function closeToDot(){
}
-// update preview
-// editor.on("change", function() {
- // clearTimeout(delay);
-
- // auto save current file on change
-
- // let last_session = fs.readFileSync('./last_session/info.json');
- // last_session = JSON.parse(last_session);
- // fs.writeFile(last_session['#' + file.id].current_path, editor.getValue(), function(error){
- // if(error) throw error;
- // });
-
- // end here
-
- // closeToDot();
- // setTimeout(updateHtmlPreview, 300);
- // setTimeout(updateMarkdownPreview, 300);
- // updateHtmlPreview();
- // updateMarkdownPreview();
-// });
-
-// Refresh Preview
-
ipc.on('refreshPreview', function(event){
updateHtmlPreview();
updateMarkdownPreview();
@@ -1295,6 +1096,7 @@ function opentab(tab){
// editor.refresh();
setTimeout(function(){
editor.refresh();
+ editor.focus();
},1);
}
}
diff --git a/assets/js/last_session.js b/assets/js/last_session.js
new file mode 100644
index 0000000..a7a699e
--- /dev/null
+++ b/assets/js/last_session.js
@@ -0,0 +1,123 @@
+
+function checkLastSessionProjectAndOpen(){
+ let info = getLastSessionProjectInfo();
+ if(Object.keys(info).length > 0){
+ ipc.send('openProjectFromLastSession', info.project.path);
+ }
+}
+
+function openLastSessionFolders(){
+ let info = getLastSessionProjectInfo();
+ if(Object.keys(info).length > 0){
+ for(let i = 0; i < info.project.openedFolders.length; i++){
+ $('#' + info.project.openedFolders[i]).parent().children('a').children('span').click();
+ }
+ }
+}
+
+function getLastSessionFilesInfo(){
+ let info = fs.readFileSync(path.join(getUserDataPath(), '/last_session/info.json'));
+ info = JSON.parse(info);
+ return info;
+}
+
+function getLastSessionProjectInfo(){
+ let info = fs.readFileSync(path.join(getUserDataPath(), '/last_session/project_info.json'));
+ info = JSON.parse(info);
+ return info;
+}
+
+function writeLastSessionFilesInfo(data){
+ fs.writeFileSync(path.join(getUserDataPath() , '/last_session/info.json'), data);
+}
+
+function writeLastSessionProjectInfo(data){
+ fs.writeFileSync(path.join(getUserDataPath() , '/last_session/project_info.json'), data);
+}
+
+function checkLastSessionFilesAndOpen(){
+ info = getLastSessionFilesInfo();
+ if(Object.keys(info).length > 0){
+ writeLastSessionFilesInfo('{}');
+ for (let i in info){
+ let data = fs.readFileSync(path.join(getUserDataPath(), info[i].current_path), 'utf-8');
+ openFile(data, info[i].original_path);
+ if('#' + file.id != i){
+ fs.unlinkSync(path.join(getUserDataPath(), info[i].current_path));
+ }
+ }
+ }else{
+ newFile();
+ }
+}
+
+function changeLastSessionFilesContent(fileID, data){
+ let info = getLastSessionFilesInfo();
+ fs.writeFile(path.join(getUserDataPath(), info['#' + fileID].current_path), data, function(error){
+ if(error) throw error;
+ });
+}
+
+function makeNewLastSessionFile(filecount, filepath, data){
+ let info = getLastSessionFilesInfo();
+ info['#new' + filecount] = {
+ original_path : filepath,
+ current_path : path.join('last_session','#new' + filecount)
+ }
+ fs.writeFile(path.join(getUserDataPath(), info['#new' + filecount].current_path), data, function(error){
+ if(error) throw error;
+ });
+ info = JSON.stringify(info, null, 2);
+ writeLastSessionFilesInfo(info);
+}
+
+function deleteLastSessionFile(fileID,){
+ let info = getLastSessionFilesInfo();
+ if(info['#' + fileID]){
+ fs.unlinkSync(path.join(getUserDataPath(), info['#' + fileID].current_path));
+ }
+ delete info['#' + fileID];
+ info = JSON.stringify(info, null, 2);
+ writeLastSessionFilesInfo(info);
+}
+
+function updateLastSessionFilePath(fileID, filepath){
+ let info = getLastSessionFilesInfo();
+ info['#' + fileID].original_path = filepath;
+ info = JSON.stringify(info, null, 2);
+ writeLastSessionFilesInfo(info);
+}
+
+function newLastSessionForProject(project_path){
+ let info = getLastSessionProjectInfo();
+ info['project'] = {
+ path : project_path,
+ openedFolders : []
+ }
+ info = JSON.stringify(info, null, 2);
+ writeLastSessionProjectInfo(info);
+}
+
+function updateOpenFolderInProjectInfo(folder_path){
+ let info = getLastSessionProjectInfo();
+ let index = info.project.openedFolders.indexOf(folder_path);
+ if(index > -1){
+ info.project.openedFolders.splice(index);
+ }else{
+ info.project.openedFolders.push(folder_path);
+ }
+ info = JSON.stringify(info, null, 2);
+ writeLastSessionProjectInfo(info);
+}
+
+module.exports = {
+ checkLastSessionProjectAndOpen : checkLastSessionProjectAndOpen,
+ checkLastSessionFilesAndOpen : checkLastSessionFilesAndOpen,
+ changeLastSessionFilesContent : changeLastSessionFilesContent,
+ makeNewLastSessionFile : makeNewLastSessionFile,
+ deleteLastSessionFile : deleteLastSessionFile,
+ updateLastSessionFilePath : updateLastSessionFilePath,
+ newLastSessionForProject : newLastSessionForProject,
+ updateOpenFolderInProjectInfo : updateOpenFolderInProjectInfo,
+ openLastSessionFolders : openLastSessionFolders
+}
\ No newline at end of file
diff --git a/main.js b/main.js
index d3f3670..6ebeabe 100644
--- a/main.js
+++ b/main.js
@@ -33,7 +33,7 @@ function createWindow () {
slashes: true
}))
// Open the DevTools.
- // mainWindow.webContents.openDevTools()
+ mainWindow.webContents.openDevTools()
// Emitted when the window is closed.
mainWindow.on('closed', function () {
// Dereference the window object, usually you would store windows
diff --git a/menu/functions.js b/menu/functions.js
index 8831b1f..0c51759 100644
--- a/menu/functions.js
+++ b/menu/functions.js
@@ -65,23 +65,41 @@ function openFile(){
});
}
-function openFolder(){
+function openFolder(project_path){
let structure = {};
- let dir = dialog.showOpenDialog(mainWindow,{properties : ['openDirectory']});
- if(dir === undefined){
- console.log("No folder selected");
+ if(project_path == undefined){
+ let dir = dialog.showOpenDialog(mainWindow, {properties: ['openDirectory']});
+ structure = {
+ path : dir[0],
+ name : path.basename(dir[0])
+ }
}else{
- // structure[dir[0]] = [];
- structure = dirTree(dir[0]);
- // openFolderHelper(dir[0],structure);
- // console.log(typeof structure);
- // console.log(structure);
- mainWindow.webContents.send('openFolder',structure);
+ structure = {
+ path : project_path,
+ name : path.basename(project_path)
+ }
}
+ mainWindow.webContents.send('openFolder', structure);
+ // let dir = dialog.showOpenDialog(mainWindow,{properties : ['openDirectory']});
+ // if(dir === undefined){
+ // console.log("No folder selected");
+ // }else{
+ // // structure[dir[0]] = [];
+ // structure = dirTree(dir[0]);
+ // // openFolderHelper(dir[0],structure);
+ // // console.log(typeof structure);
+ // // console.log(structure);
+ // mainWindow.webContents.send('openFolder',structure);
+ // }
// console.log()
}
+ipc.on('openProjectFromLastSession', function(event, project_path){
+ // console.log(project_path);
+ openFolder(project_path);
+})
+
ipc.on('createDirectoryForSpecificDirpath', function(event, folderpath){
// console.log(dirTree(folderpath));
mainWindow.webContents.send('getDirectroyForSpecificDirpath', dirTree(folderpath));
@@ -437,10 +455,14 @@ function getUserDataPath(){
if(! fs.existsSync(path.join(userDataPath, 'last_session'))){
fs.mkdirSync(path.join(userDataPath, 'last_session'));
fs.writeFileSync(path.join(userDataPath, 'last_session', 'info.json'), '{}');
+ fs.writeFileSync(path.join(userDataPath, 'last_session', 'project_info.json'), '{}');
}else{
if(! fs.existsSync(path.join(userDataPath, 'last_session', 'info.json'))){
fs.writeFileSync(path.join(userDataPath, 'last_session', 'info.json'), '{}');
}
+ if(! fs.existsSync(path.join(userDataPath, 'last_session', 'project_info.json'))){
+ fs.writeFileSync(path.join(userDataPath, 'last_session', 'project_info.json'), '{}');
+ }
}
if(! fs.existsSync(path.join(userDataPath, 'templates'))){
fs.mkdirSync(path.join(userDataPath,'templates'));
diff --git a/package-lock.json b/package-lock.json
index c622668..bc92995 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -1,6 +1,6 @@
{
"name": "Colon",
- "version": "1.4.1",
+ "version": "1.4.2",
"lockfileVersion": 1,
"requires": true,
"dependencies": {
diff --git a/views/editor.html b/views/editor.html
index ce16f4e..48ae05a 100644
--- a/views/editor.html
+++ b/views/editor.html
@@ -387,9 +387,9 @@
- Share Code
+ Share Code
- Connect
+ Connect