example.js 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. 'use strict';
  2. const path = require('path');
  3. const {app, webContents, shell} = require('electron');
  4. const AutoLaunchManager = require('../lib/autoLaunch');
  5. const shortcut = require('../lib/shortcut');
  6. exports.getPath = function () {
  7. const dir = app.getAppPath();
  8. return dir;
  9. }
  10. exports.openDir = function (dir = '') {
  11. if (!dir) {
  12. return false;
  13. }
  14. dir = getElectronPath(dir);
  15. shell.openPath(dir);
  16. return true;
  17. }
  18. exports.executeJS = function (str) {
  19. let jscode = `(()=>{alert('${str}');return 'fromJs:${str}';})()`;
  20. console.log(jscode);
  21. return webContents.fromId(1).executeJavaScript(jscode);
  22. }
  23. exports.setShortcut = function (shortcutObj) {
  24. shortcut.register(shortcutObj, true, function (){
  25. MAIN_WINDOW.hide()
  26. });
  27. return true;
  28. }
  29. exports.autoLaunchEnable = function () {
  30. const autoLaunchManager = new AutoLaunchManager()
  31. const enable = autoLaunchManager.enable()
  32. return enable
  33. }
  34. exports.autoLaunchDisable = function () {
  35. const autoLaunchManager = new AutoLaunchManager()
  36. const disable = autoLaunchManager.disable()
  37. return disable
  38. }
  39. exports.autoLaunchIsEnabled = function () {
  40. const autoLaunchManager = new AutoLaunchManager()
  41. const isEnable = autoLaunchManager.isEnabled()
  42. return isEnable
  43. }
  44. exports.openSoftware = function (softName = '') {
  45. if (!softName) {
  46. return false;
  47. }
  48. let powershellPath = path.join(app.getAppPath(), "..", "tmp", softName);
  49. console.log(powershellPath);
  50. return true;
  51. }
  52. function getElectronPath(filepath) {
  53. //filepath = path.resolve(filepath);
  54. filepath = filepath.replace("resources", "");
  55. filepath = filepath.replace("app.asar", "");
  56. filepath = path.normalize(filepath);
  57. return filepath;
  58. };