menu.js 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. /**
  2. * @author oldj
  3. * @blog http://oldj.net
  4. */
  5. "use strict";
  6. const Menu = require('menu');
  7. function makeMenu(app) {
  8. let template = [{
  9. label: 'Edit',
  10. submenu: [{
  11. label: 'Undo',
  12. accelerator: 'CmdOrCtrl+Z',
  13. role: 'undo'
  14. }, {
  15. label: 'Redo',
  16. accelerator: 'Shift+CmdOrCtrl+Z',
  17. role: 'redo'
  18. }, {
  19. type: 'separator'
  20. }, {
  21. label: 'Cut',
  22. accelerator: 'CmdOrCtrl+X',
  23. role: 'cut'
  24. }, {
  25. label: 'Copy',
  26. accelerator: 'CmdOrCtrl+C',
  27. role: 'copy'
  28. }, {
  29. label: 'Paste',
  30. accelerator: 'CmdOrCtrl+V',
  31. role: 'paste'
  32. }, {
  33. label: 'Select All',
  34. accelerator: 'CmdOrCtrl+A',
  35. role: 'selectall'
  36. }]
  37. }, {
  38. label: 'View',
  39. submenu: [{
  40. label: 'Toggle Full Screen',
  41. accelerator: (function () {
  42. if (process.platform == 'darwin') {
  43. return 'Ctrl+Command+F';
  44. } else {
  45. return 'F11';
  46. }
  47. })(),
  48. click: function (item, focusedWindow) {
  49. if (focusedWindow) {
  50. focusedWindow.setFullScreen(!focusedWindow.isFullScreen());
  51. }
  52. }
  53. //},
  54. //{
  55. // label: 'Toggle Developer Tools',
  56. // accelerator: (function () {
  57. // if (process.platform == 'darwin') {
  58. // return 'Alt+Command+I';
  59. // } else {
  60. // return 'Ctrl+Shift+I';
  61. // }
  62. // })(),
  63. // click: function (item, focusedWindow) {
  64. // if (focusedWindow) {
  65. // focusedWindow.toggleDevTools();
  66. // }
  67. // }
  68. }]
  69. }, {
  70. label: 'Window',
  71. role: 'window',
  72. submenu: [{
  73. label: 'Minimize',
  74. accelerator: 'CmdOrCtrl+M',
  75. role: 'minimize'
  76. }, {
  77. label: 'Close',
  78. accelerator: 'CmdOrCtrl+W',
  79. role: 'close'
  80. }]
  81. }, {
  82. label: 'Help',
  83. role: 'help',
  84. submenu: [{
  85. label: 'Homepage',
  86. click: function () {
  87. require('electron').shell.openExternal(config.url_homepage);
  88. }
  89. }, {
  90. label: 'Feedback',
  91. click: function () {
  92. require('electron').shell.openExternal(config.url_feedback);
  93. }
  94. }]
  95. }];
  96. if (app.__is_debug) {
  97. template[1].submenu.push({
  98. label: 'Reload',
  99. accelerator: 'CmdOrCtrl+R',
  100. click: function (item, focusedWindow) {
  101. if (focusedWindow)
  102. focusedWindow.reload();
  103. }
  104. });
  105. }
  106. if (process.platform == 'darwin') {
  107. let name = require('electron').app.getName();
  108. template.unshift({
  109. label: name,
  110. submenu: [{
  111. label: 'About ' + name,
  112. role: 'about'
  113. }, {
  114. label: 'Check for Updates...',
  115. click: function () {
  116. require('./js/chk').chkUpdate(config.VERSION, mainWindow);
  117. }
  118. }, {
  119. type: 'separator'
  120. }, {
  121. label: 'Services',
  122. role: 'services',
  123. submenu: []
  124. }, {
  125. type: 'separator'
  126. }, {
  127. label: 'Hide ' + name,
  128. accelerator: 'Command+H',
  129. role: 'hide'
  130. }, {
  131. label: 'Hide Others',
  132. accelerator: 'Command+Shift+H',
  133. role: 'hideothers'
  134. }, {
  135. label: 'Show All',
  136. role: 'unhide'
  137. }, {
  138. type: 'separator'
  139. }, {
  140. label: 'Quit',
  141. accelerator: 'Command+Q',
  142. click: function () {
  143. app.__force_quit = true;
  144. app.quit();
  145. }
  146. }]
  147. });
  148. // Window menu.
  149. template[3].submenu.push(
  150. {
  151. type: 'separator'
  152. },
  153. {
  154. label: 'Bring All to Front',
  155. role: 'front'
  156. }
  157. );
  158. }
  159. let menu = Menu.buildFromTemplate(template);
  160. Menu.setApplicationMenu(menu);
  161. }
  162. exports.makeMenu = makeMenu;