Giter VIP home page Giter VIP logo

angular-electron's Introduction

angular-electron

angularjs helpers for electron apps

Installation

npm install angular-electron
bower install angular-electron

Use 0.1.x for electron < 0.35.0 and 0.2.x for electron > 0.35.0

Usage

<body>
   <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.15/angular.min.js"></script>
   <script src="angular-electron.js"></script>
 </body>
angular.module('myModule', ['angular-electron']);

API

renderer modules

These are all the renderer modules that are available as angular services:

desktopCapturer, ipcRenderer, webFrame, clipboard, crashReporter, nativeImage, screen, shell

To use them, simply inject them to your components:

angular.module('myModule').controller('myCtrl', ['shell', function(shell) {
  shell.showItemInFolder(pathToItem);
}]);

remote and node modules

These are all the main modules that are available as angular services:

app, autoUpdater, BrowserWindow, contentTracing, dialog, globalShortcut, Menu, MenuItem, powerMonitor, powerSaveBlocker, protocol, webContents, tray

Node modules:

buffer, child_process, cluster, crypto, dns, events, fs, http, https, net, os, path, punycode, querystring, readline, stream, string_decoder, tls, dgram, url, util, v8, vm, zlib

All of the modules are lazy required (required only on use).

remoteProvider

In order to use a node package (e.g. moment), use the remoteProvider to register the package to an angular service.

angular.module('myModule').config(['remoteProvider', function(remoteProvider) {
  remoteProvider.register('moment');
}]);

or

angular.module('myModule').config(['remoteProvider', function(remoteProvider) {
  remoteProvider.register({name: 'newName', require: 'moment'});
}]);

then inject it as a regular service

angular.module('myModule').controller('myCtrl', ['moment', function(moment) {

}]);

or

angular.module('myModule').controller('myCtrl', ['newName', function(moment) {

}]);

You can also register a module by function:

angular.module('myModule').config(['remoteProvider', function(remoteProvider) {
  remoteProvider.register('exec', function(remote) {
    return remote.require('child_process').exec;
  });
}]);

then use it

angular.module('myModule').controller('myCtrl', ['exec', function(exec) {
    exec('ls');
}]);

process objects

electron process objects are available as angularjs constants.

angular.module('myModule').controller('myCtrl', ['process', 'remoteProcess',
function(process, remoteProcess) {

}]);

current window

The current window is also available as angularjs constant.

angular.module('myModule').controller('myCtrl', ['currentWindow',
function(currentWindow) {

}]);

current web contents

The current web contents module is also available as angularjs constant.

angular.module('myModule').controller('myCtrl', ['currentWebContents',
function(currentWebContents) {

}]);

external link

This is a directive which opens a link in the default desktop browser.

<a href="https://google.com" external-link>google</a>
<button external-link="https://google.com">google</button>

safe shutdown

safe shutdown is a service which handles pre-shudown actions.

angular.module('myModule').controller('myCtrl', ['safeShutdown',
function(safeShutdown) {
  safeShutdown.register(function() {
    logout();
  });
}]);

The function can return a promise to handle async operations.

You can register multiple functions

Then use currentWindow.safeReload or app.safeQuit to reload/quit your app.

These methods are available only after safeShutdown is instantiated.

angular-electron's People

Contributors

ozsay avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

angular-electron's Issues

Release on Bower

It'd be very convenient to have this available via bower.

Thanks!

Include module without electron cause error

Including the module without Electron cause error. Can be useful including it in a "progressive web app" where some build haven't electron code. Example web, android, ios, desktop with electron.

It can be solved creating a empty object electronRequire

Module won't load because window.require is unavailable

Due to a know issue with Electron (look for "jQuery/RequireJS/Meteor/AngularJS" here http://electron.atom.io/docs/faq/) the recommendation on Electron FAQ is to rename window.require to something else. However, because of this, angular-electron module won't load throwing error:

Error: [$injector:modulerr] Failed to instantiate module angular-electron due to:
TypeError: electronRequire is not a function

If you could make an assumption that the require was renamed to nodeRequire and changed this line: https://github.com/ozsay/angular-electron/blob/master/angular-electron.js#L109 to

(window.angular, window.require || window.nodeRequire, window.process);

things should work out fine.

ipcRenderer update

The ipc does not work properly since the update of electron.
We need to use the require('electron').ipcRenderer.

If you can do an update for this, coul'd be great.

Thanks.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.