diff --git a/src/constants/Channels.ts b/src/constants/Channels.ts index 1f499498..1e4c0e6c 100644 --- a/src/constants/Channels.ts +++ b/src/constants/Channels.ts @@ -18,7 +18,8 @@ const Channels = { SaveLog: 'SaveLog', GetPrerequisites: 'GetPrerequisites', CheckPrerequisite: 'CheckPrerequisite', - GetWSLPrefixPath: 'GetWSLPrefixPath' + GetWSLPrefixPath: 'GetWSLPrefixPath', + GetPowerShellVersion: 'GetPowerShellVersion' }, Git: { GetCurrentConfigs: 'GetCurrentConfigs', diff --git a/src/constants/Endpoints.ts b/src/constants/Endpoints.ts index 9e2fd44a..f2421e68 100755 --- a/src/constants/Endpoints.ts +++ b/src/constants/Endpoints.ts @@ -35,7 +35,9 @@ const Endpoints = { MICROK8S_REGISTRY_CATALOG: 'http://localhost:32000/v2/_catalog', MICROK8S_WINDOWS_REGISTRY_CATALOG: 'http://microk8s.registry:32000/v2/_catalog', SUPPORT_GITHUB: 'https://github.com/EtherealEngine/etherealengine-control-center/issues', - SUPPORT_DISCORD: 'https://discord.gg/xrf' + SUPPORT_DISCORD: 'https://discord.gg/xrf', + SET_EXECUTION_POLICY: + 'https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_execution_policies' }, Paths: { ENGINE_ENV: '.env.local', diff --git a/src/main/handlers/Utilities/Prerequisites.ts b/src/main/handlers/Utilities/Prerequisites.ts index 906956b3..e922c857 100644 --- a/src/main/handlers/Utilities/Prerequisites.ts +++ b/src/main/handlers/Utilities/Prerequisites.ts @@ -4,5 +4,11 @@ export const WindowsPrerequisites: AppModel[] = [ getAppModel('wsl', 'Windows Subsystem for Linux (WSL)', 'wsl --status;', false), getAppModel('wslUbuntu', 'WSL Ubuntu Distribution', 'wsl --status;', false), getAppModel('dockerDesktop', 'Docker Desktop', 'docker version;', false), - getAppModel('dockerDesktopUbuntu', 'Docker Desktop WSL Ubuntu Integration', 'wsl docker version;', false) + getAppModel('dockerDesktopUbuntu', 'Docker Desktop WSL Ubuntu Integration', 'wsl docker version;', false), + getAppModel( + 'ps1ExecutionPolicy', + 'PowerShell Execution Policy', + '$env:PSModulePath = "$PSHomeModules"; Get-ExecutionPolicy;', + false + ) ] diff --git a/src/main/handlers/Utilities/Utilities.class.ts b/src/main/handlers/Utilities/Utilities.class.ts index 4d624564..885c5dd5 100755 --- a/src/main/handlers/Utilities/Utilities.class.ts +++ b/src/main/handlers/Utilities/Utilities.class.ts @@ -1,3 +1,4 @@ +import { execSync } from 'child_process' import { app, BrowserWindow, clipboard, dialog, shell } from 'electron' import log from 'electron-log' import { promises as fs } from 'fs' @@ -103,12 +104,22 @@ class Utilities { return WindowsPrerequisites } } catch (err) { - log.error('Failed to get pre requisites.', err) + log.error('Failed to get prerequisites.', err) } return [] } + static getPowerShellVersion = () => { + try { + const version = execSync('powershell.exe -Command "$PSVersionTable.PSVersion.Major"').toString().trim() + return version + } catch (err) { + log.error('Failed to get PowerShell version.', err) + throw err + } + } + static checkPrerequisite = async (prerequisite: AppModel) => { try { let status = AppStatus.NotConfigured @@ -128,6 +139,7 @@ class Utilities { if ( (prerequisite.id === 'wsl' && stdOutput) || + (prerequisite.id === 'ps1ExecutionPolicy' && stdOutput.includes('Unrestricted')) || (prerequisite.id === 'wslUbuntu' && stdOutput.includes(': Ubuntu')) || ((prerequisite.id === 'dockerDesktop' || prerequisite.id === 'dockerDesktopUbuntu') && stdOutput.includes('Server: Docker Desktop')) diff --git a/src/main/handlers/Utilities/Utilities.handler.ts b/src/main/handlers/Utilities/Utilities.handler.ts index 7ee99692..890be7f5 100755 --- a/src/main/handlers/Utilities/Utilities.handler.ts +++ b/src/main/handlers/Utilities/Utilities.handler.ts @@ -34,6 +34,9 @@ class UtilitiesHandler implements IBaseHandler { ipcMain.handle(Channels.Utilities.GetPrerequisites, async (_event: IpcMainInvokeEvent) => { return await Utilities.getPrerequisites() }), + ipcMain.handle(Channels.Utilities.GetPowerShellVersion, (_event: IpcMainInvokeEvent) => { + return Utilities.getPowerShellVersion() + }), ipcMain.handle( Channels.Utilities.CheckPrerequisite, async (_event: IpcMainInvokeEvent, prerequisite: AppModel) => { diff --git a/src/renderer/components/Config/PrereqsView.tsx b/src/renderer/components/Config/PrereqsView.tsx index 87da2308..ab7a7def 100644 --- a/src/renderer/components/Config/PrereqsView.tsx +++ b/src/renderer/components/Config/PrereqsView.tsx @@ -1,4 +1,7 @@ +import Channels from 'constants/Channels' import Endpoints from 'constants/Endpoints' +import { ipcRenderer } from 'electron' +import log from 'electron-log' import Commands from 'main/Clusters/BaseCluster/BaseCluster.commands' import { AppModel, AppStatus } from 'models/AppStatus' import { OSType } from 'models/AppSysInfo' @@ -54,12 +57,12 @@ const PrereqsView = ({ sx }: Props) => { } } - const processDescriptions = (status: AppModel) => { + const processDescriptions = async (status: AppModel) => { if (status.id === 'wsl' || status.id === 'wslUbuntu') { status.description = ( - Make sure WSL is installed and Ubuntu is selected as default distribution.{' '} + Make sure WSL is installed and Ubuntu is selected as the default distribution.{' '} Install WSL @@ -98,6 +101,43 @@ const PrereqsView = ({ sx }: Props) => { . ) + } else if (status.id === 'ps1ExecutionPolicy') { + try { + const powerShellVersion = await ipcRenderer.invoke(Channels.Utilities.GetPowerShellVersion) + status.description = ( + + + Use PowerShell {powerShellVersion} for the following instructions. + +
+
+ + Check whether the execution policy is set to allow unsigned PowerShell scripts. + +
+
+ + Afterwards, if the execution policy is not set to allow unsigned PowerShell scripts, you can do so by + running the following commands: +
+
+ Get-ExecutionPolicy +
+
+ Set-ExecutionPolicy Unrestricted +
+
+ Refer to the Microsoft documentation for information on PowerShell execution policies and   +
+
+ Learn more + + . + + ) + } catch (err) { + log.error('Failed to retrieve PowerShell version.', err) + } } }