Skip to content
This repository has been archived by the owner on Aug 19, 2024. It is now read-only.

(Chore) : Added new prerequisite permission to run ps1 scripts. #77

Open
wants to merge 17 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/constants/Channels.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ const Channels = {
SaveLog: 'SaveLog',
GetPrerequisites: 'GetPrerequisites',
CheckPrerequisite: 'CheckPrerequisite',
GetWSLPrefixPath: 'GetWSLPrefixPath'
GetWSLPrefixPath: 'GetWSLPrefixPath',
GetPowerShellVersion: 'GetPowerShellVersion'
},
Git: {
GetCurrentConfigs: 'GetCurrentConfigs',
Expand Down
4 changes: 3 additions & 1 deletion src/constants/Endpoints.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
8 changes: 7 additions & 1 deletion src/main/handlers/Utilities/Prerequisites.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
]
14 changes: 13 additions & 1 deletion src/main/handlers/Utilities/Utilities.class.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -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
Expand All @@ -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'))
Expand Down
3 changes: 3 additions & 0 deletions src/main/handlers/Utilities/Utilities.handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down
44 changes: 42 additions & 2 deletions src/renderer/components/Config/PrereqsView.tsx
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -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 = (
<Typography fontSize={14}>
<span style={{ fontSize: 14, opacity: 0.6 }}>
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.{' '}
</span>
<a style={{ color: 'var(--textColor)' }} target="_blank" href={Endpoints.Docs.INSTALL_WSL}>
Install WSL
Expand Down Expand Up @@ -98,6 +101,43 @@ const PrereqsView = ({ sx }: Props) => {
.
</Typography>
)
} else if (status.id === 'ps1ExecutionPolicy') {
try {
const powerShellVersion = await ipcRenderer.invoke(Channels.Utilities.GetPowerShellVersion)
status.description = (
<Typography fontSize={14}>
<span style={{ fontSize: 14, opacity: 0.6 }}>
Use PowerShell {powerShellVersion} for the following instructions.
</span>
<br />
<br />
<span style={{ fontSize: 14, opacity: 0.6 }}>
Check whether the execution policy is set to allow unsigned PowerShell scripts.
</span>
<br />
<br />
<span style={{ fontSize: 14, opacity: 0.6 }}>
Afterwards, if the execution policy is not set to allow unsigned PowerShell scripts, you can do so by
running the following commands:
<br />
<br />
<code>Get-ExecutionPolicy</code>
<br />
<br />
<code>Set-ExecutionPolicy Unrestricted</code>
<br />
<br />
Refer to the Microsoft documentation for information on PowerShell execution policies and &nbsp;
</span>
<a style={{ color: 'white' }} target="_blank" href={'#'}>
Learn more
</a>
.
</Typography>
)
} catch (err) {
log.error('Failed to retrieve PowerShell version.', err)
}
}
}

Expand Down
Loading