mirror of
https://github.com/smartfrigde/armcord.git
synced 2024-08-14 23:56:58 +00:00
Getting ready for 3.0
This commit is contained in:
parent
521278cf00
commit
1debbe60fe
14 changed files with 4036 additions and 154 deletions
|
@ -7,6 +7,6 @@
|
|||
font-size: 12px;
|
||||
text-transform: none;
|
||||
}
|
||||
.notice-3bPHh-.colorDefault-22HBa0 {
|
||||
display: none;
|
||||
.notice-2HEN-u {
|
||||
display: none;
|
||||
}
|
|
@ -22,24 +22,7 @@
|
|||
</div>
|
||||
</div>
|
||||
<script>
|
||||
function discord() {
|
||||
switch (window.armcord.channel) {
|
||||
case "stable":
|
||||
window.location.href = "https://discord.com/app";
|
||||
break;
|
||||
case "canary":
|
||||
window.location.href = "https://canary.discord.com/app";
|
||||
break;
|
||||
case "ptb":
|
||||
window.location.href = "https://ptb.discord.com/app";
|
||||
break;
|
||||
case "foss":
|
||||
window.location.href = "https://dev.fosscord.com/app";
|
||||
break;
|
||||
default:
|
||||
window.location.href = "https://discord.com/app";
|
||||
}
|
||||
}
|
||||
|
||||
function fade(element) {
|
||||
var op = 1; // initial opacity
|
||||
var timer = setInterval(function () {
|
||||
|
@ -58,6 +41,13 @@
|
|||
"You appear to be offline. Please connect to the internet and restart ArmCord Setup.";
|
||||
} else {
|
||||
console.log("Starting ArmCord Setup...");
|
||||
document.getElementById("express").addEventListener("click", function () {
|
||||
window.armcord.saveSettings(true, "stable", true, "cumcord");
|
||||
fade(document.getElementById("setup"));
|
||||
setTimeout(function () {
|
||||
window.armcord.restart()
|
||||
}, 5000);
|
||||
})
|
||||
document.getElementById("full").addEventListener("click", function () {
|
||||
document.getElementById("setup").innerHTML = `
|
||||
<p class="text-center setup-ask">Choose your Discord channel/instance:</p>
|
||||
|
@ -103,8 +93,7 @@
|
|||
window.armcord.saveSettings(true, branch, true, mod);
|
||||
fade(document.getElementById("setup"));
|
||||
setTimeout(function () {
|
||||
window.armcord.splashEnd();
|
||||
discord();
|
||||
window.armcord.restart();
|
||||
}, 5000);
|
||||
});
|
||||
} else {
|
||||
|
@ -112,8 +101,7 @@
|
|||
window.armcord.saveSettings(true, branch, true, "none");
|
||||
fade(document.getElementById("setup"));
|
||||
setTimeout(function () {
|
||||
window.armcord.splashEnd();
|
||||
discord();
|
||||
window.armcord.restart()
|
||||
}, 5000);
|
||||
}
|
||||
});
|
||||
|
|
49
src/main.ts
49
src/main.ts
|
@ -1,31 +1,26 @@
|
|||
// Modules to control application life and create native browser window
|
||||
import { app, BrowserWindow, ipcMain, shell, desktopCapturer } from "electron";
|
||||
import { app, BrowserWindow, ipcMain, shell, desktopCapturer, session } from "electron";
|
||||
import * as path from "path";
|
||||
import "v8-compile-cache";
|
||||
import * as storage from "electron-json-storage";
|
||||
import { saveSettings } from "./utils";
|
||||
import { saveSettings, getVersion, setup } from "./utils";
|
||||
import "./extensions/mods";
|
||||
import "./extensions/plugin";
|
||||
import "./tray";
|
||||
import "./shortcuts";
|
||||
var contentPath: string = "null";
|
||||
var frame: boolean;
|
||||
var channel: string;
|
||||
var titlebar: boolean;
|
||||
export var mainWindow: BrowserWindow;
|
||||
var settings:any;
|
||||
storage.keys(function (error, keys) {
|
||||
if (error) throw error;
|
||||
var settings: any;
|
||||
|
||||
for (var key of keys) {
|
||||
console.log("There is a key called: " + key);
|
||||
}
|
||||
});
|
||||
storage.has("settings", function (error, hasKey) {
|
||||
if (error) throw error;
|
||||
|
||||
if (!hasKey) {
|
||||
console.log("First run of the ArmCord. Starting setup.");
|
||||
// setup(); will be done at setup
|
||||
setup();
|
||||
contentPath = __dirname + "/content/setup.html";
|
||||
} else {
|
||||
console.log("ArmCord has been run before. Skipping setup.");
|
||||
|
@ -80,17 +75,22 @@ function createWindow() {
|
|||
mainWindow.hide();
|
||||
});
|
||||
ipcMain.on("get-app-version", (event) => {
|
||||
event.returnValue = process.env.npm_package_version;
|
||||
event.returnValue = getVersion();
|
||||
});
|
||||
ipcMain.on("splashEnd", (event, arg) => {
|
||||
mainWindow.setSize(800, 600);
|
||||
});
|
||||
ipcMain.on("restart", (event, arg) => {
|
||||
app.relaunch();
|
||||
app.exit();
|
||||
|
||||
});
|
||||
|
||||
ipcMain.on("saveSettings", (event, ...args) => {
|
||||
//@ts-ignore
|
||||
saveSettings(...args);
|
||||
});
|
||||
ipcMain.on("channel", (event) => {
|
||||
|
||||
event.returnValue = channel;
|
||||
});
|
||||
ipcMain.on("clientmod", (event, arg) => {
|
||||
|
@ -122,7 +122,32 @@ function createWindow() {
|
|||
|
||||
app.whenReady().then(() => {
|
||||
createWindow();
|
||||
session
|
||||
.fromPartition("some-partition")
|
||||
.setPermissionRequestHandler((webContents, permission, callback) => {
|
||||
const url = webContents.getURL(); //unused?
|
||||
|
||||
if (permission === "notifications") {
|
||||
// Approves the permissions request
|
||||
callback(true);
|
||||
}
|
||||
if (permission === "media") {
|
||||
// Approves the permissions request
|
||||
callback(true);
|
||||
}
|
||||
if (url.startsWith("discord://")) {
|
||||
// Denies the permissions request
|
||||
return callback(false);
|
||||
}
|
||||
if (url.startsWith("discord.com/science")) {
|
||||
// Denies the permissions request
|
||||
return callback(false);
|
||||
}
|
||||
if (url.startsWith("discord.com/tracing")) {
|
||||
// Denies the permissions request
|
||||
return callback(false);
|
||||
}
|
||||
});
|
||||
app.on("activate", function () {
|
||||
if (BrowserWindow.getAllWindows().length === 0) createWindow();
|
||||
});
|
||||
|
|
|
@ -10,12 +10,12 @@ contextBridge.exposeInMainWorld("armcord", {
|
|||
maximize: () => ipcRenderer.send("win-maximize"),
|
||||
},
|
||||
electron: process.versions.electron,
|
||||
channel: ipcRenderer.sendSync('channel'),
|
||||
channel: ipcRenderer.sendSync("channel"),
|
||||
version: ipcRenderer.sendSync("get-app-version", "app-version"),
|
||||
getDisplayMediaSelector: getDisplayMediaSelector,
|
||||
restart: () => ipcRenderer.send("restart"),
|
||||
saveSettings: (...args: any) => ipcRenderer.send("saveSettings", ...args),
|
||||
splashEnd: () => ipcRenderer.send("splashEnd"),
|
||||
loadDiscord: () => ipcRenderer.send("loadDiscord"),
|
||||
});
|
||||
contextBridge.exposeInMainWorld("electron", {
|
||||
//deprecated, used for legacy purposes, will be removed in future versions
|
||||
|
|
35
src/shortcuts.ts
Normal file
35
src/shortcuts.ts
Normal file
|
@ -0,0 +1,35 @@
|
|||
|
||||
import { Menu, MenuItem } from "electron";
|
||||
import { mainWindow } from "./main";
|
||||
const menu = new Menu();
|
||||
menu.append(
|
||||
new MenuItem({
|
||||
label: "ArmCord" + process.env.npm_package_version,
|
||||
submenu: [
|
||||
{
|
||||
role: "toggleDevTools",
|
||||
accelerator:
|
||||
process.platform === "darwin" ? "Ctrl+Cmd+I" : "Ctrl+Shift+I",
|
||||
click: () => {
|
||||
mainWindow.webContents.toggleDevTools();
|
||||
},
|
||||
},
|
||||
{
|
||||
role: "toggleDevTools",
|
||||
accelerator: "F12",
|
||||
click: () => {
|
||||
mainWindow.webContents.toggleDevTools();
|
||||
},
|
||||
},
|
||||
{
|
||||
role: "reload",
|
||||
accelerator:
|
||||
"Ctrl+F5",
|
||||
click: () => {
|
||||
mainWindow.webContents.reload();
|
||||
},
|
||||
},
|
||||
],
|
||||
})
|
||||
);
|
||||
Menu.setApplicationMenu(menu);
|
|
@ -1,4 +1,4 @@
|
|||
import { app, Menu, Tray, ipcRenderer } from 'electron';
|
||||
import { app, Menu, Tray } from 'electron';
|
||||
import {mainWindow} from './main';
|
||||
let tray = null
|
||||
app.whenReady().then(() => {
|
||||
|
@ -24,6 +24,7 @@ app.whenReady().then(() => {
|
|||
},
|
||||
},
|
||||
]);
|
||||
|
||||
tray.setToolTip('ArmCord' + process.env.npm_package_version)
|
||||
tray.setContextMenu(contextMenu)
|
||||
})
|
65
src/utils.ts
65
src/utils.ts
|
@ -1,29 +1,58 @@
|
|||
|
||||
import * as storage from 'electron-json-storage';
|
||||
import * as fs from "fs";
|
||||
import * as storage from "electron-json-storage";
|
||||
//utillity functions that are used all over the codebase or just too obscure to be put in the file used in
|
||||
export function addStyle(styleString: string) {
|
||||
const style = document.createElement('style');
|
||||
style.textContent = styleString;
|
||||
document.head.append(style);
|
||||
};
|
||||
const style = document.createElement("style");
|
||||
style.textContent = styleString;
|
||||
document.head.append(style);
|
||||
}
|
||||
|
||||
export function addScript(scriptString: string) {
|
||||
var script = document.createElement("script");
|
||||
script.textContent = scriptString;
|
||||
document.body.append(script);
|
||||
};
|
||||
export function setup(){
|
||||
console.log("Setting up ArmCord settings.");
|
||||
storage.set('settings', { customTitlebar: true, channel: 'stable', firstRun: 'done', armcordCSP: true }, function(error) {
|
||||
if (error) throw error;
|
||||
});
|
||||
}
|
||||
export async function sleep(ms:number) {
|
||||
return new Promise(resolve => setTimeout(resolve, ms));
|
||||
}
|
||||
export function saveSettings(customTitlebarSetting: boolean, channelSetting: string, armcordCSPSetting: boolean, modsSetting: string) {
|
||||
export function setup() {
|
||||
console.log("Setting up ArmCord settings.");
|
||||
storage.set('settings', { customTitlebar: customTitlebarSetting, channel: channelSetting, firstRun: 'done', armcordCSP: armcordCSPSetting, mods: modsSetting }, function(error) {
|
||||
storage.set(
|
||||
"settings",
|
||||
{
|
||||
customTitlebar: true,
|
||||
channel: "stable",
|
||||
firstRun: "done",
|
||||
armcordCSP: true,
|
||||
},
|
||||
function (error) {
|
||||
if (error) throw error;
|
||||
});
|
||||
}
|
||||
);
|
||||
}
|
||||
export async function sleep(ms: number) {
|
||||
return new Promise((resolve) => setTimeout(resolve, ms));
|
||||
}
|
||||
export function saveSettings(
|
||||
customTitlebarSetting: boolean,
|
||||
channelSetting: string,
|
||||
armcordCSPSetting: boolean,
|
||||
modsSetting: string
|
||||
) {
|
||||
console.log("Setting up ArmCord settings.");
|
||||
storage.set(
|
||||
"settings",
|
||||
{
|
||||
customTitlebar: customTitlebarSetting,
|
||||
channel: channelSetting,
|
||||
firstRun: "done",
|
||||
armcordCSP: armcordCSPSetting,
|
||||
mods: modsSetting,
|
||||
},
|
||||
function (error) {
|
||||
if (error) throw error;
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
export function getVersion() {
|
||||
const pkgjson = fs.readFileSync("./package.json", "utf8");
|
||||
return JSON.parse(pkgjson).version;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue