-
-
Save tangb/c3e89ca6960b0392b41985451dd738f8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 createMenu() { | |
const menuTemplate = [{ | |
label: 'File', | |
submenu: [ | |
{ | |
label: 'Preferences', | |
click: () => { | |
mainWindow.webContents.send('openPage'); | |
} | |
}, { | |
type: 'separator' | |
}, { | |
label: 'Quit', | |
click: () => { | |
app.quit(); | |
} | |
} | |
] | |
}]; | |
const menu = Menu.buildFromTemplate(menuTemplate); | |
Menu.setApplicationMenu(menu) | |
} | |
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. | |
mainWindow.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(); | |
createMenu(); | |
}); | |
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) | |
{ | |
self.ipcRenderer = require('electron').ipcRenderer; | |
self.ipcRenderer.on('openPage', function() { | |
$location.path('/preferences'); | |
}); | |
}; | |
Test.controller('testController', ['$rootScope', '$scope', '$location', testController]); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment