Skip to content

Commit

Permalink
Update 1.4.1 & Discord - RPC Support
Browse files Browse the repository at this point in the history
  • Loading branch information
Chhekur committed Feb 11, 2019
1 parent 7ede5ed commit d561f69
Show file tree
Hide file tree
Showing 10 changed files with 181 additions and 15 deletions.
3 changes: 1 addition & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
## Changelog
- Add: Real Time Code Sharing
- Fixed: XSS Vulnerability
- Add: Discord RPC
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,19 @@ Colon is a flexible text editor, built on [Electron](https://github.com/electron

### macOS

Download the latest [Colon release](https://github.com/Chhekur/colon-ide/releases/download/v1.4.0/Colon-1.4.0.dmg) for mac.
Download the latest [Colon release](https://github.com/Chhekur/colon-ide/releases/download/v1.4.1/Colon-1.4.1.dmg) for mac.

Colon will automatically update when a new release is available.

### Windows

Download the latest [Colon installer](https://github.com/Chhekur/colon-ide/releases/download/v1.4.0/Colon-Setup-1.4.0.exe) for windows.
Download the latest [Colon installer](https://github.com/Chhekur/colon-ide/releases/download/v1.4.1/Colon-Setup-1.4.1.exe) for windows.

Colon will automatically update when a new release is available.

### Linux

Download the latest [Colon installer](https://github.com/Chhekur/colon-ide/releases/download/v1.4.0/Colon-1.4.0-x86_64.AppImage) for linux.
Download the latest [Colon installer](https://github.com/Chhekur/colon-ide/releases/download/v1.4.1/Colon-1.4.1-x86_64.AppImage) for linux.

## License

Expand Down
10 changes: 5 additions & 5 deletions assets/js/bootstrap.min.js

Large diffs are not rendered by default.

50 changes: 50 additions & 0 deletions assets/js/discord-rpc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
const DiscordRPC = require('discord-rpc');
const fs = require('fs');
const path = require('path');
const functions = require('../../menu/functions.js');

let settings_file = fs.readFileSync(path.join(functions.getUserDataPath(), 'settings.json'));
settings_file = JSON.parse(settings_file);


// console.log('loading discord-rpc.js');

const clientId = '544485914198409217';

DiscordRPC.register(clientId);

const rpc = new DiscordRPC.Client({ transport: 'ipc' });
const startTimestamp = new Date();

async function setActivity() {
if (!rpc || !mainWindow || ! settings_file.discord['discord-rpc-enable']) {
return;
}

// const boops = await mainWindow.webContents.executeJavaScript('window.boops');
functions.getCurrentWorkingFile(function(filename){
// console.log('hello');
rpc.setActivity({
details: `Working on ${filename}`,
state: settings_file.discord['discord-status'],
startTimestamp,
largeImageKey: 'icon',
largeImageText: 'A flexible text editor',
smallImageKey: 'snek_small',
smallImageText: 'A flexible text editor',
instance: false,
});
})

}

rpc.on('ready', () => {
setActivity();

// activity can only be set every 15 seconds
setInterval(() => {
setActivity();
}, 15e3);
});

rpc.login({ clientId }).catch(console.error);
37 changes: 37 additions & 0 deletions assets/js/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,11 @@ ipc.on('openDoubleClickFile', function(event,data,filepath){
// var file = files['#new1'];
// var editor1 = initEditor('code1')

ipc.on('currentWorkingFile', function(event){
event.sender.send('getCurrentWorkingFile', file.name);
});


function newTab(filepath, filecount ,filename, data, remote_path){
let file_id = "new" + filecount;
// if(filepath == undefined){
Expand Down Expand Up @@ -675,6 +680,8 @@ ipc.on('error', function(event, message){

// save settings

//save editor settings

function saveEditorSettings(){
let editor_settings_temp = $('#editor').children();
let editor_settings = {};
Expand Down Expand Up @@ -712,6 +719,29 @@ ipc.on('editorSettingsSaved', function(event){
// end here


// save discord settings

function saveDiscordSettings(){
let discord_settings_temp = $('#discord-rpc').children();
let discord_settings = {};
for(let i = 0; i < discord_settings_temp.length; i ++){
if(discord_settings_temp[i].getAttribute('for')){
if($('#' + discord_settings_temp[i].getAttribute('for')).attr('type') == 'checkbox'){
discord_settings[discord_settings_temp[i].getAttribute('for')] = $('#' + discord_settings_temp[i].getAttribute('for')).is(':checked');
}else if($('#' + discord_settings_temp[i].getAttribute('for')).attr('type') == 'text'){
discord_settings[discord_settings_temp[i].getAttribute('for')] = $('#' + discord_settings_temp[i].getAttribute('for')).val();
// console.log($('#discord-status').val())
}
}
}
// console.log(discord_settings);

ipc.send('saveDiscordSettings', discord_settings);
}

ipc.on('discordSettingsSaved', function(event){
console.log('discord settings saved');
});


// open about page
Expand Down Expand Up @@ -825,6 +855,13 @@ function openSettingsPanel(){
$('#' + i).val(settings_file.editor[i]);
}
}
for(let i in settings_file.discord){
if(settings_file.discord[i] == true){
$('#' + i).attr('checked','true');
}else if(settings_file.discord[i] != true && settings_file.editor[i] != false){
$('#' + i).val(settings_file.discord[i]);
}
}
}else{
// editor.refresh();
$('.panel-middle').css('width','100%');
Expand Down
5 changes: 4 additions & 1 deletion main.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ global.autoUpdater = require("electron-updater").autoUpdater;
const log = require('electron-log');
const dialog = require('electron').dialog;



let updater
autoUpdater.logger = log;
autoUpdater.logger.transports.file.level = 'info';
Expand Down Expand Up @@ -40,6 +42,7 @@ function createWindow () {
mainWindow = null
})
require('./menu/menu.js');
require('./assets/js/discord-rpc.js');
}
// This method will be called when Electron has finished
// initialization and is ready to create browser windows.
Expand Down Expand Up @@ -72,7 +75,7 @@ app.on('ready', function(){
// message:process.argv[1].toString()
// });
// console.log(process.argv);
require('./menu/functions.js').openDoubleClickFile(process.argv[1]);
require('./menu/functions.js').openDoubleClickFile(process.argv[1]);
}
});
// autoUpdater.checkForUpdatesAndNotify();
Expand Down
29 changes: 27 additions & 2 deletions menu/functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ const ipc = require('electron').ipcMain;
const path = require('path');
const util = require('util');
const exec = require('child_process').exec;

// console.log('loading functions-rpc.js');

// const spawn = require('child_process').spawn;

global.filename = undefined;
Expand Down Expand Up @@ -165,6 +168,14 @@ function save(){
mainWindow.webContents.send('save');
}

function getCurrentWorkingFile(callback){
mainWindow.webContents.send('currentWorkingFile')
ipc.once('getCurrentWorkingFile', function(event, filename){
// console.log(filename);
callback(filename);
})
}

function copyTemplate(filepath){
// console.log(path.join(getUserDataPath(), 'templates', path.basename(filepath).split('.')[1] + '.template'));
if(fs.existsSync(path.join(getUserDataPath(), 'templates', path.basename(filepath).split('.')[1] + '.template'))){
Expand Down Expand Up @@ -373,7 +384,11 @@ function getUserDataPath(){
"styleActiveLine": true,
"tabSize": 4,
"indentUnit": 4
}
},
"discord":{
"discord-rpc-enable":false,
"discord-status":"I am new to colon"
}
}
settings_default = JSON.stringify(settings_default, null, 2);
if(! fs.existsSync(path.join(userDataPath, 'settings.json'))){
Expand Down Expand Up @@ -403,6 +418,15 @@ ipc.on('saveEditorSettings', function(event, editor_settings){
mainWindow.webContents.send('editorSettingsSaved');
})

ipc.on('saveDiscordSettings', function(event, discord_settings){
let settings_file = fs.readFileSync(path.join(getUserDataPath(), 'settings.json'));
settings_file = JSON.parse(settings_file);
settings_file.discord = discord_settings;
settings_file = JSON.stringify(settings_file, null, 2)
fs.writeFileSync(path.join(getUserDataPath(), 'settings.json'), settings_file);
mainWindow.webContents.send('discordSettingsSaved');
})


function createTemplate(file_ext){
mainWindow.webContents.send('openFile', '', path.join(getUserDataPath(),'templates' , file_ext + '.template'));
Expand Down Expand Up @@ -638,5 +662,6 @@ module.exports = {
openAbout : openAbout,
createTemplate : createTemplate,
getUserDataPath : getUserDataPath,
openTemplate : openTemplate
openTemplate : openTemplate,
getCurrentWorkingFile : getCurrentWorkingFile
}
26 changes: 25 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "Colon",
"version": "1.4.0",
"version": "1.4.1",
"description": "A flexible text editor",
"author": "Harendra Chhekur <[email protected]>",
"main": "main.js",
Expand All @@ -17,6 +17,7 @@
"electron-builder": "^20.38.4"
},
"dependencies": {
"discord-rpc": "^3.0.1",
"electron-log": "^2.2.17",
"electron-updater": "^4.0.6",
"localtunnel": "^1.9.1",
Expand Down
27 changes: 27 additions & 0 deletions views/editor.html
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@
<ul id="menu">
<li id = "menu-themes" onclick = "openSettingsRightPanel('themes')">Themes</li>
<li id = "menu-editor" onclick = "openSettingsRightPanel('editor')">Editor</li>
<li id = "menu-discord-rpc" onclick = "openSettingsRightPanel('discord-rpc')">Discord RPC</li>
</ul>
</div>
<div class = "right-settings-panel">
Expand Down Expand Up @@ -348,6 +349,32 @@

<button class = "btn" onclick = "saveEditorSettings()">Save Changes</button><br><br>
</div>

<div id = "discord-rpc">

<label for="discord-rpc-enable" class="label-cbx">
<input id="discord-rpc-enable" type="checkbox" class="invisible">
<div class="checkbox">
<svg width="17px" height="17px" viewBox="0 0 20 20">
<path d="M3,1 L17,1 L17,1 C18.1045695,1 19,1.8954305 19,3 L19,17 L19,17 C19,18.1045695 18.1045695,19 17,19 L3,19 L3,19 C1.8954305,19 1,18.1045695 1,17 L1,3 L1,3 C1,1.8954305 1.8954305,1 3,1 Z"></path>
<polyline points="4 11 8 15 16 6"></polyline>
</svg>
</div>
<span>Enable Discord RPC</span>
<p class="checkbox-description">Enable Discord Status.</p>
</label>
<br>

<label for="discord-status">
<span>Discord Status</span>
<p class="checkbox-description-input">Status to show on Discord.</p>
<input id = "discord-status" type = "text" class = "input-field">
</label>
<br><br>

<button class = "btn" onclick = "saveDiscordSettings()">Save Changes</button><br><br>

</div>
</div>
</div>

Expand Down

0 comments on commit d561f69

Please sign in to comment.