base.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. 'use strict'
  2. const { app, dialog } = require('electron')
  3. const AutoLaunchManager = require('../lib/AutoLaunch')
  4. exports.autoLaunchEnable = function () {
  5. const autoLaunchManager = new AutoLaunchManager()
  6. const enable = autoLaunchManager.enable()
  7. return enable
  8. }
  9. exports.autoLaunchDisable = function () {
  10. const autoLaunchManager = new AutoLaunchManager()
  11. const disable = autoLaunchManager.disable()
  12. return disable
  13. }
  14. exports.autoLaunchIsEnabled = function () {
  15. const autoLaunchManager = new AutoLaunchManager()
  16. const isEnable = autoLaunchManager.isEnabled()
  17. return isEnable
  18. }
  19. exports.appExit = function () {
  20. app.exit()
  21. }
  22. exports.appRelaunch = function () {
  23. app.relaunch()
  24. app.exit()
  25. }
  26. /**
  27. * 选择本地文件夹
  28. * @param title 弹出框的标题
  29. * @return {Promise<*>}
  30. */
  31. exports.choiceFolder = async function (title = '') {
  32. return await dialog.showOpenDialog({
  33. properties: ['openDirectory'],
  34. title: title
  35. })
  36. }
  37. /**
  38. * 选择本地文件
  39. * @param title 弹出框的标题
  40. * @param extensions 后缀名集合 e.g: ['exe','txt','png']
  41. * @return {Promise<*>}
  42. */
  43. exports.choiceFile = async function (title = '', extensions = []) {
  44. return await dialog.showOpenDialog({
  45. properties: ['openFile'],
  46. filters: [{
  47. extensions: extensions
  48. }],
  49. title: title
  50. })
  51. }