Skip to content

Commit

Permalink
add path to chrome in config
Browse files Browse the repository at this point in the history
disable the service to download a new version of chrome each time program starts
use currently installed chrome from the PC
  • Loading branch information
Vlad Somai authored and Vlad Somai committed Jul 18, 2022
1 parent 4af235c commit d707e92
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
19 changes: 15 additions & 4 deletions Necta/Form1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ public partial class Necta : MaterialForm
{
//the following dispatcher object will be used to invoke the print method from another thread
public static Dispatcher MainThreadDispatcher = Dispatcher.CurrentDispatcher;
public static string PathToReceipt = "C:/Necta/Receipt.pdf";
public static string PathToReceipt = @"C:\Necta\Receipt.pdf";
public static string PathToChrome = "";
private static Browser browserForConverting = null;

private static readonly object printingInProgressLock = new object();
private static bool _printingInProgress = false;
Expand Down Expand Up @@ -63,6 +65,7 @@ private void SetDataFromConfig()
ApiUpdateUri_textBox.Text = config.API_UPDATE_URI;
ApiPrinterInfoUri_textBox.Text = config.API_PRINTER_INFO_URI;
ApiRequestInterval_value.Value = config.API_REQUEST_INTERVAL;
PathToChrome = config.CHROME_PATH + "chrome.exe";
}

private void SaveAndValidateURI(bool isFirstPaint = false)
Expand Down Expand Up @@ -127,6 +130,15 @@ public static async void PrintReceipt(Receipt receipt)
{
NectaLogService.WriteLog(ex.Message, LogLevels.ERROR);
NectaLogService.WriteLog(ex.InnerException?.Message, LogLevels.ERROR);

if (browserForConverting != null)
await browserForConverting.CloseAsync();

if (ex.Message == "Failed to launch browser! path to executable does not exist")
{
NectaLogService.WriteLog("You must stop Necta.exe and add the corect path to the chrome executable in C:/Necta/Config/Config.json!", LogLevels.ERROR);
}
printingInProgress = false;
return;
}

Expand Down Expand Up @@ -163,13 +175,12 @@ private void onResize(object sender, EventArgs e)

private static async Task<int> ChromeConvertHtmlToPdf(string html)
{
BrowserFetcher browserFetcher = new BrowserFetcher();
await browserFetcher.DownloadAsync(BrowserFetcher.DefaultChromiumRevision);
{
string[] args1 = { "--disable-gpu" };
Browser browserForConverting = await Puppeteer.LaunchAsync(new LaunchOptions
browserForConverting = await Puppeteer.LaunchAsync(new LaunchOptions
{
Headless = true,
ExecutablePath = PathToChrome,
Args = args1,
});

Expand Down
5 changes: 5 additions & 0 deletions Necta/NectaServices/NectaConfigService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public static void Initialize()
file.WriteLine(" \"API_GET_URI\": \"https://develop.meals.lv/other/printer/?method=queue&key=rest4\",");
file.WriteLine(" \"API_UPDATE_URI\": \"https://develop.meals.lv/other/printer/?method=setPrinted&key=rest4\",");
file.WriteLine(" \"API_PRINTER_INFO_URI\": \"https://develop.meals.lv/other/printer/?method=printerStatus\", ");
file.WriteLine(" \"CHROME_PATH\": \"C:/Program Files/Google/Chrome/Application/\", ");
file.WriteLine(" \"API_REQUEST_INTERVAL\": 3000");
file.WriteLine("}");
}
Expand All @@ -46,12 +47,15 @@ public static void SaveNewConfig()
if (!Directory.Exists(nectaConfigPath))
Directory.CreateDirectory(nectaConfigPath);

var currentConfig = ReadConfig();

using (StreamWriter file = new StreamWriter(nectaConfigFile))
{
file.WriteLine("{");
file.WriteLine(" \"API_GET_URI\": \"{0}\",", API_Handler.API_GET_URI);
file.WriteLine(" \"API_UPDATE_URI\": \"{0}\",", API_Handler.API_UPDATE_URI);
file.WriteLine(" \"API_PRINTER_INFO_URI\": \"{0}\",",API_Handler.API_PRINTER_INFO_URI);
file.WriteLine(" \"CHROME_PATH\": \"{0}\",", currentConfig.CHROME_PATH);
file.WriteLine(" \"API_REQUEST_INTERVAL\": {0}", API_Handler.API_REQUEST_INTERVAL);
file.WriteLine("}");
}
Expand All @@ -63,6 +67,7 @@ class ConfigType
public string API_GET_URI { get; set; }
public string API_UPDATE_URI { get; set; }
public string API_PRINTER_INFO_URI { get; set; }
public string CHROME_PATH { get; set; }
public int API_REQUEST_INTERVAL { get; set; }
}
}

0 comments on commit d707e92

Please sign in to comment.