Skip to content
This repository has been archived by the owner on Mar 4, 2020. It is now read-only.

Commit

Permalink
big init
Browse files Browse the repository at this point in the history
  • Loading branch information
LizAinslie committed Dec 30, 2018
0 parents commit 2027c91
Show file tree
Hide file tree
Showing 16 changed files with 4,962 additions and 0 deletions.
9 changes: 9 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Packages & Libs
node_modules

# Logs
yarn-error.log
npm-debug.log

# Distribution Files
dist
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"git.ignoreLimitWarning": true
}
14 changes: 14 additions & 0 deletions gulpfile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
const gulp = require('gulp');
const sass = require('gulp-sass');

sass.compiler = require('node-sass');

gulp.task('sass', function () {
return gulp.src('./src/scss/style.scss')
.pipe(sass().on('error', sass.logError))
.pipe(gulp.dest('./src/public'));
});

gulp.task('sass:watch', function () {
gulp.watch('./src/scss/style.scss', ['sass']);
});
36 changes: 36 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
"name": "myrpc",
"version": "1.0.0",
"description": "Distributed Discord RPC for @everyone!",
"main": "src/main.js",
"repository": "https://github.com/RailRunner166/MyRpc.git",
"author": "Landon Gravat <[email protected]>",
"license": "MIT",
"private": false,
"scripts": {
"launch": "electron src/main.js",
"styles": "gulp sass",
"pack": "electron-builder --dir",
"dist": "electron-builder"
},
"build": {
"appId": "me.railrunner16.myrpc",
"productName": "MyRPC",
"win": {
"target": "msi",
"icon": "src/assets/logo_square_512.png"
}
},
"dependencies": {
"discord-rich-presence": "^0.0.7",
"moment": "^2.23.0",
"register-scheme": "github:devsnek/node-register-scheme"
},
"devDependencies": {
"electron": "^4.0.0",
"electron-builder": "^20.38.4",
"gulp": "^4.0.0",
"gulp-sass": "^4.0.2",
"node-sass": "^4.11.0"
}
}
Binary file added src/assets/logo_square_512.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
95 changes: 95 additions & 0 deletions src/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
'use strict';

/* eslint-disable no-console */

const { app, BrowserWindow, nativeImage, ipcMain, globalShortcut } = require('electron');
const path = require('path');
const url = require('url');
const rpc = require('discord-rich-presence')('528735337015410712');

const startTimestamp = new Date();
const rpcData = {
startTimestamp,
instance: true,
details: 'Using MyRPC',
state: 'Being totally awesome',
largeImageText: 'MyRPC',
smallImageText: 'Made by RailRunner16',
largeImageKey: 'large_default',
smallImageKey: 'small_default'
}

let mainWindow;

const createWindow = () => {
mainWindow = new BrowserWindow({
width: 1200,
height: 1000,
resizable: true,
titleBarStyle: 'hidden',
});

mainWindow.loadURL(url.format({
pathname: path.join(__dirname, 'public/index.html'),
protocol: 'file:',
slashes: true,
}));

const icon = nativeImage.createFromPath(path.join(__dirname, 'assets/logo_square_512.png'));
mainWindow.setIcon(icon);

mainWindow.on('closed', () => {
mainWindow = null;
});
}

const setActivity = data => {
if (!rpc || !mainWindow) {
return;
}

return rpc.updatePresence(data);
}

app.on('ready', () => {
createWindow()
app.setName('MyRPC')

globalShortcut.register('CommandOrControl+Shift+I', () => {
mainWindow.webContents.openDevTools();
});

setActivity(rpcData);
});

app.on('window-all-closed', () => {
app.quit();
});

app.on('activate', () => {
if (mainWindow === null) {
createWindow();
}
});

ipcMain.on('asynchronous-message', (e, data) => {
rpcData.details = data.details;
rpcData.state = data.state;
rpcData.largeImageText = data.largeImageText;
rpcData.smallImageText = data.smallImageText;
rpcData.largeImageKey = data.largeImageKey;
rpcData.smallImageKey = data.smallImageKey;

console.debug(rpcData);

setActivity(rpcData);
})

ipcMain.on('synchronous-message', (e, action) => {
switch (action.toLowerCase()) {
case 'get_time':
e.returnValue = startTimestamp;
}
});

process.on('unhandledRejection', console.error);
68 changes: 68 additions & 0 deletions src/public/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>MyRPC</title>
<link rel=stylesheet href=style.css />
</head>
<body>
<h1 class="ui header">
MyRPC
<span class="sub header">Easily set your Discord status to anything!</span>
</h1>

<div class="ui grid">
<div class="column">
<div class="ui form">
<div class="input">
<label for="inputDetails">Details</label>
<input type="text" name="inputDetails" id="inputDetails" />
</div>
<div class="input">
<label for="inputState">State</label>
<input type="text" name="inputState" id="inputState" />
</div>
<div class="input">
<label for="inputLargeImageText">Large Image Text</label>
<input type="text" name="inputLargeImageText" id="inputLargeImageText" />
</div>
<div class="input">
<label for="inputSmallImageText">Small Image Text</label>
<input type="text" name="inputSmallImageText" id="inputSmallImageText" />
</div>
<div class="input">
<label for="selectLargeImageKey">Large Image</label>
<select name="selectLargeImageKey" id="selectLargeImageKey">
<option selected value="large_default">Default</option>
</select>
</div>
<div class="input">
<label for="selectSmallImageKey">Small Image</label>
<select name="selectSmallImageKey" id="selectSmallImageKey">
<option selected value="small_default">Default</option>
</select>
</div>

<button id="buttonSubmit">Make it So!</button>
</div>
</div>
<div class="column">
<div class="ui preview">
<div class="images">
<img class="big image" id="previewBigImg" alt="MyRPC" src="https://cdn.discordapp.com/app-assets/528735337015410712/528749698408906752.png">
<img class="small image" id="previewSmallImg" alt="Made by RailRunner16" src="https://cdn.discordapp.com/app-assets/528735337015410712/528761124267753473.png">
</div>
<div class="info">
<span class="text row name">MyRPC</span>
<span id="previewDetailsText" class="text row">Using MyRPC</span>
<span id="previewStateText" class="text row">Being Totally Awesome</span>
<span id="previewTimestampText" class="text row">00:00 elapsed</span>
</div>
</div>
</div>
</div>

<span class="ui credits">Made by <a class="link" title="chat.railrunner16.me" href="http://chat.railrunner16.me/" rel="nofollow" target="_blank">RailRunner16#0001</a> (Friend me on Discord!) with <span title="Love">❤️</span> and <span title="code">⌨️</span>.</span>
<script src=renderer.js></script>
</body>
</html>
85 changes: 85 additions & 0 deletions src/public/renderer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
'use strict';

/* eslint-env browser */

const { ipcRenderer } = require('electron');
const moment = require('moment');

const time = ipcRenderer.sendSync('synchronous-message', 'get_time');

const detailsInput = document.getElementById('inputDetails');
const stateInput = document.getElementById('inputState');
const largeImageTextInput = document.getElementById('inputLargeImageText');
const smallImageTextInput = document.getElementById('inputSmallImageText');
const largeImageKeySelect = document.getElementById('selectLargeImageKey');
const smallImageKeySelect = document.getElementById('selectSmallImageKey');
const submitButton = document.getElementById('buttonSubmit');

const data = {
details: 'Using MyRPC',
state: 'Being totally awesome',
largeImageText: 'MyRPC',
smallImageText: 'Made by RailRunner16',
largeImageKey: 'large_default',
smallImageKey: 'small_default',
};

const assets = {
large_default: 'https://cdn.discordapp.com/app-assets/528735337015410712/528749698408906752.png',
small_default: 'https://cdn.discordapp.com/app-assets/528735337015410712/528761124267753473.png',
};

const updateInputs = () => {
detailsInput.value = data.details;
stateInput.value = data.state;
largeImageTextInput.value = data.largeImageText;
smallImageTextInput.value = data.smallImageText;
largeImageKeySelect.value = data.largeImageKey;
smallImageKeySelect.value = data.smallImageKey;
};

const updatePreview = () => {
data.details = detailsInput.value;
data.state = stateInput.value;
data.largeImageText = largeImageTextInput.value;
data.smallImageText = smallImageTextInput.value;
data.largeImageKey = largeImageKeySelect.value;
data.smallImageKey = smallImageKeySelect.value;

document.getElementById('previewDetailsText').innerHTML = data.details;
document.getElementById('previewStateText').innerHTML = data.state;
document.getElementById('previewTimestampText').innerHTML = `${moment(time).fromNow(true)} elapsed`;

document.getElementById('previewBigImg').alt = data.largeImageText;
document.getElementById('previewSmallImg').alt = data.smallImageText;

document.getElementById('previewBigImg').src = assets[data.largeImageKey];
document.getElementById('previewSmallImg').src = assets[data.smallImageKey];
};

detailsInput.onchange = updatePreview;
stateInput.onchange = updatePreview;
largeImageTextInput.onchange = updatePreview;
smallImageTextInput.onchange = updatePreview;
largeImageKeySelect.onchange = updatePreview;
smallImageKeySelect.onchange = updatePreview;

updateInputs();

submitButton.onclick = () => {
data.details = `${detailsInput.value}`;
data.state = `${stateInput.value}`;
data.largeImageText = `${largeImageTextInput.value}`;
data.smallImageText = `${smallImageTextInput.value}`;
data.largeImageKey = `${largeImageKeySelect.value}`;
data.smallImageKey = `${smallImageKeySelect.value}`;

ipcRenderer.send('asynchronous-message', data);

updateInputs();
updatePreview();
};

setInterval(updatePreview, 100);

document.onerror = console.error;
Loading

0 comments on commit 2027c91

Please sign in to comment.