menu.js 4.6 KB

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