Skip to content

Commit

Permalink
Merge pull request #220 from BetterDiscord/development
Browse files Browse the repository at this point in the history
Merge Development
  • Loading branch information
zerebos authored Oct 19, 2021
2 parents 1bf733d + 97f5037 commit 1b020b8
Show file tree
Hide file tree
Showing 28 changed files with 2,622 additions and 2,158 deletions.
11 changes: 6 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ These will link you to the latest builds found in the [releases](https://github.
## Prerequisites
- [Git](https://git-scm.com)
- [Node.js](https://nodejs.org/en/) with `npm`.
- [Node.js](https://nodejs.org/en/)
- [yarn](https://yarnpkg.com)
- Command line of your choice.

## Building
Expand All @@ -79,27 +80,27 @@ This will create a local copy of this repository and navigate you to the root fo
### 2: Install Dependencies
Run this command at the root folder to install dependencies:
```ps
npm i
yarn install
```

### 3: Run Build Script
To run the installer in development mode, simply run the following command:
```ps
npm run dev
yarn dev
```

## Additional Scripts

### Linting
This project uses [ESLint](https://eslint.org/). Run this command to lint your changes:
```ps
npm run lint
yarn lint
```

### Compiling & Distribution

```ps
npm run dist
yarn dist
```

---
Expand Down
29 changes: 25 additions & 4 deletions assets/license.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,28 @@
Copyright (c) 2017 - Present BetterDiscord
End-User License Agreement for BetterDiscord

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
PLEASE READ THIS AGREEMENT CAREFULLY. IT CONTAINS IMPORTANT TERMS THAT AFFECT YOU AND YOUR USE OF THE SOFTWARE. BY INSTALLING, COPYING OR USING THE SOFTWARE, YOU AGREE TO BE BOUND BY THE TERMS OF THIS AGREEMENT. IF YOU DO NOT AGREE TO THESE TERMS, DO NOT INSTALL, COPY, OR USE THE SOFTWARE.

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
This End-User License Agreement (EULA) is a legal agreement between you--either an individual or a single entity--and the author(s) of this Software for the product identified above, which includes computer software and may include associated media, and online or electronic documentation ("Software").

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
By installing, copying, or otherwise using the Software, you agree to be bounded by the terms of this EULA.
If you do not agree to the terms of this EULA, do not install or use the Software.


1. GRANT OF LICENSE.
This EULA grants you a non-exclusive, non-sublicensable, non-transferable license to install and use the Software. You may install and use an unlimited number of copies of the Software.

You may reproduce and distribute an unlimited number of copies of the Software; provided that each copy shall be a true and complete copy, including all copyright and trademark notices.

Without prejudice to any other rights, the author(s) of this Software may terminate this EULA if you fail to comply with the terms and conditions of this EULA. In such event, you must destroy all copies of the Software and all of its component parts.


2. COPYRIGHT.
All title and copyrights in and to the Software (including but not limited to any images, libraries, and examples incorporated into the Software), the accompanying documentation, and any copies of the Software are owned by the author(s) of this Software.


3. NO WARRANTIES.
The author(s) of this Software expressly disclaims any warranty for the Software. The Software and any related documentation is provided "as is" without warranty of any kind, either express or implied, including, without limitation, the implied warranties or merchantability, fitness for a particular purpose, or noninfringement. The entire risk arising out of use or performance of the Software remains with you.


4. NO LIABILITY FOR DAMAGES.
In no event shall the author(s) of this Software be liable for any special, consequential, incidental or indirect damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or any other pecuniary loss) arising out of the use of or inability to use this product, even if the author(s) of this Software is aware of the possibility of such damages and known defects.
8 changes: 3 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"dist:dir": "yarn dist --dir -c.compression=store -c.mac.identity=null"
},
"dependencies": {
"semver": "^7.3.5",
"source-map-support": "^0.5.16"
},
"devDependencies": {
Expand All @@ -26,8 +27,8 @@
"eslint-plugin-svelte3": "^3.1.2",
"find-process": "^1.4.4",
"focus-visible": "^5.2.0",
"phin": "^3.5.1",
"svelte": "^3.35.0",
"phin": "^3.6.0",
"svelte": "^3.38.2",
"svelte-loader": "^3.0.0",
"svelte-spa-router": "^3.1.0",
"tree-kill": "^1.2.2",
Expand All @@ -39,7 +40,6 @@
"productName": "BetterDiscord",
"copyright": "Copyright © 2021 BetterDiscord",
"afterAllArtifactBuild": "scripts/fixmac.js",

"win": {
"artifactName": "${productName}-Windows.${ext}",
"icon": "assets/icon.ico",
Expand All @@ -54,7 +54,6 @@
"requestExecutionLevel": "user",
"useZip": true
},

"mac": {
"artifactName": "${productName}-Mac.${ext}",
"icon": "assets/icon.icns",
Expand All @@ -66,7 +65,6 @@
]
}
},

"linux": {
"artifactName": "${productName}-Linux.${ext}",
"category": "Utility",
Expand Down
8 changes: 5 additions & 3 deletions src/main/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {app, BrowserWindow, ipcMain} from "electron";
import {app, BrowserWindow, shell} from "electron";
import path from "path";
import URL from "url";
import updateInstaller from "./update_installer";

const isDevelopment = process.env.NODE_ENV !== "production";
app.name = "BetterDiscord";
Expand Down Expand Up @@ -54,7 +55,7 @@ function createMainWindow() {

window.webContents.on("new-window", (e, url) => {
e.preventDefault();
require("electron").shell.openExternal(url);
shell.openExternal(url);
});

return window;
Expand All @@ -73,6 +74,7 @@ app.on("activate", () => {
});

// create main BrowserWindow when electron is ready
app.on("ready", () => {
app.on("ready", async () => {
mainWindow = createMainWindow();
if (!process.env.BD_SKIP_UPDATECHECK) updateInstaller();
});
45 changes: 45 additions & 0 deletions src/main/update_installer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import {dialog, shell} from "electron";
import phin from "phin";
const semverGreaterThan = require("semver/functions/gt");
const {version} = require("../../package.json");

const getJSON = phin.defaults({
method: "GET",
parse: "json",
headers: {"User-Agent": "BetterDiscord Installer"},
followRedirects: true
});

export default async function () {
const downloadUrl = "https://api.github.com/repos/BetterDiscord/Installer/releases";
console.info(`Better Discord Installer ${version}`);

try {
const response = await getJSON(downloadUrl);
const latestRelease = response.body[0];
const latestVersion = latestRelease.tag_name;

if (semverGreaterThan(latestVersion, version)) {
console.info(`Found new release ${latestVersion}`);

const result = await dialog.showMessageBox({
title: "New Installer Version Available",
message: `A new version of the BetterDiscord installer is available. Click "Download" to download the newest version.`,
buttons: ["Download", "Later"],
defaultId: 0,
cancelId: 1
});

if (result.response === 0) {
await shell.openExternal(latestRelease.html_url);
process.exit(0);
}

} else {
console.info(`The installer is up to date.`);
}
}
catch (err) {
console.error("Failed to check for updates.", err);
}
}
31 changes: 20 additions & 11 deletions src/renderer/App.svelte
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
<script>
import "focus-visible";
// import Page from "./containers/Page.svelte";
import Titlebar from "./common/Titlebar.svelte";
import Footer from "./common/Footer.svelte";
import Router from "svelte-spa-router";
import routes from "./routes";
require("focus-visible");
</script>

<div class="main-window platform-{process.platform}">
{#if process.platform == "darwin"}
<Titlebar macButtons />
{:else}
<Titlebar />
{/if}
<div class="main-window platform-{process.platform || "win32"}">
<Titlebar macButtons={process.platform === "darwin"} />
<main class="installer-body">
<div class="sections">
<Router {routes} />
Expand All @@ -22,25 +19,37 @@
</div>

<style>
@import url('https://rsms.me/inter/inter.css');
@import url("https://rsms.me/inter/inter.css");
:global(.focus-visible) {
:global([data-focus-visible-added]) {
box-shadow: 0 0 0 4px var(--accent-faded) !important;
}
:root {
/* Primary backgrounds */
--bg1: #040405;
--bg2: #0c0d10;
--bg2-alt: #101116;
--bg3: #14151b;
--bg3-alt: #191a21;
--bg4: #20212b;
/* Text Colors */
--text-light: #f1f1f1;
--text-normal: #bfc4c9;
--text-muted: #95989d;
--text-link: #5a88ce;
/* Accent colors */
--accent: #3a71c1;
--accent-hover: #2f5b9d;
--accent-faded: rgba(58, 113, 193, .4);
--accent-faded: rgba(58, 113, 193, 0.4);
/* Danger colors */
--danger: #c13a3a;
--danger-hover: #992e2e;
--danger-faded: rgb(193, 58, 58, 0.4);
}
:global(html),
Expand Down Expand Up @@ -127,7 +136,7 @@
}
.installer-body::after {
content: '';
content: "";
position: absolute;
top: 0;
left: 0;
Expand Down
6 changes: 3 additions & 3 deletions src/renderer/actions/install.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,15 @@ async function makeDirectories(...folders) {
}
}

const getJSON = phin.defaults({method: "GET", parse: "json", headers: {"User-Agent": "BetterDiscord Installer"}});
const getJSON = phin.defaults({method: "GET", parse: "json", followRedirects: true, headers: {"User-Agent": "BetterDiscord Installer"}});
const downloadFile = phin.defaults({method: "GET", followRedirects: true, headers: {"User-Agent": "BetterDiscord Installer", "Accept": "application/octet-stream"}});
const asarPath = path.join(bdDataFolder, "betterdiscord.asar");
async function downloadAsar() {
let downloadUrl = "https://api.github.com/repos/rauenzi/BetterDiscordApp/releases";
let downloadUrl = "https://api.github.com/repos/BetterDiscord/BetterDiscord/releases";
try {
const response = await getJSON(downloadUrl);
const releases = response.body;
const asset = releases[0].assets.find(a => a.name === "betterdiscord.asar");
const asset = releases && releases.length ? releases[0].assets.find(a => a.name === "betterdiscord.asar") : "https://api.github.com/repos/BetterDiscord/BetterDiscord/releases/assets/39982244"; // temporary workaround
downloadUrl = asset.url;

const resp = await downloadFile(downloadUrl);
Expand Down
8 changes: 4 additions & 4 deletions src/renderer/actions/paths.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const getDiscordPath = function(releaseChannel) {
if (process.platform === "win32") {
const basedir = path.join(process.env.LOCALAPPDATA, releaseChannel.replace(/ /g, ""));
if (!fs.existsSync(basedir)) return "";
const version = fs.readdirSync(basedir).filter(f => fs.lstatSync(path.join(basedir, f)).isDirectory() && f.split(".").length > 1).sort().reverse()[0];
const version = fs.readdirSync(basedir).filter(f => fs.lstatSync(path.join(basedir, f)).isDirectory() && f.split(".").length > 1).sort()[0];
if (!version) return "";
resourcePath = path.join(basedir, version, "resources");
}
Expand All @@ -20,7 +20,7 @@ const getDiscordPath = function(releaseChannel) {
else {
const basedir = path.join(remote.app.getPath("userData"), "..", releaseChannel.toLowerCase().replace(" ", ""));
if (!fs.existsSync(basedir)) return "";
const version = fs.readdirSync(basedir).filter(f => fs.lstatSync(path.join(basedir, f)).isDirectory() && f.split(".").length > 1).sort().reverse()[0];
const version = fs.readdirSync(basedir).filter(f => fs.lstatSync(path.join(basedir, f)).isDirectory() && f.split(".").length > 1).sort()[0];
if (!version) return "";
resourcePath = path.join(basedir, version, "modules", "discord_desktop_core");
}
Expand Down Expand Up @@ -55,7 +55,7 @@ const validateWindows = function(channel, proposedPath) {
const selected = path.basename(proposedPath);
const isBaseDir = selected === channelName;
if (isBaseDir) {
const version = fs.readdirSync(proposedPath).filter(f => fs.lstatSync(path.join(proposedPath, f)).isDirectory() && f.split(".").length > 1).sort().reverse()[0];
const version = fs.readdirSync(proposedPath).filter(f => fs.lstatSync(path.join(proposedPath, f)).isDirectory() && f.split(".").length > 1).sort()[0];
if (!version) return "";
resourcePath = path.join(proposedPath, version, "resources");
}
Expand Down Expand Up @@ -90,7 +90,7 @@ const validateLinux = function(channel, proposedPath) {
let resourcePath = "";
const selected = path.basename(proposedPath);
if (selected === channelName) {
const version = fs.readdirSync(proposedPath).filter(f => fs.lstatSync(path.join(proposedPath, f)).isDirectory() && f.split(".").length > 1).sort().reverse()[0];
const version = fs.readdirSync(proposedPath).filter(f => fs.lstatSync(path.join(proposedPath, f)).isDirectory() && f.split(".").length > 1).sort()[0];
if (!version) return "";
resourcePath = path.join(proposedPath, version, "modules", "discord_desktop_core");
}
Expand Down
25 changes: 16 additions & 9 deletions src/renderer/common/Button.svelte
Original file line number Diff line number Diff line change
@@ -1,16 +1,23 @@
<script>
export let type = "secondary";
export let disabled = false;
const types = ["primary", "secondary"];
</script>

<button type="button"{disabled} on:keypress on:click|preventDefault|stopPropagation class="btn {(type == "primary" || type == "secondary") ? type : "secondary"}">
<button
class="button {types.includes(type) ? `type-${type}` : "type-secondary"}"
type="button"
on:keypress
on:click|preventDefault|stopPropagation
{...$$restProps}
>
<span>
<slot></slot>
</span>
</button>

<style>
.btn {
.button {
width: auto;
border: none;
display: flex;
Expand All @@ -27,34 +34,34 @@
border-radius: 2px;
}
.btn[disabled] {
.button[disabled] {
opacity: .5;
pointer-events: none;
}
.btn span {
.button span {
max-width: 100%;
overflow: hidden;
text-overflow: ellipsis;
}
.btn.primary {
.button.type-primary {
border: 1px solid transparent;
background-color: var(--accent);
color: #ffffff;
}
.btn.primary:hover {
.button.type-primary:hover {
background-color: var(--accent-hover);
}
.btn.secondary {
.button.type-secondary {
background-color: transparent;
border: 1px solid rgba(255, 255, 255, 0.05);
color: var(--text-normal);
}
.btn.secondary:hover {
.button.type-secondary:hover {
border-color: rgba(255, 255, 255, 0.1);
}
</style>
Loading

0 comments on commit 1b020b8

Please sign in to comment.