application-menu.js 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. const {Menu, shell} = require('electron');
  2. const menu = require('./function/menu');
  3. const dialog = require('./function/dialog');
  4. const demo = require('./function/demo-application-menu');
  5. let template = [
  6. {
  7. label: 'Fichier',
  8. submenu: [
  9. {
  10. label: 'Nouveau',
  11. accelerator: 'CmdOrCtrl+N',
  12. click: menu.new
  13. },
  14. {
  15. label: 'Importer',
  16. accelerator: 'CmdOrCtrl+I',
  17. click: menu.import
  18. },
  19. {
  20. type: 'separator'
  21. },
  22. {
  23. label: 'Reset',
  24. accelerator: 'CmdOrCtrl+R',
  25. click: () => {
  26. mainWindow.webContents.send('reset-app');
  27. }
  28. }
  29. ]
  30. },
  31. {
  32. label: 'Démo',
  33. submenu: [
  34. {
  35. label: 'Calcul nombre premier',
  36. click: demo.primeNumber
  37. },
  38. {
  39. label: 'Reduire l\'application',
  40. click: demo.tray
  41. }
  42. ]
  43. },
  44. {
  45. label: 'Fenêtre',
  46. submenu: [
  47. {
  48. label: 'Pleine écran',
  49. accelerator: (() => {
  50. if (process.platform === 'darwin') {
  51. return 'Ctrl+Command+F'
  52. } else {
  53. return 'F11'
  54. }
  55. })(),
  56. click: (item, focusedWindow) => {
  57. if (focusedWindow) {
  58. focusedWindow.setFullScreen(!focusedWindow.isFullScreen())
  59. }
  60. }
  61. },
  62. {
  63. label: 'Minimiser',
  64. accelerator: 'CmdOrCtrl+M',
  65. role: 'minimize'
  66. },
  67. {
  68. label: 'Fermer',
  69. accelerator: 'CmdOrCtrl+W',
  70. role: 'close'
  71. },
  72. {
  73. type: 'separator'
  74. },
  75. {
  76. label: 'Outils Developpeur',
  77. accelerator: (() => {
  78. if (process.platform === 'darwin') {
  79. return 'Alt+Command+I'
  80. } else {
  81. return 'Ctrl+Shift+I'
  82. }
  83. })(),
  84. click: menu.devTool
  85. }
  86. ]
  87. },
  88. {
  89. label: 'À propos',
  90. submenu: [
  91. {
  92. label: 'Electron',
  93. click: () => {
  94. shell.openExternal('https://www.electronjs.org');
  95. }
  96. },
  97. {
  98. label: 'Electronotes',
  99. click: () => {
  100. shell.openExternal('https://gitlab.univ-artois.fr/arthur_brandao/conf-electron');
  101. }
  102. },
  103. {
  104. label: 'Versions',
  105. click: () => {
  106. dialog.message(
  107. 'Versions',
  108. `Electron : ${process.versions.electron}\nChrome : ${process.versions.chrome}\nNode : ${process.versions.node}`,
  109. 'info',
  110. ['Fermer']
  111. );
  112. }
  113. }
  114. ]
  115. }
  116. ];
  117. const appMenu = Menu.buildFromTemplate(template);
  118. Menu.setApplicationMenu(appMenu);