Skip to content
This repository has been archived by the owner on Apr 13, 2021. It is now read-only.

Commit

Permalink
first release
Browse files Browse the repository at this point in the history
  • Loading branch information
ozsay committed Oct 29, 2015
1 parent f7a4546 commit 054746a
Show file tree
Hide file tree
Showing 8 changed files with 163 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
node_modules/

dist/
34 changes: 34 additions & 0 deletions gulpfile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
var del = require('del'),
gulp = require('gulp'),
concat = require('gulp-concat'),
insert = require('gulp-insert'),
uglify = require('gulp-uglify');

var HEADER = "define(['angular'], function(angular) {\n" +
"'use strict';\n\n" +
"angular.module('angular-electron', []);\n\n";
var FOOTER = "\n});";

gulp.task('clean', function () {
return del(['dist']);
});

gulp.task('build:dev', ['clean'], function () {
return gulp.src('./src/*')
.pipe(concat('angular-electron.js'))
.pipe(insert.prepend(HEADER))
.pipe(insert.append(FOOTER))
.pipe(gulp.dest('./dist/'));
});

gulp.task('build:prod', ['clean'], function () {
return gulp.src('./src/*')
.pipe(concat('angular-electron.min.js'))
.pipe(insert.prepend(HEADER))
.pipe(insert.append(FOOTER))
.pipe(uglify())
.pipe(gulp.dest('./dist/'));
});

gulp.task('build', ['build:dev', 'build:prod'], function() {
});
30 changes: 30 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"name": "angular-electron",
"version": "0.1.0",
"description": "angularjs helpers for electron apps",
"repository": {
"type": "git",
"url": "git+https://github.com/ozsay/angular-electron.git"
},
"keywords": [
"angular",
"angularjs",
"electron"
],
"author": "Oz Sayag",
"license": "MIT",
"bugs": {
"url": "https://github.com/ozsay/angular-electron/issues"
},
"homepage": "https://github.com/ozsay/angular-electron",
"dependencies": {
"angular": "^1.2.29"
},
"devDependencies": {
"del": "^2.0.2",
"gulp": "^3.9.0",
"gulp-concat": "^2.6.0",
"gulp-insert": "^0.5.0",
"gulp-uglify": "^1.4.2"
}
}
12 changes: 12 additions & 0 deletions src/external-link.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
angular.module('angular-electron').directive('externalLink', ['shell', function (shell) {
return {
restrict: 'A',
link: function(scope, elem, attrs) {
elem.on('click', function(event) {
event.preventDefault();

shell.openExternal(attrs.href || attrs.externalLink);
});
}
};
}]);
1 change: 1 addition & 0 deletions src/process.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
angular.module('angular-electron').constant('process', process);
37 changes: 37 additions & 0 deletions src/remote.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
var remoteModules = ['app', 'auto-updater', 'browser-window', 'content-tracing', 'dialog',
'global-shortcut', 'menu', 'menu-item', 'power-save-blocker',
'protocol', 'web-contents', 'tray'];
var nodeModules = ['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'];

angular.module('angular-electron').provider('remote', ['$provide', function($provide) {
var remote = require('remote');

function register(name, _require) {
_require = _require || name;

$provide.service(name, function() {
var __module = remote.require(_require);

return __module;
});
}

this.register = register;

this.$get = [function() {
return remote;
}];

$provide.constant('remoteProcess', remote.process);
$provide.constant('currentWindow', remote.getCurrentWindow());

angular.forEach(remoteModules, function(remoteModule) {
register(remoteModule.name || remoteModule, remoteModule.require);
});

angular.forEach(nodeModules, function(nodeModule) {
register(nodeModule.name || nodeModule, nodeModule.require);
});
}]);
9 changes: 9 additions & 0 deletions src/rendererModules.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
var wrapModules = ['ipc', 'web-frame', 'clipboard', 'crash-reporter', 'native-image', 'screen', 'shell'];

angular.forEach(wrapModules, function (_module) {
angular.module('angular-electron').service(_module.name || _module, [function() {
var __module = require(_module.require || _module);

return __module;
}]);
});
37 changes: 37 additions & 0 deletions src/safeShutdown.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
angular.module('angular-electron').service('safeShutdown', ['$q', 'currentWindow', 'app', function($q, currentWindow, app) {
var actions = [];

function register(fn) {
this.actions.push(fn);
}

function exec() {
var promises = [];

angular.forEach(this.actions, function (action) {
var res = action();

if (res !== undefined && res.then !== undefined) {
promises.push(res);
}
});

return $q.all(promises);
}

currentWindow.safeReload = function() {
exec().then(function() {
currentWindow.reload();
});
};

app.safeQuit = function() {
exec().then(function() {
app.quit();
});
};

return {
register: register
};
}]);

0 comments on commit 054746a

Please sign in to comment.