BetterDiscord / Installer

A simple standalone program which automates the installation, removal and maintenance of BetterDiscord.
https://betterdiscord.app
MIT License
1.77k stars 188 forks source link

Silent Install #372

Closed Obegg closed 4 months ago

Obegg commented 5 months ago

Is your feature request related to a problem? Please describe. No.

Describe the solution you'd like Solution 1 (Using BetterDiscord-Windows.exe):

(New-Object System.Net.WebClient).DownloadFile('https://github.com/BetterDiscord/Installer/releases/latest/download/BetterDiscord-Windows.exe', "$env:TEMP\BetterDiscord.exe")
Start-Process -FilePath "$env:TEMP\BetterDiscord.exe" -ArgumentList '/S'

Solution 2 (Using betterdiscord.asar):

(TODO: Learn how to install a .asar file using PowerShell)

Describe alternatives you've considered I tried a this https://github.com/BetterDiscord/Installer/issues/52#issuecomment-813924646 but I get the following error:

Join-Path : A positional parameter cannot be found that accepts argument 'app-0.0.309'.
At line:1 char:31
+ ... cordPath = (Join-Path $env:LOCALAPPDATA "Discord" "app-0.0.309" "reso ...
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (:) [Join-Path], ParentContainsErrorRecordException
    + FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.PowerShell.Commands.JoinPathCommand
Inve1951 commented 5 months ago

See https://github.com/BetterDiscord/cli for GUI-less installation.

Obegg commented 5 months ago

Thank you, very helpful.

Created a PowerShell script to install BetterDiscord with some plugins and themes:

Write-Host 'BetterDiscord: Closing Discord' -ForegroundColor green -BackgroundColor black
Get-Process Discord -ea 0 | ForEach-Object { $_.CloseMainWindow() | Out-Null }
Start-Sleep 1
Get-Process Discord -ea 0 | Stop-Process -Force

Write-Host 'BetterDiscord: Checking for folders' -ForegroundColor green -BackgroundColor black
if (!(Test-Path -Path $env:APPDATA\BetterDiscord)) {
    New-Item -Path $env:APPDATA\BetterDiscord -Value BetterDiscord -ItemType Directory
}
if (!(Test-Path -Path $env:APPDATA\BetterDiscord\plugins)) {
    New-Item -Path $env:APPDATA\BetterDiscord\plugins -Value plugins -ItemType Directory
}
if (!(Test-Path -Path $env:APPDATA\BetterDiscord\themes)) {
    New-Item -Path $env:APPDATA\BetterDiscord\themes -Value themes -ItemType Directory
}
if (!(Test-Path -Path "$env:APPDATA\BetterDiscord\data")) {
    New-Item -Path "$env:APPDATA\BetterDiscord\data" -Value 'data' -ItemType Directory
}
if (!(Test-Path -Path "$env:APPDATA\BetterDiscord\data\stable")) {
    New-Item -Path "$env:APPDATA\BetterDiscord\data\stable" -Value 'stable' -ItemType Directory
}

Write-Host 'BetterDiscord: Adding Theme: amoled-cord.css' -ForegroundColor green -BackgroundColor black
(New-Object System.Net.WebClient).DownloadFile('https://raw.githubusercontent.com/LuckFire/amoled-cord/main/clients/amoled-cord.theme.css', "$env:APPDATA\BetterDiscord\themes\amoled-cord.theme.css")

Write-Host 'BetterDiscord: Adding DoNotTrack.plugin.js' -ForegroundColor green -BackgroundColor black
(New-Object System.Net.WebClient).DownloadFile('https://raw.githubusercontent.com/rauenzi/BetterDiscordAddons/master/Plugins/DoNotTrack/DoNotTrack.plugin.js', "$env:APPDATA\BetterDiscord\plugins\DoNotTrack.plugin.js")

Write-Host 'BetterDiscord: Adding 0PluginLibrary.plugin.js (DoNotTrack)' -ForegroundColor green -BackgroundColor black
(New-Object System.Net.WebClient).DownloadFile('https://raw.githubusercontent.com/rauenzi/BDPluginLibrary/master/release/0PluginLibrary.plugin.js', "$env:APPDATA\BetterDiscord\plugins\0PluginLibrary.plugin.js")

Write-Host 'BetterDiscord: Adding PluginRepo.plugin.js' -ForegroundColor green -BackgroundColor black
(New-Object System.Net.WebClient).DownloadFile('https://raw.githubusercontent.com/mwittrien/BetterDiscordAddons/master/Plugins/PluginRepo/PluginRepo.plugin.js', "$env:APPDATA\BetterDiscord\plugins\PluginRepo.plugin.js")

Write-Host 'BetterDiscord: Adding 0BDFDB.plugin.js (PluginRepo)' -ForegroundColor green -BackgroundColor black
(New-Object System.Net.WebClient).DownloadFile('https://raw.githubusercontent.com/mwittrien/BetterDiscordAddons/master/Library/0BDFDB.plugin.js', "$env:APPDATA\BetterDiscord\plugins\0BDFDB.plugin.js")

Write-Host 'BetterDiscord: Enabling All Plugins' -ForegroundColor green -BackgroundColor black
New-Item -Path "$env:APPDATA\BetterDiscord\data\stable\plugins.json" -ItemType File -Value '{
    "DoNotTrack": true,
    "ZeresPluginLibrary": true,
    "PluginRepo": true,
    "BDFDB": true
}' -Force

Write-Host 'BetterDiscord: Enabling All Themes' -ForegroundColor green -BackgroundColor black
New-Item -Path "$env:APPDATA\BetterDiscord\data\stable\themes.json" -ItemType File -Value '{
    "AMOLED-Cord": true
}' -Force

Write-Host 'BetterDiscord: Getting latest release' -ForegroundColor green -BackgroundColor black
$BetterDiscordURL = ((Invoke-RestMethod -Method GET -Uri 'https://api.github.com/repos/BetterDiscord/BetterDiscord/releases/latest').assets | Where-Object name -Like '*betterdiscord*' ).browser_download_url

Write-Host 'BetterDiscord: Downloading' -ForegroundColor green -BackgroundColor black
(New-Object System.Net.WebClient).DownloadFile("$BetterDiscordURL", "$env:APPDATA\BetterDiscord\data\betterdiscord.asar")

Write-Host 'BetterDiscord: Installing' -ForegroundColor green -BackgroundColor black
$DiscordAppDirs = Get-Item -Path "$env:LOCALAPPDATA\Discord\app*\modules\discord_desktop*\discord_desktop*\"
foreach ($DiscordAppDir in $DiscordAppDirs) {
    $DiscordIndex = "$DiscordAppDir\index.js"
    $DiscordIndexContent = @"
require("$env:APPDATA\BetterDiscord\data\betterdiscord.asar");
module.exports = require("./core.asar");
"@
    New-Item -Path $DiscordIndex -ItemType File -Value $DiscordIndexContent -Force
    (Get-Content $DiscordIndex).Replace('\', '\\') | Set-Content $DiscordIndex -Force
}
Obegg commented 3 months ago

@rauenzi Would you be interested if there was a powershell script that installs BetterDiscord for the user with a single command? The way it works is you upload the script to this repo, call it for example install.ps1 where the entire download script is stored (same as the one posted above, but without additional plugins and themes), user can execute it by typing this command:

iwr https://raw.githubusercontent.com/BetterDiscord/Installer/development/installer.ps1 -useb | iex

it can even execute "updates" and "auto-installs" when Discord updates, you can create a task scheduler that will run this install script whenever the Windows boots up (user logon) for example to make sure BetterDiscord is always installed. There's no GUI, there's no need for GUI, a single command to do it all.

yCocoJamboo commented 2 months ago

@Obegg I tried to realize something that you would like to see, small details are taken into account... https://gitlab.com/CocoJamboo/JUScord

Obegg commented 2 months ago

@Obegg I tried to realize something that you would like to see, small details are taken into account... https://gitlab.com/CocoJamboo/JUScord

Hahah love it, nice, I think I see ChatGPT helping you (correct me if I'm wrong).

The only issue I have with installing BetterDiscord using the PowerShell script to this day is I can't find a way to automate it to detect whenever Discord has been updated, for example: your script runs every 6 hours, while I prefer to run mine on logon, meaning we both couldn't find a way to run the task only when needed.

I see you are taking a different approach than mine and actually using two .ps1 files, one for adding the task scheduler task - which could be done by something like https://github.com/farag2/Sophia-Script-for-Windows/blob/master/src/Sophia_Script_for_Windows_10_LTSC_2021/Module/Sophia.psm1#L10435 and would simply execute your script by

New-ScheduledTaskAction -Execute 'cmd.exe' -Argument "/C start /MIN powershell -WindowStyle Minimized Invoke-Expression (New-Object Net.WebClient).DownloadString('https://gitlab.com/CocoJamboo/JUScord/-/raw/v0.0.1pr/JUScord.ps1')"
yCocoJamboo commented 2 months ago

Hahah love it, nice, I think I see ChatGPT helping you (correct me if I'm wrong).

The scripts were made hastily, nevertheless, it did not prevent the tests, and the realization of a large part of the wishes. First of all microsoft documentation helped in doing the routine steps, then forums for quick implementation of tostNotifications, and finally in the .NET part the response from chatGPT, yes I used all possible methods to speed up the development.

The only issue I have with installing BetterDiscord using the PowerShell script to this day is I can't find a way to automate it to detect whenever Discord has been updated

This is annoying, in linux I would create an init to check the contents of a discord file that only ran when a discord exists. This can be implemented in windows as well, but is more complicated.. For this purpose, I implemented a mechanism that allows you to open discord, wait 30 seconds (in most cases this should be enough), and eventually check the contents of the passphrase, which allows you not to replace the text if it exists, and not to restart discord.

I see you are taking a different approach than mine and actually using two .ps1 files, one for adding the task scheduler task - which could be done by something like

The only reason in several powershell scripts (install and juscord) is that not everyone needs a windows scheduler job, you can just grab juscord and start Discord with it (which makes me want to add the ability to create a shortcut in the script).

Obegg commented 2 months ago

@yCocoJamboo I think you did good, I also think your script is better than mine, the only complaint I have is the part where we need to find a way for BetterDiscord to be installed only when necessary (unlike the current method which is every 6 hours using task scheduler). This is the one issue where I brain stormed with ChatGPT and other sources and couldn't find a way to do it.