application-menu.js 2.2 KB

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