Skip to content

Commit

Permalink
Refactor all the code that launches a browser to go through a common …
Browse files Browse the repository at this point in the history
…method
  • Loading branch information
andybak committed Apr 3, 2024
1 parent 3765981 commit 553d7bb
Showing 1 changed file with 18 additions and 125 deletions.
143 changes: 18 additions & 125 deletions Assets/Scripts/SketchControlsScript.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4401,26 +4401,10 @@ public void IssueGlobalCommand(GlobalCommands rEnum, int iParam1 = -1,
EatGazeObjectInput();
break;
case GlobalCommands.FAQ:
//launch external window and tell the user we did so
EatGazeObjectInput();
if (!App.Config.IsMobileHardware)
{
OutputWindowScript.m_Instance.CreateInfoCardAtController(
InputManager.ControllerName.Brush,
kRemoveHeadsetFyi, fPopScalar: 0.5f);
}
App.OpenURL(m_HelpCenterURL);
OpenURLAndInformUser(m_HelpCenterURL);
break;
case GlobalCommands.ReleaseNotes:
//launch external window and tell the user we did so
EatGazeObjectInput();
if (!App.Config.IsMobileHardware)
{
OutputWindowScript.m_Instance.CreateInfoCardAtController(
InputManager.ControllerName.Brush,
kRemoveHeadsetFyi, fPopScalar: 0.5f);
}
App.OpenURL(m_ReleaseNotesURL);
OpenURLAndInformUser(m_ReleaseNotesURL);
break;
case GlobalCommands.ExportRaw:
if (!FileUtils.CheckDiskSpaceWithError(App.UserExportPath()))
Expand Down Expand Up @@ -4489,35 +4473,7 @@ public void IssueGlobalCommand(GlobalCommands rEnum, int iParam1 = -1,
break;
}
case GlobalCommands.About:
EatGazeObjectInput();

if (!App.Config.IsMobileHardware)
{
// Launch external window and tell the user we did so/
OutputWindowScript.m_Instance.CreateInfoCardAtController(
InputManager.ControllerName.Brush,
kRemoveHeadsetFyi, fPopScalar: 0.5f);
}

// This call is Windows only.
if ((Application.platform == RuntimePlatform.WindowsPlayer) ||
(Application.platform == RuntimePlatform.WindowsEditor))
{
if (!Application.isEditor)
{
System.Diagnostics.Process.Start("notepad.exe",
Path.Combine(App.PlatformPath(), "NOTICE"));
}
else
{
System.Diagnostics.Process.Start("notepad.exe",
Path.Combine(App.SupportPath(), "ThirdParty/GeneratedThirdPartyNotices.txt"));
}
}
else if (App.Config.IsMobileHardware)
{
App.OpenURL(m_ThirdPartyNoticesURL);
}
OpenURLAndInformUser(m_ThirdPartyNoticesURL);
break;
case GlobalCommands.StencilsDisabled:
SketchMemoryScript.m_Instance.PerformAndRecordCommand(new StencilsVisibleCommand());
Expand Down Expand Up @@ -4599,17 +4555,8 @@ public void IssueGlobalCommand(GlobalCommands rEnum, int iParam1 = -1,
break;
}
case GlobalCommands.ViewOnlineGallery:
{
if (!App.Config.IsMobileHardware)
{
OutputWindowScript.m_Instance.CreateInfoCardAtController(
InputManager.ControllerName.Brush,
kRemoveHeadsetFyi, fPopScalar: 0.5f);
}
App.OpenURL(kTiltBrushGalleryUrl);
EatGazeObjectInput();
break;
}
OpenURLAndInformUser(kTiltBrushGalleryUrl);
break;
case GlobalCommands.CancelUpload:
VrAssetService.m_Instance.CancelUpload();
break;
Expand All @@ -4630,19 +4577,12 @@ public void IssueGlobalCommand(GlobalCommands rEnum, int iParam1 = -1,
}
break;
case GlobalCommands.ShowGoogleDrive:
EatGazeObjectInput();
if (!App.Config.IsMobileHardware)
{
OutputWindowScript.m_Instance.CreateInfoCardAtController(
InputManager.ControllerName.Brush,
kRemoveHeadsetFyi, fPopScalar: 0.5f);
}
string baseDriveUrl = "https://drive.google.com";
string driveURL = !App.GoogleIdentity.LoggedIn ? baseDriveUrl :
string.Format(
"http://accounts.google.com/AccountChooser?Email={0}&continue={1}",
App.GoogleIdentity.Profile.email, baseDriveUrl);
App.OpenURL(driveURL);
OpenURLAndInformUser(driveURL);
break;
case GlobalCommands.GoogleDriveSync:
App.DriveSync.SyncEnabled = !App.DriveSync.SyncEnabled;
Expand Down Expand Up @@ -4703,24 +4643,10 @@ public void IssueGlobalCommand(GlobalCommands rEnum, int iParam1 = -1,
SaveModel();
break;
case GlobalCommands.ViewPolyPage:
if (!App.Config.IsMobileHardware)
{
OutputWindowScript.m_Instance.CreateInfoCardAtController(
InputManager.ControllerName.Brush,
kRemoveHeadsetFyi, fPopScalar: 0.5f);
}
App.OpenURL(kPolyMainPageUri);
EatGazeObjectInput();
OpenURLAndInformUser(kPolyMainPageUri);
break;
case GlobalCommands.ViewPolyGallery:
if (!App.Config.IsMobileHardware)
{
OutputWindowScript.m_Instance.CreateInfoCardAtController(
InputManager.ControllerName.Brush,
kRemoveHeadsetFyi, fPopScalar: 0.5f);
}
App.OpenURL(kBlocksGalleryUrl);
EatGazeObjectInput();
OpenURLAndInformUser(kBlocksGalleryUrl);
break;
case GlobalCommands.ExportListed:
StartCoroutine(ExportListAndQuit());
Expand Down Expand Up @@ -4871,47 +4797,16 @@ public void IssueGlobalCommand(GlobalCommands rEnum, int iParam1 = -1,
}
break;
case GlobalCommands.ShowTos:
// Launch external window and tell the user we did so
EatGazeObjectInput();
if (!App.Config.IsMobileHardware)
{
OutputWindowScript.m_Instance.CreateInfoCardAtController(
InputManager.ControllerName.Brush,
kRemoveHeadsetFyi, fPopScalar: 0.5f);
}
App.OpenURL(m_TosURL);
OpenURLAndInformUser(m_TosURL);
break;
case GlobalCommands.ShowPrivacy:
// Launch external window and tell the user we did so
EatGazeObjectInput();
if (!App.Config.IsMobileHardware)
{
OutputWindowScript.m_Instance.CreateInfoCardAtController(
InputManager.ControllerName.Brush,
kRemoveHeadsetFyi, fPopScalar: 0.5f);
}
App.OpenURL(m_PrivacyURL);
OpenURLAndInformUser(m_PrivacyURL);
break;
case GlobalCommands.ShowQuestSideLoading:
// Launch external window and tell the user we did so
EatGazeObjectInput();
if (!App.Config.IsMobileHardware)
{
OutputWindowScript.m_Instance.CreateInfoCardAtController(
InputManager.ControllerName.Brush,
kRemoveHeadsetFyi, fPopScalar: 0.5f);
}
App.OpenURL(m_QuestSideLoadingHowToURL);
OpenURLAndInformUser(m_QuestSideLoadingHowToURL);
break;
case GlobalCommands.ShowContribution:
EatGazeObjectInput();
if (!App.Config.IsMobileHardware)
{
OutputWindowScript.m_Instance.CreateInfoCardAtController(
InputManager.ControllerName.Brush,
kRemoveHeadsetFyi, fPopScalar: 0.5f);
}
App.OpenURL(m_ContributionURL);
OpenURLAndInformUser(m_ContributionURL);
break;
case GlobalCommands.UnloadReferenceImageCatalog:
ReferenceImageCatalog.m_Instance.UnloadAllImages();
Expand Down Expand Up @@ -4939,16 +4834,13 @@ public void IssueGlobalCommand(GlobalCommands rEnum, int iParam1 = -1,
EatGazeObjectInput();
break;
case GlobalCommands.OpenScriptsCommandsList:
// TODO refactor code above to use this method
OpenUrl($"http://localhost:{App.HttpServer.HttpPort}/help/commands");
OpenURLAndInformUser($"http://localhost:{App.HttpServer.HttpPort}/help/commands");
break;
case GlobalCommands.OpenScriptsList:
// TODO refactor code above to use this method
OpenUrl($"http://localhost:{App.HttpServer.HttpPort}/scripts");
OpenURLAndInformUser($"http://localhost:{App.HttpServer.HttpPort}/scripts");
break;
case GlobalCommands.OpenExampleScriptsList:
// TODO refactor code above to use this method
OpenUrl($"http://localhost:{App.HttpServer.HttpPort}/examplescripts");
OpenURLAndInformUser($"http://localhost:{App.HttpServer.HttpPort}/examplescripts");
break;
case GlobalCommands.RepaintOptions: break; // Intentionally blank.
case GlobalCommands.Null: break; // Intentionally blank.
Expand Down Expand Up @@ -4977,15 +4869,16 @@ private void LoadNamed(string path, bool quickload, bool additive)
}
}

private void OpenUrl(string url)
public void OpenURLAndInformUser(string url)
{
// On desktop - launch external browser and inform the user
// On mobile - the browser appears over the app
if (!App.Config.IsMobileHardware)
{
OutputWindowScript.m_Instance.CreateInfoCardAtController(
InputManager.ControllerName.Brush,
kRemoveHeadsetFyi, fPopScalar: 0.5f);
}

App.OpenURL(url);
EatGazeObjectInput();
}
Expand Down

0 comments on commit 553d7bb

Please sign in to comment.