Skip to content

Instantly share code, notes, and snippets.

@tangb
Created August 29, 2017 11:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tangb/1018d44603672bd7d45c4f7c559d412c to your computer and use it in GitHub Desktop.
Save tangb/1018d44603672bd7d45c4f7c559d412c to your computer and use it in GitHub Desktop.
MAIN.JS
=======
const electron = require('electron')
const Menu = require('electron').Menu
const MenuItem = require('electron').MenuItem
// Module to control application life.
const app = electron.app
// Module to create native browser window.
const BrowserWindow = electron.BrowserWindow
// external browser
const shell = require('electron').shell;
const path = require('path')
const url = require('url')
var log = require('electron-log');
// 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
function createWindow () {
// Create the browser window.
mainWindow = new BrowserWindow({width: 800, height: 600})
mainWindow.maximize();
// and load the index.html of the app.
mainWindow.loadURL(url.format({
//pathname: path.join(__dirname, 'devices.html'),
pathname: path.join(__dirname, 'index.html'),
protocol: 'file:',
slashes: true
}), {"extraHeaders" : "pragma: no-cache\n"})
// Open the DevTools.
Window.webContents.openDevTools()
// Emitted when the window is closed.
mainWindow.on('closed', function () {
// Dereference the window object, usually you would store windows
// in an array if your app supports multi windows, this is the time
// when you should delete the corresponding element.
mainWindow = null
})
}
// This method will be called when Electron has finished
// initialization and is ready to create browser windows.
// Some APIs can only be used after this event occurs.
app.on('ready', function() {
createWindow();
});
RENDERER.JS
===========
var Test = angular.module('Test', ['ngMaterial', 'ngAnimate', 'ngMessages', 'ngRoute']);
Test.config(['$routeProvider', function ($routeProvider) {
$routeProvider
.when('/', {
templateUrl: 'empty.html'
})
.when('/preferences', {
templateUrl: 'preferences.html'
});
$routeProvider.otherwise({ redirectTo: '/' });
}]);
var testController = function($rootScope, $scope, $location, $route)
{
var self = this;
self.remote = require('electron').remote;
self.Menu = self.remote.Menu;
self.App = self.remote.app;
self.menu = [{
label: 'File',
submenu: [{
label: 'Preferences',
click: function() {
self.openPage();
}
}, {
label: 'Quit',
click: function() {
self.App.quit();
}
}]
}];
self.openPage = function(page)
{
console.log('openPage called');
$location.path('/preferences');
};
self.init = function()
{
var menu = self.Menu.buildFromTemplate(self.menu);
self.App.setApplicationMenu(menu);
};
self.init();
};
Test.controller('testController', ['$rootScope', '$scope', '$location', '$route', testController]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment