window.js 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. const config = require('../config');
  2. const { BrowserWindow } = require('electron');
  3. const path = require('path');
  4. const window = {};
  5. window.hidden = function (file) {
  6. const win = new BrowserWindow({
  7. width: 0,
  8. height: 0,
  9. show: false,
  10. webPreferences: {
  11. nodeIntegration: true
  12. }
  13. });
  14. if (file) {
  15. win.loadFile(file);
  16. }
  17. return win;
  18. }
  19. window.new = function (file, width, height) {
  20. // Default values
  21. width = width ? width : config.window.width;
  22. height = height ? height : config.window.height;
  23. // New window
  24. const win = new BrowserWindow ({
  25. width: width,
  26. height: height,
  27. icon: path.join(__dirname, '../electronotes.png'),
  28. webPreferences: {
  29. nodeIntegration: true
  30. }
  31. });
  32. win.loadFile(file);
  33. return win;
  34. }
  35. window.simple = function (file, width, height) {
  36. // Default values
  37. width = width ? width : config.window.width;
  38. height = height ? height : config.window.height;
  39. // New window
  40. const win = new BrowserWindow ({
  41. width: width,
  42. height: height,
  43. icon: path.join(__dirname, '../electronotes.png'),
  44. webPreferences: {
  45. nodeIntegration: false
  46. }
  47. });
  48. win.loadFile(file);
  49. return win;
  50. }
  51. window.frameless = function (file, parent, width, height) {
  52. // Default values
  53. width = width ? width : config.window.width;
  54. height = height ? height : config.window.height;
  55. // Options
  56. const opts = {
  57. width: width,
  58. height: height,
  59. frame: false,
  60. icon: path.join(__dirname, '../electronotes.png'),
  61. webPreferences: {
  62. nodeIntegration: true
  63. }
  64. }
  65. // Add parent if have one
  66. if (parent) {
  67. opts.parent = parent;
  68. }
  69. // New window
  70. const win = new BrowserWindow (opts);
  71. win.loadFile(file);
  72. return win;
  73. }
  74. module.exports = window;