Skip to content

Commit

Permalink
smol tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
Milkshiift committed May 9, 2023
1 parent 91d053f commit 20337c2
Show file tree
Hide file tree
Showing 10 changed files with 121 additions and 157 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ Otherwise donwload source code using big green button on top of the page and ext
### How can I access the settings?
- Multiple ways:
- Right-click on the tray icon and click `Open Settings`
- Open Discord settings and scroll down until you see information about versions. Click on the ArmCord version and the settings window will pop out.
- Open Discord settings and scroll down until you see information about versions. Click on the GoofCord version and the settings window will pop out.
- Press `Ctrl+Shift+'` shortcut.

### Where can I find the source code?
Expand Down
8 changes: 3 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "goofcord",
"name": "GoofCord",
"version": "0.5.1",
"description": "GoofCord is a custom client designed to enhance your Discord experience while keeping everything lightweight.",
"main": "ts-out/main.js",
Expand Down Expand Up @@ -44,7 +44,6 @@
"include": "build/installer.nsh"
},
"appId": "com.milkshift.goofcord",
"compression": "maximum",
"productName": "GoofCord",
"files": [
"!*",
Expand All @@ -65,16 +64,15 @@
"category": "Network"
},
"win": {
"target": "nsis"
"target": ["nsis","zip"]
},
"linux": {
"icon": "build/icon.icns",
"icon": "build/icon.png",
"category": "Network",
"maintainer": "[email protected]",
"target": [
"deb",
"tar.gz",
"rpm",
"AppImage"
]
}
Expand Down
128 changes: 64 additions & 64 deletions src/content/css/titlebar.css

Large diffs are not rendered by default.

3 changes: 1 addition & 2 deletions src/ipc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import {app, desktopCapturer, ipcMain, nativeImage, shell} from "electron";
import {mainWindow} from "./window";
import {getConfig, getDisplayVersion, getVersion, getWindowState, packageVersion, setConfigBulk} from "./utils";
import {customTitlebar} from "./main";
import {createSettingsWindow} from "./settings/main";
import os from "os";
import path from "path";
Expand Down Expand Up @@ -93,7 +92,7 @@ export function registerIpc() {
event.returnValue = await getConfig("minimizeToTray");
});
ipcMain.on("titlebar", (event) => {
event.returnValue = customTitlebar;
event.returnValue = true;
});
ipcMain.on("openSettingsWindow", () => {
createSettingsWindow();
Expand Down
58 changes: 26 additions & 32 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,45 +9,39 @@ import {createCustomWindow} from "./window";
import path from "path";

export var iconPath: string;
export var customTitlebar: boolean;
export var clientName: "GoofCord";

if (!app.requestSingleInstanceLock()) {
// kill if 2nd instance
app.quit();
} else {
// Your data now belongs to CCP
crashReporter.start({uploadToServer: false});
}
// Your data now belongs to CCP
crashReporter.start({uploadToServer: false});

autoUpdater.checkForUpdatesAndNotify();
autoUpdater.checkForUpdatesAndNotify();

app.commandLine.appendSwitch("disable-features", "OutOfBlinkCors");
app.commandLine.appendSwitch("enable-features", "WebRTC");
checkConfig();
checkIfWhitelistIsNotEmpty();
checkIfConfigExists();
app.whenReady().then(async () => {
iconPath = path.join(__dirname, "../", "/assets/ac_icon_transparent.png");
app.commandLine.appendSwitch("disable-features", "OutOfBlinkCors");
app.commandLine.appendSwitch("enable-features", "WebRTC");
checkConfig();
checkIfWhitelistIsNotEmpty();
checkIfConfigExists();
app.whenReady().then(async () => {
iconPath = path.join(__dirname, "../", "/assets/ac_icon_transparent.png");

async function init() {
await createCustomWindow();
customTitlebar = true;
await createCustomWindow();
await installModLoader();
session.fromPartition("some-partition").setPermissionRequestHandler((webContents, permission, callback) => {
if (permission === "notifications") {
// Approves the permissions request
callback(true);
}
if (permission === "media") {
// Approves the permissions request
callback(true);
}

await init();
await installModLoader();
session.fromPartition("some-partition").setPermissionRequestHandler((webContents, permission, callback) => {
if (permission === "notifications") {
// Approves the permissions request
callback(true);
}
if (permission === "media") {
// Approves the permissions request
callback(true);
}
});
app.on("activate", async function () {
if (BrowserWindow.getAllWindows().length === 0) await init();
});
});
}
app.on("activate", async function () {
if (BrowserWindow.getAllWindows().length === 0) await createCustomWindow();
});
});

2 changes: 1 addition & 1 deletion src/preload/bridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ interface IPCSources {
thumbnail: HTMLCanvasElement;
}

contextBridge.exposeInMainWorld("armcord", {
contextBridge.exposeInMainWorld("goofcord", {
window: {
show: () => ipcRenderer.send("win-show"),
hide: () => ipcRenderer.send("win-hide"),
Expand Down
2 changes: 1 addition & 1 deletion src/preload/capturer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ window.navigator.mediaDevices.getDisplayMedia = () => new Promise(async (resolve
try {
const selectionElem = document.createElement('div');
selectionElem.classList = ['desktop-capturer-selection'];
selectionElem.innerHTML = await window.armcord.getDisplayMediaSelector();
selectionElem.innerHTML = await window.goofcord.getDisplayMediaSelector();
document.body.appendChild(selectionElem);
document
.querySelectorAll('.desktop-capturer-selection__btn')
Expand Down
4 changes: 2 additions & 2 deletions src/preload/preload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ sleep(5000).then(async () => {
set(onClick) {
originalSetter.call(this, function() {
onClick.apply(this, arguments);
armcord.window.show();
armcord.window.maximize();
goofcord.window.show();
goofcord.window.maximize();
})
},
configurable: true
Expand Down
2 changes: 1 addition & 1 deletion src/preload/titlebar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export function injectTitlebar() {
addStyle(fs.readFileSync(titlebarcssPath, "utf8"));
addStyle(fs.readFileSync(wordmarkcssPath, "utf8"));
document.body.setAttribute("customTitlebar", "");
document.body.setAttribute("armcord-platform", os.platform());
document.body.setAttribute("goofcord-platform", os.platform());

const minimize = document.getElementById("minimize");
const maximize = document.getElementById("maximize");
Expand Down
69 changes: 21 additions & 48 deletions src/window.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,20 @@
import {app, BrowserWindow, dialog, nativeImage, session, shell} from "electron";
import {checkIfConfigIsBroken, contentPath, getConfig, setConfig, setWindowState} from "./utils";
import {app, BrowserWindow, nativeImage, session, shell} from "electron";
import {checkIfConfigIsBroken, contentPath, getConfig, setWindowState} from "./utils";
import {registerIpc} from "./ipc";
import {setMenu} from "./menu";
import * as fs from "fs";
import contextMenu from "electron-context-menu";
import {tray} from "./tray";
import {iconPath} from "./main";
import {loadMods} from "./extensions/plugin";
import {type} from "os";

const path = require("path");

export let mainWindow: BrowserWindow;
//let osType = os.type();
contextMenu({
showSaveImageAs: true,
showCopyImageAddress: true,
showSearchWithGoogle: false
//showSearchWithDuckDuckGo: true
});

async function doAfterDefiningTheWindow() {
Expand All @@ -26,9 +23,9 @@ async function doAfterDefiningTheWindow() {
} else {
mainWindow.show();
}
const ignoreProtocolWarning = await getConfig("ignoreProtocolWarning");
await checkIfConfigIsBroken();
registerIpc();
await setMenu();
mainWindow.webContents.userAgent = `Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/${process.versions.chrome} Safari/537.36`;
app.on("second-instance", (event, commandLine, workingDirectory, additionalData) => {
// Print out data received from the second instance.
Expand All @@ -41,12 +38,7 @@ async function doAfterDefiningTheWindow() {
mainWindow.focus();
}
});
mainWindow.webContents.setWindowOpenHandler(({url}) => {
if (url.startsWith("https:") || url.startsWith("http:") || url.startsWith("mailto:")) {
shell.openExternal(url);
}
return {action: "deny"};
});

console.log("Starting screenshare module...");
import("./screenshare/main");

Expand Down Expand Up @@ -77,7 +69,6 @@ async function doAfterDefiningTheWindow() {
if (process.platform === "win32" && trayPath.getSize().height > 32) trayPath = trayPath.resize({height: 32});
tray.setImage(trayPath);
});
await setMenu();
mainWindow.on("close", async (e) => {
let [width, height] = mainWindow.getSize();
await setWindowState({
Expand All @@ -96,58 +87,44 @@ async function doAfterDefiningTheWindow() {
app.quit();
}
});

mainWindow.on("focus", () => {
mainWindow.webContents.executeJavaScript(`document.body.removeAttribute("unFocused");`);
});
mainWindow.on("blur", () => {
mainWindow.webContents.executeJavaScript(`document.body.setAttribute("unFocused", "");`);
});

mainWindow.on("maximize", () => {
mainWindow.webContents.executeJavaScript(`document.body.setAttribute("isMaximized", "");`);
});
mainWindow.on("unmaximize", () => {
mainWindow.webContents.executeJavaScript(`document.body.removeAttribute("isMaximized");`);
});
console.log(contentPath);

await mainWindow.loadFile(path.join(__dirname, "/content/splash.html"));
if (await getConfig("startMinimized")) {
mainWindow.hide();
} else {
mainWindow.show();
}
const disUrl = await getConfig("discordUrl");
await mainWindow.webContents
.executeJavaScript(
`
window.location.replace("${disUrl}");
`
)
.executeJavaScript(`window.location.replace("${disUrl}");`)
.then(async () => {
loadMods();

await mainWindow.webContents.executeJavaScript(`
const Logger = window.__SENTRY__.logger
Logger.disable()
`);
const Logger = window.__SENTRY__.logger
Logger.disable()
`);

const whiteList = await getConfig("whitelist");
const regexList = whiteList.map((url: string) => new RegExp(`^${url.replace(/\*/g, ".*")}`));

setTimeout(() => {
session.defaultSession.webRequest.onBeforeRequest({urls: ["<all_urls>"]}, async (details, callback) => {
const requestUrl = details.url;
const isAllowedUrl = regexList.some((regex: RegExp) => regex.test(requestUrl));
if (!isAllowedUrl) {
callback({cancel: true});
return;
} else {
callback({});
return;
}
});
}, 10);
session.defaultSession.webRequest.onBeforeRequest({urls: ["<all_urls>"]}, async (details, callback) => {
const requestUrl = details.url;
const isAllowedUrl = regexList.some((regex: RegExp) => regex.test(requestUrl));
if (!isAllowedUrl) {
callback({cancel: true});
return;
} else {
callback({});
return;
}
});
});
}

Expand All @@ -164,21 +141,17 @@ export async function createCustomWindow() {
autoHideMenuBar: true,
webPreferences: {
sandbox: false,
//preload: path.resolve(app.getAppPath(), 'preload/preload.js'),
preload: path.join(__dirname, "preload/preload.js"),
contextIsolation: true,
nodeIntegration: false, // https://electronjs.org/docs/tutorial/security#2-do-not-enable-nodejs-integration-for-remote-content
webviewTag: true,
nodeIntegrationInSubFrames: false,
webSecurity: true,
enableWebSQL: false,
webgl: false,
safeDialogs: true, // prevents dialog spam by the website
autoplayPolicy: "no-user-gesture-required",
plugins: true,
spellcheck: true,
devTools: true, // Allows the use of the devTools.
experimentalFeatures: false
devTools: true // Allows the use of the devTools.
}
});

Expand Down

0 comments on commit 20337c2

Please sign in to comment.