Sync with stable@0.0.307, I guess ?
This commit is contained in:
parent
85e4a7936a
commit
dd860e82ba
|
@ -22,7 +22,7 @@ export function cleanOldVersions(buildInfo) {
|
|||
const entries = fs.readdirSync(userDataPath) || [];
|
||||
entries.forEach(entry => {
|
||||
const fullPath = path.join(userDataPath, entry);
|
||||
if (fs.statSync(fullPath).isDirectory() && entry.indexOf(buildInfo.version) === -1) {
|
||||
if (fs.lstatSync(fullPath).isDirectory() && entry.indexOf(buildInfo.version) === -1) {
|
||||
if (entry.match('^[0-9]+.[0-9]+.[0-9]+') != null) {
|
||||
console.log('Removing old directory ', entry);
|
||||
rimraf(fullPath, originalFs, error => {
|
||||
|
|
150
src/index.ts
150
src/index.ts
|
@ -1,28 +1,27 @@
|
|||
/** settings */
|
||||
import appSettings from "./appSettings"
|
||||
let settings = appSettings.getSettings()
|
||||
import appSettings from "./appSettings";
|
||||
let settings = appSettings.getSettings();
|
||||
|
||||
/** Glasstron */
|
||||
if(settings.get("GLASSTRON", true)){
|
||||
const glasstron = require("glasstron")
|
||||
glasstron.init()
|
||||
if (settings.get("GLASSTRON", true)) {
|
||||
const glasstron = require("glasstron");
|
||||
glasstron.init();
|
||||
}
|
||||
|
||||
/** Modules */
|
||||
import * as electron from "electron"
|
||||
import * as electron from "electron";
|
||||
import requireNativeDiscordModule from "./requireNative";
|
||||
import autoStart from "./autoStart"
|
||||
import * as buildInfo from "./buildInfo"
|
||||
import * as Constants from "./Constants"
|
||||
import * as GPUSettings from "./GPUSettings"
|
||||
import * as moduleUpdater from "./common/moduleUpdater"
|
||||
import * as paths from "./common/paths"
|
||||
import { create } from "./singleInstance";
|
||||
import * as splashScreen from "./splashScreen"
|
||||
import { join } from "path"
|
||||
import { homedir } from "os"
|
||||
import autoStart from "./autoStart";
|
||||
import * as buildInfo from "./buildInfo";
|
||||
import * as Constants from "./Constants";
|
||||
import * as GPUSettings from "./GPUSettings";
|
||||
import * as moduleUpdater from "./common/moduleUpdater";
|
||||
import * as paths from "./common/paths";
|
||||
import * as splashScreen from "./splashScreen";
|
||||
import { join } from "path";
|
||||
import { homedir } from "os";
|
||||
|
||||
if (process.platform === 'linux') {
|
||||
if (process.platform === "linux") {
|
||||
// Some people are reporting audio problems on Linux that are fixed by setting
|
||||
// an environment variable PULSE_LATENCY_MSEC=30 -- the "real" fix is to see
|
||||
// what conditions require this and set this then (also to set it directly in
|
||||
|
@ -32,22 +31,24 @@ if (process.platform === 'linux') {
|
|||
}
|
||||
}
|
||||
|
||||
paths.init(buildInfo)
|
||||
electron.app.commandLine.appendSwitch('autoplay-policy', 'no-user-gesture-required');
|
||||
paths.init(buildInfo);
|
||||
electron.app.commandLine.appendSwitch(
|
||||
"autoplay-policy",
|
||||
"no-user-gesture-required"
|
||||
);
|
||||
electron.app.commandLine.appendSwitch("no-force-async-hooks-checks");
|
||||
|
||||
function setupHardwareAcceleration() {
|
||||
const settings = appSettings.getSettings();
|
||||
//@ts-ignore
|
||||
const electronMajor = parseInt(process.versions.electron.split('.')[0]);
|
||||
const allowed = process.env.DISCORD_ENABLE_HARDWARE_ACCELERATION || buildInfo.releaseChannel === 'development' || !(electronMajor === 7 && process.platform === 'darwin');
|
||||
// TODO: this is a copy of gpuSettings.getEnableHardwareAcceleration
|
||||
if (!allowed || !settings.get('enableHardwareAcceleration', true)) {
|
||||
if (!settings.get("enableHardwareAcceleration", true)) {
|
||||
electron.app.disableHardwareAcceleration();
|
||||
}
|
||||
}
|
||||
|
||||
global["releaseChannel"] = "stable"
|
||||
electron.app.allowRendererProcessReuse = false;
|
||||
|
||||
global["releaseChannel"] = "stable";
|
||||
|
||||
setupHardwareAcceleration();
|
||||
function hasArgvFlag(flag) {
|
||||
|
@ -55,38 +56,76 @@ function hasArgvFlag(flag) {
|
|||
}
|
||||
|
||||
//Transform main thread into async
|
||||
(async function Main(){
|
||||
await electron.app.whenReady()
|
||||
(async function Main() {
|
||||
await electron.app.whenReady();
|
||||
|
||||
if(process.argv.includes("--should-create-shortcut")){
|
||||
console.log(`Creating shortcuts.`)
|
||||
if(process.platform === "win32"){
|
||||
electron.shell.writeShortcutLink(join(homedir(), "Desktop", "Lightcord.lnk"), "create", {
|
||||
"appUserModelId": Constants.APP_ID,
|
||||
if (process.argv.includes("--should-create-shortcut")) {
|
||||
console.log(`Creating shortcuts.`);
|
||||
if (process.platform === "win32") {
|
||||
electron.shell.writeShortcutLink(
|
||||
join(homedir(), "Desktop", "Lightcord.lnk"),
|
||||
"create",
|
||||
{
|
||||
appUserModelId: Constants.APP_ID,
|
||||
description: Constants.packageJSON.description,
|
||||
target: process.execPath
|
||||
})
|
||||
electron.shell.writeShortcutLink(join(electron.app.getPath("appData"), "Microsoft", "Windows", "Start Menu", "Programs", "Lightcord.lnk"), "create", {
|
||||
"appUserModelId": Constants.APP_ID,
|
||||
target: process.execPath,
|
||||
}
|
||||
);
|
||||
electron.shell.writeShortcutLink(
|
||||
join(
|
||||
electron.app.getPath("appData"),
|
||||
"Microsoft",
|
||||
"Windows",
|
||||
"Start Menu",
|
||||
"Programs",
|
||||
"Lightcord.lnk"
|
||||
),
|
||||
"create",
|
||||
{
|
||||
appUserModelId: Constants.APP_ID,
|
||||
description: Constants.packageJSON.description,
|
||||
target: process.execPath
|
||||
})
|
||||
target: process.execPath,
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
console.log(`Initializing Lightcord.`)
|
||||
console.log(`Initializing Lightcord.`);
|
||||
console.log(`Version: ${buildInfo.version}
|
||||
releaseChannel: ${buildInfo.releaseChannel}
|
||||
commit: ${buildInfo.commit}`)
|
||||
commit: ${buildInfo.commit}`);
|
||||
|
||||
if(!electron.app.commandLine.hasSwitch('enable-transparent-visuals'))electron.app.commandLine.appendSwitch('enable-transparent-visuals');
|
||||
if (!electron.app.commandLine.hasSwitch("enable-transparent-visuals"))electron.app.commandLine.appendSwitch("enable-transparent-visuals");
|
||||
electron.app.setAppUserModelId(Constants.APP_ID);
|
||||
|
||||
let coreModule
|
||||
create(() => {
|
||||
const startMinimized = hasArgvFlag('--start-minimized');
|
||||
|
||||
coreModule = requireNativeDiscordModule('discord_desktop_core');
|
||||
|
||||
let coreModule;
|
||||
|
||||
const isFirstInstance = electron.app.requestSingleInstanceLock();
|
||||
const allowMultipleInstances = hasArgvFlag("--multi-instance");
|
||||
if (!isFirstInstance && !allowMultipleInstances) {
|
||||
electron.app.quit();
|
||||
return
|
||||
}
|
||||
|
||||
if (!allowMultipleInstances) {
|
||||
electron.app.on("second-instance", (_event, args, _workingDirectory) => {
|
||||
if(args && args[0] === "--overlay-host"){
|
||||
// this is a patch for Lightcord that focus itself when the user is playing a game.
|
||||
//console.warn("OVERLAY HOST DÉTECTÉ. EVENNEMENT IGNORÉ MAIS POURRAIT CAUSER UN PROBLÈME.")
|
||||
return;
|
||||
}
|
||||
|
||||
if (coreModule) {
|
||||
coreModule.handleSingleInstance(args);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
const startMinimized = hasArgvFlag("--start-minimized");
|
||||
|
||||
coreModule = requireNativeDiscordModule("discord_desktop_core");
|
||||
coreModule.startup({
|
||||
paths,
|
||||
splashScreen,
|
||||
|
@ -95,25 +134,8 @@ commit: ${buildInfo.commit}`)
|
|||
buildInfo,
|
||||
appSettings,
|
||||
Constants,
|
||||
GPUSettings
|
||||
GPUSettings,
|
||||
});
|
||||
|
||||
coreModule.setMainWindowVisible(!startMinimized)
|
||||
}, (args) => {
|
||||
if(args && args.length > 0){
|
||||
if(args.length > 0 && args[0] === '--squirrel-uninstall') {
|
||||
electron.app.quit();
|
||||
return;
|
||||
}
|
||||
|
||||
if(args && args.length === 1 && args[0] === "--overlay-host"){ // this is a patch for Lightcord that focus itself
|
||||
//console.warn("OVERLAY HOST DÉTECTÉ. EVENNEMENT IGNORÉ MAIS POURRAIT CAUSER UN PROBLÈME.")
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
if (coreModule) {
|
||||
coreModule.handleSingleInstance(args);
|
||||
}
|
||||
})
|
||||
})()
|
||||
coreModule.setMainWindowVisible(!startMinimized);
|
||||
})();
|
||||
|
|
|
@ -1,106 +0,0 @@
|
|||
import * as electron from "electron"
|
||||
import * as net from "net"
|
||||
import * as path from "path"
|
||||
import * as fs from "fs"
|
||||
import * as os from "os"
|
||||
import * as buildinfo from "./buildInfo"
|
||||
|
||||
function deleteSocketFile(socketPath) {
|
||||
if (process.platform === 'win32') {
|
||||
return;
|
||||
}
|
||||
|
||||
if (fs.existsSync(socketPath)) {
|
||||
try {
|
||||
fs.unlinkSync(socketPath);
|
||||
} catch (error) {
|
||||
// Ignore ENOENT errors in case the file was deleted between the exists
|
||||
// check and the call to unlink sync. This occurred occasionally on CI
|
||||
// which is why this check is here.
|
||||
if (error.code !== 'ENOENT') {
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates server to listen for additional atom application launches.
|
||||
*
|
||||
* You can run the command multiple times, but after the first launch
|
||||
* the other launches will just pass their information to this server and then
|
||||
* close immediately.
|
||||
*/
|
||||
function listenForArgumentsFromNewProcess(socketPath, callback) {
|
||||
deleteSocketFile(socketPath);
|
||||
|
||||
const server = net.createServer(connection => {
|
||||
connection.on('data', data => {
|
||||
const args = JSON.parse(data.toString());
|
||||
callback(args);
|
||||
});
|
||||
});
|
||||
server.listen(socketPath);
|
||||
server.on('error', error => console.error('Application server failed', error));
|
||||
return server;
|
||||
}
|
||||
|
||||
function tryStart(socketPath, callback, otherAppFound) {
|
||||
// FIXME: Sometimes when socketPath doesn't exist, net.connect would strangely
|
||||
// take a few seconds to trigger 'error' event, it could be a bug of node
|
||||
// or atom-shell, before it's fixed we check the existence of socketPath to
|
||||
// speedup startup.
|
||||
if (process.platform !== 'win32' && !fs.existsSync(socketPath)) {
|
||||
callback();
|
||||
return;
|
||||
}
|
||||
|
||||
const client = net.connect({ path: socketPath }, () => {
|
||||
client.write(JSON.stringify(process.argv.slice(1)), () => {
|
||||
client.end();
|
||||
otherAppFound();
|
||||
});
|
||||
});
|
||||
client.on('error', callback);
|
||||
}
|
||||
|
||||
function makeSocketPath() {
|
||||
let name = electron.app.name ? electron.app.name : electron.app.getName();
|
||||
if (buildinfo.releaseChannel !== 'stable') {
|
||||
name += buildinfo.releaseChannel;
|
||||
}
|
||||
|
||||
if (process.platform === 'win32') {
|
||||
return '\\\\.\\pipe\\' + name + '-sock';
|
||||
} else {
|
||||
return path.join(os.tmpdir(), name + '.sock');
|
||||
}
|
||||
}
|
||||
|
||||
export function create(startCallback, newProcessCallback) {
|
||||
const socketPath = makeSocketPath();
|
||||
|
||||
tryStart(socketPath, () => {
|
||||
const server = listenForArgumentsFromNewProcess(socketPath, newProcessCallback);
|
||||
|
||||
electron.app.on('will-quit', () => {
|
||||
server.close();
|
||||
deleteSocketFile(socketPath);
|
||||
});
|
||||
|
||||
//@ts-ignore
|
||||
electron.app.on('will-exit', () => {
|
||||
server.close();
|
||||
deleteSocketFile(socketPath);
|
||||
});
|
||||
|
||||
startCallback();
|
||||
}, () => {
|
||||
console.log('Another instance exists. Quitting.');
|
||||
electron.app.exit(0);
|
||||
});
|
||||
}
|
||||
|
||||
export function pipeCommandLineArgs(noOtherAppFoundCallback, otherAppFound) {
|
||||
tryStart(makeSocketPath(), noOtherAppFoundCallback, otherAppFound);
|
||||
}
|
|
@ -2,7 +2,6 @@ import * as electron from "electron"
|
|||
import {EventEmitter} from "events"
|
||||
import * as fs from "fs"
|
||||
import * as path from "path"
|
||||
import * as url from "url"
|
||||
import * as moduleUpdater from "./common/moduleUpdater"
|
||||
import * as paths from "./common/paths"
|
||||
import * as ipcMain from "./ipcMain"
|
||||
|
@ -10,7 +9,7 @@ import * as ipcMain from "./ipcMain"
|
|||
// citron note: atom seems to add about 50px height to the frame on mac but not windows
|
||||
// TODO: see if we can eliminate fudge by using useContentSize BrowserWindow option
|
||||
const LOADING_WINDOW_WIDTH = 300;
|
||||
const LOADING_WINDOW_HEIGHT = process.platform == 'darwin' ? 300 : 350;
|
||||
const LOADING_WINDOW_HEIGHT = process.platform === 'darwin' ? 300 : 350;
|
||||
|
||||
// TODO: addModulesListener events should use Module's constants
|
||||
const UPDATE_CHECK_FINISHED = 'update-check-finished';
|
||||
|
@ -103,7 +102,7 @@ function launchSplashWindow(startMinimized = false) {
|
|||
show: false,
|
||||
webPreferences: {
|
||||
nodeIntegration: true,
|
||||
|
||||
enableRemoteModule: true
|
||||
},
|
||||
icon: path.join(__dirname, "..", "discord.png")
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue