Skip to content

Instantly share code, notes, and snippets.

@MauriceBrg
Last active January 21, 2018 22:29
Show Gist options
  • Save MauriceBrg/d639161cb82c2f7c446ab012505aab7e to your computer and use it in GitHub Desktop.
Save MauriceBrg/d639161cb82c2f7c446ab012505aab7e to your computer and use it in GitHub Desktop.
Workaround for the RocketChat/Rocket.Chat.Electron #380 Issue. Place these two files in some directory. Create a shortcut to the .bat script and run it whenever your Rocket Chat Client is hidden on the disconnected second Screen. It stops RocketChat, fixes a config and restarts it afterwards.
<#
.SYNOPSIS
Workaround for the Multi-Monitor Issue: RocketChat/Rocket.Chat.Electron #380
.DESCRIPTION
This script assumes that Rocket Chat is running. It extracts the path to the Rocket
Chat executable and stops the Rocket Chat Client afterwards. Then the json file that
containts the clients window state gets updated and Rocket Chat will be restarted.
(Just a quick and dirty workaround, no warranties of any kind...)
.NOTES
Author: Maurice B.
Github: https://github.com/MauriceBrg
#>
# Stop on error
$ErrorActionPreference = "stop"
# Change this to "Continue" if you want to see the output
$DebugPreference = "SilentlyContinue"
# Path to the file where the Window State is stored
$WindowStateFilePath = ("{0}\Rocket.Chat+\window-state-main.json" -f $env:APPDATA)
# Fetch the path where RocketChat is installed fromt the currently running instance
$RocketChatPath = (Get-Process -Name Rocket.Chat+ | Select-Object Path)[0].Path
Write-Debug ("Path to RocketChat executable: {0}" -f $RocketChatPath )
Write-Debug "Stopping running Rocket Chat instances"
$StopResult = Get-Process -Name Rocket.Chat+ | Stop-Process -Force
Write-Debug "Fixing the Window Position Config"
# Read the file, parse it's content, update the x-value and save it again.
$WindowState = Get-Content -Path $WindowStateFilePath | ConvertFrom-Json
$WindowState.x = 0
$WindowState | ConvertTo-Json | Out-File $WindowStateFilePath -Force
Write-Debug "Updated the Window Position Config"
Write-Debug ("Restarting RocketChat from {0}" -f $RocketChatPath)
Start-Process -FilePath $RocketChatPath
REM Run the Powershell Script to fix the Rocket Chat bug that lies relative to the script location
SET ScriptLocation=%~dp0
powershell -ExecutionPolicy Bypass -WindowStyle Hidden %ScriptLocation%Rocket_Chat_Fix_Window_Position.ps1
@MauriceBrg
Copy link
Author

Workaround for RocketChat/Rocket.Chat.Electron#380 on Windows.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment