ariaNgNativeElectronService.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. (function () {
  2. 'use strict';
  3. angular.module('ariaNg').factory('ariaNgNativeElectronService', ['ariaNgLocalizationService', function (ariaNgLocalizationService) {
  4. var electron = angular.isFunction(window.nodeRequire) ? nodeRequire('electron') : {};
  5. var remote = electron.remote || {
  6. require: function () {
  7. return {};
  8. },
  9. getGlobal: function () {
  10. return {};
  11. },
  12. getCurrentWindow: function () {
  13. return {};
  14. }
  15. };
  16. var ipcRenderer = electron.ipcRenderer || {};
  17. var shell = electron.shell || {
  18. openExternal: function () {
  19. return false;
  20. }
  21. };
  22. var cmd = remote.require('./cmd');
  23. var tray = remote.require('./tray');
  24. return {
  25. remote: remote,
  26. shell: shell,
  27. getSettings: function () {
  28. return remote.getGlobal('settings');
  29. },
  30. getRuntimeEnvironment: function () {
  31. if (!remote.process || !remote.process.versions) {
  32. return null;
  33. }
  34. var versions = remote.process.versions;
  35. var items = [];
  36. items.push({name: 'Electron', value: versions.electron});
  37. items.push({name: 'Node.js', value: versions.node});
  38. items.push({name: 'Chrome', value: versions.chrome});
  39. items.push({name: 'V8', value: versions.v8});
  40. return items;
  41. },
  42. version: function() {
  43. return this.getSettings().version;
  44. },
  45. ariaNgVersion: function() {
  46. return this.getSettings().ariaNgVersion;
  47. },
  48. isDevMode: function () {
  49. return !!this.getSettings().isDevMode;
  50. },
  51. useCustomAppTitle: function () {
  52. return !!this.getSettings().useCustomAppTitle;
  53. },
  54. getCurrentWindow: function () {
  55. return remote.getCurrentWindow();
  56. },
  57. openExternalLink: function (url) {
  58. return shell.openExternal(url);
  59. },
  60. registerEvent: function (event, callback) {
  61. this.getCurrentWindow().on && this.getCurrentWindow().on(event, callback);
  62. },
  63. onMessage: function (messageType, callback) {
  64. ipcRenderer.on && ipcRenderer.on(messageType, callback);
  65. },
  66. initTray: function () {
  67. tray.init({
  68. labels: {
  69. ShowAriaNgNative: ariaNgLocalizationService.getLocalizedText('tray.ShowAriaNgNative'),
  70. Exit: ariaNgLocalizationService.getLocalizedText('tray.Exit')
  71. }
  72. });
  73. },
  74. setTrayLanguage: function () {
  75. tray.destroy();
  76. this.initTray();
  77. },
  78. getAndClearToBeCreatedTaskFilePath: function () {
  79. return cmd.getAndClearToBeCreatedTaskFilePath();
  80. },
  81. isMaximized: function () {
  82. return this.getCurrentWindow().isMaximized && this.getCurrentWindow().isMaximized();
  83. },
  84. minimizeWindow: function () {
  85. this.getCurrentWindow().minimize();
  86. },
  87. maximizeOrRestoreWindow: function () {
  88. if (!this.getCurrentWindow().isMaximized()) {
  89. this.getCurrentWindow().maximize();
  90. } else {
  91. this.getCurrentWindow().unmaximize();
  92. }
  93. },
  94. exitApp: function () {
  95. this.getCurrentWindow().close();
  96. }
  97. };
  98. }]);
  99. }());