This repository was archived by the owner on Apr 13, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathangular-electron.js
More file actions
109 lines (83 loc) · 3.1 KB
/
angular-electron.js
File metadata and controls
109 lines (83 loc) · 3.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
(function(angular, electronRequire, electronProcess, undefined) {'use strict';
angular.module('angular-electron', []);
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);
});
}
};
}]);
angular.module('angular-electron').constant('process', electronProcess);
var remoteModules = ['app', 'autoUpdater', 'BrowserWindow', 'contentTracing', 'dialog',
'globalShortcut', 'Menu', 'MenuItem', 'powerMonitor', 'powerSaveBlocker',
'protocol', 'webContents', '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 = electronRequire('electron').remote;
function registerElectronModule(_module) {
$provide.service(_module, function() {
return remote[_module];
});
}
function registerNodeModule(name, _require) {
_require = _require || name;
$provide.service(name, function() {
return typeof _require === 'function' ? _require(remote) : remote.require(_require);
});
}
this.register = registerNodeModule;
this.$get = [function() {
return remote;
}];
$provide.constant('remoteProcess', remote.process);
$provide.constant('currentWindow', remote.getCurrentWindow());
$provide.constant('currentWebContents', remote.getCurrentWebContents());
angular.forEach(remoteModules, function(remoteModule) {
registerElectronModule(remoteModule);
});
angular.forEach(nodeModules, function(nodeModule) {
registerNodeModule(nodeModule.name || nodeModule, nodeModule.require);
});
}]);
var wrapModules = ['desktopCapturer', 'ipcRenderer', 'webFrame', 'clipboard', 'crashReporter', 'nativeImage', 'screen', 'shell'];
angular.forEach(wrapModules, function (_module) {
angular.module('angular-electron').service(_module.name || _module, [function() {
return electronRequire('electron')[_module.require || _module];
}]);
});
angular.module('angular-electron').service('safeShutdown', ['$q', 'currentWindow', 'app', function($q, currentWindow, app) {
var actions = [];
function register(fn) {
actions.push(fn);
}
function exec() {
var promises = [];
angular.forEach(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
};
}]);
})(window.angular, window.require, window.process);