ariaNgNativeElectronService.js 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. (function () {
  2. 'use strict';
  3. angular.module('ariaNg').factory('ariaNgNativeElectronService', [function () {
  4. var electron = angular.isFunction(window.nodeRequire) ? nodeRequire('electron') : {};
  5. var remote = electron.remote || {
  6. getGlobal: function () {
  7. return {};
  8. },
  9. getCurrentWindow: function () {
  10. return {};
  11. }
  12. };
  13. var shell = electron.shell || {
  14. openExternal: function () {
  15. return false;
  16. }
  17. };
  18. return {
  19. remote: remote,
  20. shell: shell,
  21. getSettings: function () {
  22. return remote.getGlobal('settings');
  23. },
  24. getRuntimeEnvironment: function () {
  25. if (!remote.process || !remote.process.versions) {
  26. return null;
  27. }
  28. var versions = remote.process.versions;
  29. var items = [];
  30. items.push({name: 'Electron', value: versions.electron});
  31. items.push({name: 'Node.js', value: versions.node});
  32. items.push({name: 'Chrome', value: versions.chrome});
  33. items.push({name: 'V8', value: versions.v8});
  34. return items;
  35. },
  36. version: function() {
  37. return this.getSettings().version;
  38. },
  39. ariaNgVersion: function() {
  40. return this.getSettings().ariaNgVersion;
  41. },
  42. isDevMode: function () {
  43. return !!this.getSettings().isDevMode;
  44. },
  45. useCustomAppTitle: function () {
  46. return !!this.getSettings().useCustomAppTitle;
  47. },
  48. getCurrentWindow: function () {
  49. return remote.getCurrentWindow();
  50. },
  51. openExternalLink: function (url) {
  52. return shell.openExternal(url);
  53. },
  54. registerEvent: function (event, callback) {
  55. this.getCurrentWindow().on && this.getCurrentWindow().on(event, callback);
  56. },
  57. isMaximized: function () {
  58. return this.getCurrentWindow().isMaximized && this.getCurrentWindow().isMaximized();
  59. },
  60. minimizeWindow: function () {
  61. this.getCurrentWindow().minimize();
  62. },
  63. maximizeOrRestoreWindow: function () {
  64. if (!this.getCurrentWindow().isMaximized()) {
  65. this.getCurrentWindow().maximize();
  66. } else {
  67. this.getCurrentWindow().unmaximize();
  68. }
  69. },
  70. exitApp: function () {
  71. this.getCurrentWindow().close();
  72. }
  73. };
  74. }]);
  75. }());