From a46a59f57c456adcb49b96b28f00179d0c3a0e93 Mon Sep 17 00:00:00 2001
From: Manuel Thalmann <m@nuth.ch>
Date: Mon, 17 Jul 2023 02:55:45 +0200
Subject: [PATCH] Install Tobii apps for user

---
 profiles/DerGeret/Windows/Drivers.ps1         | 10 ++++++++
 scripts/Windows/Collections/Personal.ps1      |  6 +++++
 .../Windows/Drivers/Tobii EyeX/Install.ps1    | 24 -------------------
 .../TobiiGameHub}/GameHub.ahk                 |  0
 .../Windows/Software/TobiiGameHub/Install.ps1 | 18 ++++++++++++++
 .../TobiiGhost}/Ghost.ahk                     |  4 ----
 .../Windows/Software/TobiiGhost/Install.ps1   | 18 ++++++++++++++
 7 files changed, 52 insertions(+), 28 deletions(-)
 rename scripts/Windows/{Drivers/Tobii EyeX => Software/TobiiGameHub}/GameHub.ahk (100%)
 create mode 100644 scripts/Windows/Software/TobiiGameHub/Install.ps1
 rename scripts/Windows/{Drivers/Tobii EyeX => Software/TobiiGhost}/Ghost.ahk (75%)
 create mode 100644 scripts/Windows/Software/TobiiGhost/Install.ps1

diff --git a/profiles/DerGeret/Windows/Drivers.ps1 b/profiles/DerGeret/Windows/Drivers.ps1
index 487c7de8..29dcad81 100644
--- a/profiles/DerGeret/Windows/Drivers.ps1
+++ b/profiles/DerGeret/Windows/Drivers.ps1
@@ -19,3 +19,13 @@ function Install-PortValhallaDrivers {
     choco install -y amd-ryzen-master geforce-game-ready-driver icue wavelink;
     $context.RemoveDesktopIcon("*Wave Link*");
 }
+
+function Install-PersonalDrivers {
+    param(
+        [Context] $context
+    )
+
+    $softwarePath = "$PSScriptRoot/../../../scripts/Windows/Software";
+    . "$softwarePath/TobiiGhost/Install.ps1" $context;
+    . "$softwarePath/TobiiGameHub/Install.ps1" $context;
+}
diff --git a/scripts/Windows/Collections/Personal.ps1 b/scripts/Windows/Collections/Personal.ps1
index b9511078..2293f5cd 100644
--- a/scripts/Windows/Collections/Personal.ps1
+++ b/scripts/Windows/Collections/Personal.ps1
@@ -27,6 +27,12 @@ function Backup-PersonalApps([Context] $context) {
 }
 
 function Restore-PersonalApps([Context] $context) {
+    # Device specific
+    if ((Get-Command Install-PersonalDrivers -ErrorAction SilentlyContinue)) {
+        Write-Information "Driver installation function was found. Starting installation";
+        Install-PersonalDrivers $context;
+    }
+
     # Backed up applications
     Restore-Git $context;
     Restore-LogitechGHUB $context;
diff --git a/scripts/Windows/Drivers/Tobii EyeX/Install.ps1 b/scripts/Windows/Drivers/Tobii EyeX/Install.ps1
index 4cbf2d58..bfd0a921 100644
--- a/scripts/Windows/Drivers/Tobii EyeX/Install.ps1	
+++ b/scripts/Windows/Drivers/Tobii EyeX/Install.ps1	
@@ -2,29 +2,5 @@
 param($context)
 . "$PSScriptRoot/../../Scripts/SoftwarePackage.ps1";
 
-choco install -y "dotnet-6.0-desktopruntime" vcredist2013;
-$tempDir = $context.GetTempDirectory();
-$installer = "setup.exe";
-
-Push-Location $tempDir;
-
 Write-Host "Installing Tobii Eye Tracking";
-Write-Host "Installing Tobii EyeX";
 Install-SoftwarePackage $context "https://files.update.tech.tobii.com/Tobii_Eye_Tracking_Core_v2.16.8.214_x86.exe";
-
-Write-Host "Installing Tobii Ghost";
-Write-Information "Downloading Tobii Ghost installer";
-Invoke-WebRequest "https://files.update.oem.tobii.com/Ghost/TobiiGhost.1.14.1-Setup.exe" -OutFile $installer;
-
-Write-Information "Running Tobii Ghost installer";
-Start-Process -Wait -FilePath "$PSScriptRoot/Ghost.ahk";
-
-Write-Host "Installing Tobii Game Hub";
-Write-Information "Downloading Tobii Game Hub installer";
-Invoke-WebRequest "https://files.update.oem.tobii.com/GameHub/TobiiGameHub.3.0.1-Setup.exe" -OutFile $installer;
-
-Write-Information "Running Tobii Game Hub installer";
-Start-Process -Wait -FilePath "$PSScriptRoot/GameHub.ahk";
-
-Pop-Location;
-Remove-Item -Recurse $tempDir;
diff --git a/scripts/Windows/Drivers/Tobii EyeX/GameHub.ahk b/scripts/Windows/Software/TobiiGameHub/GameHub.ahk
similarity index 100%
rename from scripts/Windows/Drivers/Tobii EyeX/GameHub.ahk
rename to scripts/Windows/Software/TobiiGameHub/GameHub.ahk
diff --git a/scripts/Windows/Software/TobiiGameHub/Install.ps1 b/scripts/Windows/Software/TobiiGameHub/Install.ps1
new file mode 100644
index 00000000..398082ea
--- /dev/null
+++ b/scripts/Windows/Software/TobiiGameHub/Install.ps1
@@ -0,0 +1,18 @@
+#!/bin/pwsh
+param($context)
+$tempDir = $context.GetTempDirectory();
+$installer = "setup.exe";
+
+Push-Location $tempDir;
+
+choco install -y vcredist2013;
+
+Write-Host "Installing Tobii Game Hub";
+Write-Information "Downloading Tobii Game Hub installer";
+Invoke-WebRequest "https://files.update.oem.tobii.com/GameHub/TobiiGameHub.3.0.1-Setup.exe" -OutFile $installer;
+
+Write-Information "Running Tobii Game Hub installer";
+Start-Process -Wait -FilePath "$PSScriptRoot/GameHub.ahk";
+
+Pop-Location;
+Remove-Item -Recurse $tempDir;
diff --git a/scripts/Windows/Drivers/Tobii EyeX/Ghost.ahk b/scripts/Windows/Software/TobiiGhost/Ghost.ahk
similarity index 75%
rename from scripts/Windows/Drivers/Tobii EyeX/Ghost.ahk
rename to scripts/Windows/Software/TobiiGhost/Ghost.ahk
index df6007b7..c26a99a7 100644
--- a/scripts/Windows/Drivers/Tobii EyeX/Ghost.ahk	
+++ b/scripts/Windows/Software/TobiiGhost/Ghost.ahk
@@ -10,13 +10,9 @@ InstallGhost()
 	MouseClick, Left, 330, 752
 	WinWaitNotActive
 	WinWait % windowTitle,, 20
-	WinActivate % windowTitle
 	MouseClick, Left, 563, 397
 	MouseClick, Left, 650, 497
 	Sleep, 10 * 1000
-	WinActivate % windowTitle
-	WinGet, pid, PID
-	Run, pwsh -c "Stop-Process -Force %pid%"
 }
 
 InstallGhost()
diff --git a/scripts/Windows/Software/TobiiGhost/Install.ps1 b/scripts/Windows/Software/TobiiGhost/Install.ps1
new file mode 100644
index 00000000..b56735fb
--- /dev/null
+++ b/scripts/Windows/Software/TobiiGhost/Install.ps1
@@ -0,0 +1,18 @@
+#!/bin/pwsh
+param($context)
+$tempDir = $context.GetTempDirectory();
+$installer = "setup.exe";
+
+Push-Location $tempDir;
+
+choco install -y "dotnet-6.0-desktopruntime";
+
+Write-Host "Installing Tobii Ghost";
+Write-Information "Downloading Tobii Ghost installer";
+Invoke-WebRequest "https://files.update.oem.tobii.com/Ghost/TobiiGhost.1.14.1-Setup.exe" -OutFile $installer;
+
+Write-Information "Running Tobii Ghost installer";
+Start-Process -Wait -FilePath "$PSScriptRoot/Ghost.ahk";
+
+Pop-Location;
+Remove-Item -Recurse $tempDir;