using System;
using System.Runtime.InteropServices.JavaScript;
using Amphora;
namespace Foundations
{
///
/// Does what every browser program does first, which is read the flags in its page's address.
///
public static partial class BrowserStartup
{
[JSImport("globalThis.alert")]
private static partial void Alert(string message);
///
/// Reads the query string of the page's address, warns on the console about any parameter it ignored, and shows
/// help if asked. Returns whether the program should go on to run, which it shouldn't after help.
///
public static bool TryBegin(out Flags flags)
{
string query = JSHost.GlobalThis.GetPropertyAsJSObject("location").GetPropertyAsString("search");
bool goOn = Startup.TryReadQuery(
FlagRegistry.ScanLoadedAssemblies(), query, out flags, out string message);
if (message != null)
{
Console.WriteLine(message);
}
if (!goOn)
{
Alert(message);
}
return goOn;
}
}
}