index.ts 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /** Glasstron */
  2. import * as glasstron from "glasstron"
  3. glasstron.init()
  4. /** Modules */
  5. import * as electron from "electron"
  6. import requireNativeDiscordModule from "./requireNative";
  7. import appSettings from "./appSettings"
  8. import autoStart from "./autoStart"
  9. import * as buildInfo from "./buildInfo"
  10. import * as Constants from "./Constants"
  11. import * as GPUSettings from "./GPUSettings"
  12. import * as moduleUpdater from "./common/moduleUpdater"
  13. import * as paths from "./common/paths"
  14. import { create } from "./singleInstance";
  15. import * as splashScreen from "./splashScreen"
  16. if (process.platform === 'linux') {
  17. // Some people are reporting audio problems on Linux that are fixed by setting
  18. // an environment variable PULSE_LATENCY_MSEC=30 -- the "real" fix is to see
  19. // what conditions require this and set this then (also to set it directly in
  20. // our webrtc setup code rather than here) but this should fix the bug for now.
  21. if (process.env.PULSE_LATENCY_MSEC === undefined) {
  22. process.env.PULSE_LATENCY_MSEC = "30";
  23. }
  24. }
  25. paths.init(buildInfo)
  26. electron.app.commandLine.appendSwitch('autoplay-policy', 'no-user-gesture-required');
  27. electron.app.commandLine.appendSwitch("no-force-async-hooks-checks");
  28. function setupHardwareAcceleration() {
  29. const settings = appSettings.getSettings();
  30. //@ts-ignore
  31. const electronMajor = parseInt(process.versions.electron.split('.')[0]);
  32. const allowed = process.env.DISCORD_ENABLE_HARDWARE_ACCELERATION || buildInfo.releaseChannel === 'development' || !(electronMajor === 7 && process.platform === 'darwin');
  33. // TODO: this is a copy of gpuSettings.getEnableHardwareAcceleration
  34. if (!allowed || !settings.get('enableHardwareAcceleration', true)) {
  35. electron.app.disableHardwareAcceleration();
  36. }
  37. }
  38. global["releaseChannel"] = "stable"
  39. setupHardwareAcceleration();
  40. function hasArgvFlag(flag) {
  41. return (process.argv || []).slice(1).includes(flag);
  42. }
  43. //Transform main thread into async
  44. (async function Main(){
  45. await electron.app.whenReady()
  46. console.log(`Initializing Lightcord.`)
  47. console.log(`Version: ${buildInfo.version}
  48. releaseChannel: ${buildInfo.releaseChannel}
  49. commit: ${buildInfo.commit}`)
  50. if(!electron.app.commandLine.hasSwitch('enable-transparent-visuals'))electron.app.commandLine.appendSwitch('enable-transparent-visuals');
  51. electron.app.setAppUserModelId(Constants.APP_ID);
  52. let coreModule
  53. create(() => {
  54. const startMinimized = hasArgvFlag('--start-minimized');
  55. coreModule = requireNativeDiscordModule('discord_desktop_core');
  56. coreModule.startup({
  57. paths,
  58. splashScreen,
  59. moduleUpdater,
  60. autoStart,
  61. buildInfo,
  62. appSettings,
  63. Constants,
  64. GPUSettings
  65. });
  66. coreModule.setMainWindowVisible(!startMinimized)
  67. }, (args) => {
  68. if (args != null && args.length > 0 && args[0] === '--squirrel-uninstall') {
  69. electron.app.quit();
  70. return;
  71. }
  72. if(args.length === 1 && args[0] === "--overlay-host"){ // this is a patch for Lightcord that focus itself
  73. //console.warn("OVERLAY HOST DÉTECTÉ. EVENNEMENT IGNORÉ MAIS POURRAIT CAUSER UN PROBLÈME.")
  74. return
  75. }
  76. if (coreModule) {
  77. coreModule.handleSingleInstance(args);
  78. }
  79. })
  80. })()