Skip to content

Commit 0e59f3d

Browse files
committed
Use host 0.0.0.0 instead of the ipv4 host on the default network adapter
1 parent 9452f43 commit 0e59f3d

File tree

4 files changed

+165
-37
lines changed

4 files changed

+165
-37
lines changed

Pipfile

+4-4
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,13 @@ python_version = "3.9"
3030
install_dlls = "python .scripts/install_dlls.py"
3131
uninstall_dlls = "python .scripts/uninstall_dlls.py"
3232
start = "python main.py"
33-
dev = "pwsh.exe -File .scripts/dev.ps1" # Requires that nodemon is installed globally, this can be installed with `npm i -g nodemon`
33+
dev = "powershell.exe -File .scripts/dev.ps1" # Requires that nodemon is installed globally, this can be installed with `npm i -g nodemon`
3434
build = "pyinstaller --noconfirm --onedir --windowed --icon \"./assets/favicon.ico\" --name \"mimic\" --add-data \"./assets;assets\" --add-data \"./mimic/public;mimic/public/\" --hidden-import \"pkg_resources\" \"./main.py\""
3535
build-debug = "pyinstaller --noconfirm --onedir --console --icon \"./assets/favicon.ico\" --name \"mimic\" --add-data \"./assets;assets\" --add-data \"./mimic/public;mimic/public/\" --hidden-import \"pkg_resources\" \"./main.py\""
36-
installer = "pwsh.exe -File .scripts/build_installer.ps1"
37-
profile = "pwsh.exe -File .scripts/profile.ps1"
36+
installer = "powershell.exe -File .scripts/build_installer.ps1"
37+
profile = "powershell.exe -File .scripts/profile.ps1"
3838
lint = "python .scripts/lint.py"
39-
pslint = "pwsh.exe -File .scripts/lint.ps1"
39+
pslint = "powershell.exe -File .scripts/lint.ps1"
4040
lint-imports = "isort main.py mimic"
4141
lint-code = "autopep8 --in-place --recursive main.py mimic"
4242
lint-type_checking = "mypy main.py mimic --config-file mypy.ini"

install-pyenv-win.ps1

+156
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
1+
<#
2+
.SYNOPSIS
3+
Installs pyenv-win
4+
5+
.DESCRIPTION
6+
Installs pyenv-win to $HOME\.pyenv
7+
If pyenv-win is already installed, try to update to the latest version.
8+
9+
.PARAMETER Uninstall
10+
Uninstall pyenv-win. Note that this uninstalls any Python versions that were installed with pyenv-win.
11+
12+
.INPUTS
13+
None.
14+
15+
.OUTPUTS
16+
None.
17+
18+
.EXAMPLE
19+
PS> install-pyenv-win.ps1
20+
21+
.LINK
22+
Online version: https://pyenv-win.github.io/pyenv-win/
23+
#>
24+
25+
param (
26+
[Switch] $Uninstall = $False
27+
)
28+
29+
$PyEnvDir = "${env:USERPROFILE}\.pyenv"
30+
$PyEnvWinDir = "${PyEnvDir}\pyenv-win"
31+
$BinPath = "${PyEnvWinDir}\bin"
32+
$ShimsPath = "${PyEnvWinDir}\shims"
33+
34+
Function Remove-PyEnvVars() {
35+
$PathParts = [System.Environment]::GetEnvironmentVariable('PATH', "User") -Split ";"
36+
$NewPathParts = $PathParts.Where{ $_ -ne $BinPath }.Where{ $_ -ne $ShimsPath }
37+
$NewPath = $NewPathParts -Join ";"
38+
[System.Environment]::SetEnvironmentVariable('PATH', $NewPath, "User")
39+
40+
[System.Environment]::SetEnvironmentVariable('PYENV', $null, "User")
41+
[System.Environment]::SetEnvironmentVariable('PYENV_ROOT', $null, "User")
42+
[System.Environment]::SetEnvironmentVariable('PYENV_HOME', $null, "User")
43+
}
44+
45+
Function Remove-PyEnv() {
46+
Write-Host "Removing $PyEnvDir..."
47+
If (Test-Path $PyEnvDir) {
48+
Remove-Item -Path $PyEnvDir -Recurse
49+
}
50+
Write-Host "Removing environment variables..."
51+
Remove-PyEnvVars
52+
}
53+
54+
Function Get-CurrentVersion() {
55+
$VersionFilePath = "$PyEnvDir\.version"
56+
If (Test-Path $VersionFilePath) {
57+
$CurrentVersion = Get-Content $VersionFilePath
58+
}
59+
Else {
60+
$CurrentVersion = ""
61+
}
62+
63+
Return $CurrentVersion
64+
}
65+
66+
Function Get-LatestVersion() {
67+
$LatestVersionFilePath = "$PyEnvDir\latest.version"
68+
(New-Object System.Net.WebClient).DownloadFile("https://raw.githubusercontent.com/pyenv-win/pyenv-win/master/.version", $LatestVersionFilePath)
69+
$LatestVersion = Get-Content $LatestVersionFilePath
70+
71+
Remove-Item -Path $LatestVersionFilePath
72+
73+
Return $LatestVersion
74+
}
75+
76+
Function Main() {
77+
If ($Uninstall) {
78+
Remove-PyEnv
79+
If ($? -eq $True) {
80+
Write-Host "pyenv-win successfully uninstalled."
81+
}
82+
Else {
83+
Write-Host "Uninstallation failed."
84+
}
85+
exit
86+
}
87+
88+
$BackupDir = "${env:Temp}/pyenv-win-backup"
89+
90+
$CurrentVersion = Get-CurrentVersion
91+
If ($CurrentVersion) {
92+
Write-Host "pyenv-win $CurrentVersion installed."
93+
$LatestVersion = Get-LatestVersion
94+
If ($CurrentVersion -eq $LatestVersion) {
95+
Write-Host "No updates available."
96+
exit
97+
}
98+
Else {
99+
Write-Host "New version available: $LatestVersion. Updating..."
100+
101+
Write-Host "Backing up existing Python installations..."
102+
$FoldersToBackup = "install_cache", "versions", "shims"
103+
ForEach ($Dir in $FoldersToBackup) {
104+
If (-not (Test-Path $BackupDir)) {
105+
New-Item -ItemType Directory -Path $BackupDir
106+
}
107+
Move-Item -Path "${PyEnvWinDir}/${Dir}" -Destination $BackupDir
108+
}
109+
110+
Write-Host "Removing $PyEnvDir..."
111+
Remove-Item -Path $PyEnvDir -Recurse
112+
}
113+
}
114+
115+
New-Item -Path $PyEnvDir -ItemType Directory
116+
117+
$DownloadPath = "$PyEnvDir\pyenv-win.zip"
118+
119+
(New-Object System.Net.WebClient).DownloadFile("https://github.com/pyenv-win/pyenv-win/archive/master.zip", $DownloadPath)
120+
121+
Start-Process -FilePath "powershell.exe" -ArgumentList @(
122+
"-NoProfile",
123+
"-Command `"Microsoft.PowerShell.Archive\Expand-Archive -Path \`"$DownloadPath\`" -DestinationPath \`"$PyEnvDir\`"`""
124+
) -NoNewWindow -Wait
125+
126+
Move-Item -Path "$PyEnvDir\pyenv-win-master\*" -Destination "$PyEnvDir"
127+
Remove-Item -Path "$PyEnvDir\pyenv-win-master" -Recurse
128+
Remove-Item -Path $DownloadPath
129+
130+
# Update env vars
131+
[System.Environment]::SetEnvironmentVariable('PYENV', "${PyEnvWinDir}\", "User")
132+
[System.Environment]::SetEnvironmentVariable('PYENV_ROOT', "${PyEnvWinDir}\", "User")
133+
[System.Environment]::SetEnvironmentVariable('PYENV_HOME', "${PyEnvWinDir}\", "User")
134+
135+
$PathParts = [System.Environment]::GetEnvironmentVariable('PATH', "User") -Split ";"
136+
137+
# Remove existing paths, so we don't add duplicates
138+
$NewPathParts = $PathParts.Where{ $_ -ne $BinPath }.Where{ $_ -ne $ShimsPath }
139+
$NewPathParts = ($BinPath, $ShimsPath) + $NewPathParts
140+
$NewPath = $NewPathParts -Join ";"
141+
[System.Environment]::SetEnvironmentVariable('PATH', $NewPath, "User")
142+
143+
If (Test-Path $BackupDir) {
144+
Write-Host "Restoring Python installations..."
145+
Move-Item -Path "$BackupDir/*" -Destination $PyEnvWinDir
146+
}
147+
148+
If ($? -eq $True) {
149+
Write-Host "pyenv-win is successfully installed. You may need to close and reopen your terminal before using it."
150+
}
151+
Else {
152+
Write-Host "pyenv-win was not installed successfully. If this issue persists, please open a ticket: https://github.com/pyenv-win/pyenv-win/issues."
153+
}
154+
}
155+
156+
Main

mimic/Utils/Host.py

-29
This file was deleted.

mimic/WebServer.py

+5-4
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@
4343
from mimic.Constants import SLEEP_INTERVAL
4444
from mimic.Pipeable import LogMessage
4545
from mimic.Utils.AppData import mkdir_local_app_data, resolve_local_app_data
46-
from mimic.Utils.Host import resolve_host
4746
from mimic.Utils.SSL import generate_ssl_certs, ssl_certs_generated
4847
from mimic.Utils.Time import RollingTimeout, latency, timestamp
4948

@@ -291,11 +290,13 @@ async def on_ended():
291290
runner = web.AppRunner(app, handle_signals=True)
292291
await runner.setup()
293292

294-
site = web.TCPSite(runner, host=resolve_host(),
295-
port=8080, ssl_context=ssl_context)
293+
host = "0.0.0.0"
294+
port = 8080
295+
site = web.TCPSite(runner, host=host,
296+
port=port, ssl_context=ssl_context)
296297
await site.start()
297298

298-
log(f"Server listening at https://{resolve_host()}:8080")
299+
log(f"Server listening at https://{host}:{port}")
299300

300301
# Acquire virtual camera
301302
camera_init_sucess = False

0 commit comments

Comments
 (0)