ariaNgNativeElectronService.js 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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. var localfs = remote.require('./localfs');
  25. return {
  26. remote: remote,
  27. shell: shell,
  28. getSettings: function () {
  29. return remote.getGlobal('settings');
  30. },
  31. getRuntimeEnvironment: function () {
  32. if (!remote.process || !remote.process.versions) {
  33. return null;
  34. }
  35. var versions = remote.process.versions;
  36. var items = [];
  37. items.push({name: 'Electron', value: versions.electron});
  38. items.push({name: 'Node.js', value: versions.node});
  39. items.push({name: 'Chrome', value: versions.chrome});
  40. items.push({name: 'V8', value: versions.v8});
  41. return items;
  42. },
  43. version: function() {
  44. return this.getSettings().version;
  45. },
  46. ariaNgVersion: function() {
  47. return this.getSettings().ariaNgVersion;
  48. },
  49. isDevMode: function () {
  50. return !!this.getSettings().isDevMode;
  51. },
  52. useCustomAppTitle: function () {
  53. return !!this.getSettings().useCustomAppTitle;
  54. },
  55. getCurrentWindow: function () {
  56. return remote.getCurrentWindow();
  57. },
  58. isLocalFSExists: function (fullpath) {
  59. return localfs.isExists(fullpath);
  60. },
  61. openExternalLink: function (url) {
  62. return shell.openExternal(url);
  63. },
  64. openFileInDirectory: function (dir, filename) {
  65. var fullpath = localfs.getFullPath(dir, filename);
  66. return shell.showItemInFolder(fullpath);
  67. },
  68. registerEvent: function (event, callback) {
  69. this.getCurrentWindow().on && this.getCurrentWindow().on(event, callback);
  70. },
  71. onMessage: function (messageType, callback) {
  72. ipcRenderer.on && ipcRenderer.on(messageType, callback);
  73. },
  74. initTray: function () {
  75. tray.init({
  76. labels: {
  77. ShowAriaNgNative: ariaNgLocalizationService.getLocalizedText('tray.ShowAriaNgNative'),
  78. Exit: ariaNgLocalizationService.getLocalizedText('tray.Exit')
  79. }
  80. });
  81. },
  82. setTrayLanguage: function () {
  83. tray.destroy();
  84. this.initTray();
  85. },
  86. getAndClearToBeCreatedTaskFilePath: function () {
  87. return cmd.getAndClearToBeCreatedTaskFilePath();
  88. },
  89. isMaximized: function () {
  90. return this.getCurrentWindow().isMaximized && this.getCurrentWindow().isMaximized();
  91. },
  92. minimizeWindow: function () {
  93. this.getCurrentWindow().minimize();
  94. },
  95. maximizeOrRestoreWindow: function () {
  96. if (!this.getCurrentWindow().isMaximized()) {
  97. this.getCurrentWindow().maximize();
  98. } else {
  99. this.getCurrentWindow().unmaximize();
  100. }
  101. },
  102. exitApp: function () {
  103. this.getCurrentWindow().close();
  104. }
  105. };
  106. }]);
  107. }());