Skip to content

Commit d561f69

Browse files
committed
Update 1.4.1 & Discord - RPC Support
1 parent 7ede5ed commit d561f69

10 files changed

Lines changed: 181 additions & 15 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
11
## Changelog
2-
- Add: Real Time Code Sharing
3-
- Fixed: XSS Vulnerability
2+
- Add: Discord RPC

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,19 @@ Colon is a flexible text editor, built on [Electron](https://github.com/electron
66

77
### macOS
88

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

1111
Colon will automatically update when a new release is available.
1212

1313
### Windows
1414

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

1717
Colon will automatically update when a new release is available.
1818

1919
### Linux
2020

21-
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.
21+
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.
2222

2323
## License
2424

assets/js/bootstrap.min.js

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

assets/js/discord-rpc.js

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
const DiscordRPC = require('discord-rpc');
2+
const fs = require('fs');
3+
const path = require('path');
4+
const functions = require('../../menu/functions.js');
5+
6+
let settings_file = fs.readFileSync(path.join(functions.getUserDataPath(), 'settings.json'));
7+
settings_file = JSON.parse(settings_file);
8+
9+
10+
// console.log('loading discord-rpc.js');
11+
12+
const clientId = '544485914198409217';
13+
14+
DiscordRPC.register(clientId);
15+
16+
const rpc = new DiscordRPC.Client({ transport: 'ipc' });
17+
const startTimestamp = new Date();
18+
19+
async function setActivity() {
20+
if (!rpc || !mainWindow || ! settings_file.discord['discord-rpc-enable']) {
21+
return;
22+
}
23+
24+
// const boops = await mainWindow.webContents.executeJavaScript('window.boops');
25+
functions.getCurrentWorkingFile(function(filename){
26+
// console.log('hello');
27+
rpc.setActivity({
28+
details: `Working on ${filename}`,
29+
state: settings_file.discord['discord-status'],
30+
startTimestamp,
31+
largeImageKey: 'icon',
32+
largeImageText: 'A flexible text editor',
33+
smallImageKey: 'snek_small',
34+
smallImageText: 'A flexible text editor',
35+
instance: false,
36+
});
37+
})
38+
39+
}
40+
41+
rpc.on('ready', () => {
42+
setActivity();
43+
44+
// activity can only be set every 15 seconds
45+
setInterval(() => {
46+
setActivity();
47+
}, 15e3);
48+
});
49+
50+
rpc.login({ clientId }).catch(console.error);

assets/js/editor.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,11 @@ ipc.on('openDoubleClickFile', function(event,data,filepath){
137137
// var file = files['#new1'];
138138
// var editor1 = initEditor('code1')
139139

140+
ipc.on('currentWorkingFile', function(event){
141+
event.sender.send('getCurrentWorkingFile', file.name);
142+
});
143+
144+
140145
function newTab(filepath, filecount ,filename, data, remote_path){
141146
let file_id = "new" + filecount;
142147
// if(filepath == undefined){
@@ -675,6 +680,8 @@ ipc.on('error', function(event, message){
675680

676681
// save settings
677682

683+
//save editor settings
684+
678685
function saveEditorSettings(){
679686
let editor_settings_temp = $('#editor').children();
680687
let editor_settings = {};
@@ -712,6 +719,29 @@ ipc.on('editorSettingsSaved', function(event){
712719
// end here
713720

714721

722+
// save discord settings
723+
724+
function saveDiscordSettings(){
725+
let discord_settings_temp = $('#discord-rpc').children();
726+
let discord_settings = {};
727+
for(let i = 0; i < discord_settings_temp.length; i ++){
728+
if(discord_settings_temp[i].getAttribute('for')){
729+
if($('#' + discord_settings_temp[i].getAttribute('for')).attr('type') == 'checkbox'){
730+
discord_settings[discord_settings_temp[i].getAttribute('for')] = $('#' + discord_settings_temp[i].getAttribute('for')).is(':checked');
731+
}else if($('#' + discord_settings_temp[i].getAttribute('for')).attr('type') == 'text'){
732+
discord_settings[discord_settings_temp[i].getAttribute('for')] = $('#' + discord_settings_temp[i].getAttribute('for')).val();
733+
// console.log($('#discord-status').val())
734+
}
735+
}
736+
}
737+
// console.log(discord_settings);
738+
739+
ipc.send('saveDiscordSettings', discord_settings);
740+
}
741+
742+
ipc.on('discordSettingsSaved', function(event){
743+
console.log('discord settings saved');
744+
});
715745

716746

717747
// open about page
@@ -825,6 +855,13 @@ function openSettingsPanel(){
825855
$('#' + i).val(settings_file.editor[i]);
826856
}
827857
}
858+
for(let i in settings_file.discord){
859+
if(settings_file.discord[i] == true){
860+
$('#' + i).attr('checked','true');
861+
}else if(settings_file.discord[i] != true && settings_file.editor[i] != false){
862+
$('#' + i).val(settings_file.discord[i]);
863+
}
864+
}
828865
}else{
829866
// editor.refresh();
830867
$('.panel-middle').css('width','100%');

main.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ global.autoUpdater = require("electron-updater").autoUpdater;
33
const log = require('electron-log');
44
const dialog = require('electron').dialog;
55

6+
7+
68
let updater
79
autoUpdater.logger = log;
810
autoUpdater.logger.transports.file.level = 'info';
@@ -40,6 +42,7 @@ function createWindow () {
4042
mainWindow = null
4143
})
4244
require('./menu/menu.js');
45+
require('./assets/js/discord-rpc.js');
4346
}
4447
// This method will be called when Electron has finished
4548
// initialization and is ready to create browser windows.
@@ -72,7 +75,7 @@ app.on('ready', function(){
7275
// message:process.argv[1].toString()
7376
// });
7477
// console.log(process.argv);
75-
require('./menu/functions.js').openDoubleClickFile(process.argv[1]);
78+
require('./menu/functions.js').openDoubleClickFile(process.argv[1]);
7679
}
7780
});
7881
// autoUpdater.checkForUpdatesAndNotify();

menu/functions.js

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ const ipc = require('electron').ipcMain;
44
const path = require('path');
55
const util = require('util');
66
const exec = require('child_process').exec;
7+
8+
// console.log('loading functions-rpc.js');
9+
710
// const spawn = require('child_process').spawn;
811

912
global.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+
168179
function 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

407431
function 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
}

package-lock.json

Lines changed: 25 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "Colon",
3-
"version": "1.4.0",
3+
"version": "1.4.1",
44
"description": "A flexible text editor",
55
"author": "Harendra Chhekur <820121223505e@gmail.com>",
66
"main": "main.js",
@@ -17,6 +17,7 @@
1717
"electron-builder": "^20.38.4"
1818
},
1919
"dependencies": {
20+
"discord-rpc": "^3.0.1",
2021
"electron-log": "^2.2.17",
2122
"electron-updater": "^4.0.6",
2223
"localtunnel": "^1.9.1",

views/editor.html

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@
156156
<ul id="menu">
157157
<li id = "menu-themes" onclick = "openSettingsRightPanel('themes')">Themes</li>
158158
<li id = "menu-editor" onclick = "openSettingsRightPanel('editor')">Editor</li>
159+
<li id = "menu-discord-rpc" onclick = "openSettingsRightPanel('discord-rpc')">Discord RPC</li>
159160
</ul>
160161
</div>
161162
<div class = "right-settings-panel">
@@ -348,6 +349,32 @@
348349

349350
<button class = "btn" onclick = "saveEditorSettings()">Save Changes</button><br><br>
350351
</div>
352+
353+
<div id = "discord-rpc">
354+
355+
<label for="discord-rpc-enable" class="label-cbx">
356+
<input id="discord-rpc-enable" type="checkbox" class="invisible">
357+
<div class="checkbox">
358+
<svg width="17px" height="17px" viewBox="0 0 20 20">
359+
<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>
360+
<polyline points="4 11 8 15 16 6"></polyline>
361+
</svg>
362+
</div>
363+
<span>Enable Discord RPC</span>
364+
<p class="checkbox-description">Enable Discord Status.</p>
365+
</label>
366+
<br>
367+
368+
<label for="discord-status">
369+
<span>Discord Status</span>
370+
<p class="checkbox-description-input">Status to show on Discord.</p>
371+
<input id = "discord-status" type = "text" class = "input-field">
372+
</label>
373+
<br><br>
374+
375+
<button class = "btn" onclick = "saveDiscordSettings()">Save Changes</button><br><br>
376+
377+
</div>
351378
</div>
352379
</div>
353380

0 commit comments

Comments
 (0)