Skip to content

Instantly share code, notes, and snippets.

View SuddenDevelopment's full-sized avatar
🤖

SuddenDevelopment SuddenDevelopment

🤖
View GitHub Profile
@SuddenDevelopment
SuddenDevelopment / electron-forge-protocol-config.json
Created March 23, 2017 16:51
Electron-Forge custom protocol definition for osx
"config": {
"forge": {
"make_targets": {
"win32": [ "squirrel" ],
"darwin": [ "zip" ],
"linux": [ "deb","rpm" ]
},
"electronPackagerConfig": {
"protocols":[
{
//create a new window for oAuth
var oAuthWindow = new BrowserWindow({ width: 480, height: 640, });
//send to the destination oauth
oAuthWindow.loadURL(URL_TO_LOAD);
oAuthWindow.webContents.on('did-navigate', function (objEvent,strUrl) {
//console.log(objEvent,strUrl);
if(strUrl.indexOf(URL_MATCH_THAT_INDICATES_COMPLETE) > -1){
oAuthWindow.hide();
//send whatever you need to back to the main window
mainWindow.webContents.send('electron-msg', DATA_TO_SEND_MAIN_WINDOW_ON_COMPLETE);
fnMayI=function(intPerms,strPerm){
//intPerms is an dec number that conatins all of the permissions
//set these to your permissions map these are the binary positions of intPerms
var objPerms={
"read":1
,"update":2
,"create":4
,"props":16
,"delete":64
,"perms":65536
@SuddenDevelopment
SuddenDevelopment / index.js
Created June 7, 2017 13:57
electron new window from ipc
// get an IPC message from renderer
// I put an "action" filed in my ipc messages to switch on
ipcMain.on('electron-msg', (event, objMsg) => {
//handle incoming message here
switch(objMsg.action){
case 'oAuth':
// Create a system default browser window.
shell.openExternal(objMsg.data.url);
@SuddenDevelopment
SuddenDevelopment / package.json
Last active June 9, 2017 15:16
modify electron forge installer / package configs
"config": {
"forge": {
"electronInstallerDMG":{"format":"UDRO"},
"make_targets": {
"win32": [
"squirrel"
],
"darwin": [
"dmg"
],
@SuddenDevelopment
SuddenDevelopment / index.js
Created June 20, 2017 14:52
electron pass info from a custom protocol url to the main window before it opens
// capture any data you need from the url that opened the app
app.on('open-url',function(e, strUrl){
var someThingToUse = strUrl;
});
const createWindow = () => {
// Create the browser window.
mainWindow = new BrowserWindow({
width: 1280,
height: 800,
@SuddenDevelopment
SuddenDevelopment / app.js
Created July 8, 2017 03:20
cytoscape : update node style on click event
//watch all nodes for a click
cy.on('click', 'node', function(evt){
//add the labeling style to show the name on the specific one clicked
cy.$('#'+this.id()).style({
"content": this[0]._private.data.name,
"font-size": "12px",
"text-valign": "top",
"text-halign": "center"
});
});
@SuddenDevelopment
SuddenDevelopment / index.js
Created July 30, 2017 03:02
electron OSX menu that enables clipboard copy and paste
//this is a modified electron-forge default main.js file
import { app, BrowserWindow, ipcMain, shell, protocol, dialog, session, clipboard, Menu } from 'electron';
const metastream = require('metastream');
// Keep a global reference of the window object, if you don't, the window will
// be closed automatically when the JavaScript object is garbage collected.
let mainWindow;
process.on('uncaughtException', (err) => { console.error(err); });
const createWindow = () => {
@SuddenDevelopment
SuddenDevelopment / index.js
Created August 25, 2017 23:30
nvd3 focus zoom brush values callback
//add data to the array like this
$scope.chartData=[{x:0,y:0}];
$scope.chartOptions = {
"chart": {
"type": 'linePlusBarChart',
//...the other options...
"callback": function(chart){
chart.dispatch.on( 'brush', function (objBrush) {
// objBrush.extent these are array index values!
<div style={{"background":'linear-gradient(90deg, #f00 70%, transparent 30%)'}}> {objV.label} </div>