config.js 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. 'use strict';
  2. const path = require('path');
  3. const dayjs = require('dayjs');
  4. const storage = require('./storage');
  5. const config = {
  6. log: {
  7. file: {
  8. fileName: path.normalize('./logs/electron-' + dayjs().format('YYYY-MM-DD') + '.log'),
  9. level: 'silly', // error, warn, info, verbose, debug, silly
  10. format: '[{y}-{m}-{d} {h}:{i}:{s}.{ms}] [{level}] {text}',
  11. maxSize: '1048576' // 1048576 (1mb) by default.
  12. }
  13. },
  14. windowsOption: {
  15. width: 980,
  16. height: 600,
  17. minWidth: 800,
  18. minHeight: 600,
  19. webPreferences: {
  20. //webSecurity: false,
  21. nodeIntegration: true,
  22. preload: path.join(__dirname, '../preload.js')
  23. },
  24. //frame: false,
  25. //titleBarStyle: 'hidden'
  26. },
  27. egg: {
  28. title: 'electron-egg',
  29. env: 'prod',
  30. port: 7068,
  31. hostname: '0.0.0.0',
  32. workers: 1
  33. },
  34. autoUpdate: {
  35. enable: false,
  36. options: {
  37. provider: 'generic', // or github, s3, bintray
  38. url: 'https://raw.githubusercontent.com/wallace5303/electron-egg/master/' // resource dir
  39. }
  40. },
  41. electronApi: {
  42. port: 7069,
  43. hostname: '0.0.0.0',
  44. }
  45. }
  46. exports.get = function (flag = '', env = 'prod') {
  47. console.log('[config] [get] flag:', flag);
  48. if (flag === 'log') {
  49. return config.log;
  50. }
  51. if (flag === 'windowsOption') {
  52. return config.windowsOption;
  53. }
  54. if (flag === 'webEgg') {
  55. return config.egg;
  56. }
  57. if (flag === 'egg') {
  58. const eggConfig = storage.getEggConfig();
  59. if (env === 'prod' && eggConfig.port) {
  60. config.egg.port = eggConfig.port;
  61. }
  62. return config.egg;
  63. }
  64. if (flag === 'autoUpdate') {
  65. return config.autoUpdate;
  66. }
  67. return {};
  68. };
  69. exports = module.exports;