Skip to content

Commit ded77d1

Browse files
committed
Automatically set itself to auto-launch if not previously installed
Thanks u/elvissteinjr for pointing out this possibility!
1 parent f41223c commit ded77d1

1 file changed

Lines changed: 17 additions & 13 deletions

File tree

OpenVRStartup/Program.cs

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,10 @@ static void Main(string[] args)
3434
else {
3535
Utils.PrintInfo("\n========================");
3636
Utils.PrintInfo(" First Run Instructions ");
37-
Utils.PrintInfo("========================\n");
38-
Utils.Print("To get this to launch every time you start SteamVR, do the following steps:");
39-
Utils.Print(" 1. Launch SteamVR.");
40-
Utils.Print(" 2. Open [Settings] from the hamburger menu in the SteamVR status window.");
41-
Utils.Print(" 3. Select the [Startup / Shutdown] section in the menu to the left.");
42-
Utils.Print(" 4. Click [Choose startup overlay apps].");
43-
Utils.Print(" 5. Locate OpenVRStartup and toggle the switch to [On].");
44-
Utils.Print("\nThe next time this program runs it will be minimized and terminate as soon as scripts have been launched.");
45-
Utils.Print("\nTo see this message again, delete the log file that is in the same folder.");
37+
Utils.PrintInfo("========================");
38+
Utils.Print("\nThis app automatically sets itself to auto-launch with SteamVR.");
39+
Utils.Print("\nWhen it runs it will in turn run all .cmd files in the same folder.");
40+
Utils.Print("\nThis message is only shown once, to see it again delete the log file.");
4641
Utils.Print("\nPress [Enter] in this window to continue execution.");
4742
Console.ReadLine();
4843
_isReady = true;
@@ -97,9 +92,18 @@ private static bool InitVR()
9792
{
9893
LogUtils.WriteLineToCache("OpenVR init success");
9994

100-
// Load app manifest
101-
var appError = OpenVR.Applications.AddApplicationManifest(Path.GetFullPath("./app.vrmanifest"), false);
102-
if (appError != EVRApplicationError.None) LogUtils.WriteLineToCache($"Error: Failed to load app manifest: {Enum.GetName(typeof(EVRApplicationError), appError)}");
95+
// Add app manifest and set auto-launch
96+
var appKey = "boll7708.openvrstartup";
97+
if (!OpenVR.Applications.IsApplicationInstalled(appKey))
98+
{
99+
var manifestError = OpenVR.Applications.AddApplicationManifest(Path.GetFullPath("./app.vrmanifest"), false);
100+
if (manifestError == EVRApplicationError.None) LogUtils.WriteLineToCache("Successfully installed app manifest");
101+
else LogUtils.WriteLineToCache($"Error: Failed to add app manifest: {Enum.GetName(typeof(EVRApplicationError), manifestError)}");
102+
103+
var autolaunchError = OpenVR.Applications.SetApplicationAutoLaunch(appKey, true);
104+
if (autolaunchError == EVRApplicationError.None) LogUtils.WriteLineToCache("Successfully set app to auto launch");
105+
else LogUtils.WriteLineToCache($"Error: Failed to turn on auto launch: {Enum.GetName(typeof(EVRApplicationError), autolaunchError)}");
106+
}
103107
return true;
104108
}
105109
}
@@ -119,7 +123,7 @@ private static void RunScripts()
119123
p.StartInfo.FileName = Path.Combine(Environment.CurrentDirectory, file);
120124
p.Start();
121125
}
122-
if(files.Length == 0) LogUtils.WriteLineToCache($"Did not find any .cmd files to execute.");
126+
if(files.Length == 0) LogUtils.WriteLineToCache("Did not find any .cmd files to execute.");
123127
} catch(Exception e)
124128
{
125129
LogUtils.WriteLineToCache($"Error: Could not load scripts: {e.Message}");

0 commit comments

Comments
 (0)