Disclosure Statement: This site contains affiliate links, which means that I may receive a commission if you make a purchase using these links. As an eBay Partner, I earn from qualifying purchases.
If you find these projects useful please consider becoming a sponsor with Patreon, GitHub or Liberapay.

Start my application with parameters

Post Reply
ericktux
Posts: 40
Joined: Thu Oct 29, 2020 10:11 am

Start my application with parameters

Post by ericktux »

Good morning, my friend Salvador, and everyone. I have a question: Is there a way to start my app automatically with parameters? For example, I tried this without success:

Code: Select all

GlobalCEFApp.AddCustomCommandLine('--password-store=basic');
To prevent the Ubuntu "gnome keyring" "keystore" box from popping up, but it doesn't work. Currently, I run it like this and it works fine:

Code: Select all

./myapp --password-store=basic
But I would like to know if there is a way to start my app with commands without needing the terminal or extra files?
Please help. :(
User avatar
salvadordf
Posts: 4620
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: Start my application with parameters

Post by salvadordf »

Hi,

Try adding this before the GlobalCEFApp.StartMainProcess call :

Code: Select all

GlobalCEFApp.AddCustomCommandLine('--password-store', 'basic');
You'll see that switch if you navigate to chrome://version
ericktux
Posts: 40
Joined: Thu Oct 29, 2020 10:11 am

Re: Start my application with parameters

Post by ericktux »

Thanks a lot, Salvador. I see that it appears in:
chrome://version
but the "gnome keyring" window keeps appearing. If I run it as a parameter from the terminal, it works. Do you know of any way to integrate that parameter into my app without the terminal?
ericktux
Posts: 40
Joined: Thu Oct 29, 2020 10:11 am

Re: Start my application with parameters

Post by ericktux »

I found this solution, so far it works well on Windows and Linux.

Code: Select all

    program project1;
     
    {$mode objfpc}{$H+}
     
    uses
      {$IFDEF UNIX}
      cthreads,
      {$ENDIF}
      {$IFDEF HASAMIGA}
      athreads,
      {$ENDIF}
      Interfaces, // this includes the LCL widgetset
      Forms, unit1, process
      { you can add units after this };
     
    {$R *.res}
     
    procedure RelaunchWithParam;
    var
      AProcess: TProcess;
    begin
      AProcess := TProcess.Create(nil);
      try
        AProcess.Executable := ParamStr(0);  // Ruta del ejecutable
        AProcess.Parameters.Add('--password-store=basic'); // Agregar parámetro
        //AProcess.Options := [poWaitOnExit];      // No esperar a que termine
        AProcess.Execute;                    // Ejecutar nueva instancia
      finally
        AProcess.Free;
      end;
      Halt;  // Detener la instancia original
    end;
     
    begin
        // Si no hay parámetros, relanzamos con "--password-store=basic"
      if ParamCount = 0 then
        RelaunchWithParam;
     
      RequireDerivedFormResource:=True;
      Application.Scaled:=True;
      Application.Initialize;
      Application.CreateForm(TForm1, Form1);
      Application.Run;
    end.
User avatar
salvadordf
Posts: 4620
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: Start my application with parameters

Post by salvadordf »

Hi,

I just updated CEF4Delphi with a new GlobalCEFApp.PasswordStorage property for Linux. It adds the correct command line switch to select the password storage.

I added GlobalCEFApp.PasswordStorage := psBasic; to the TinyBrowser2 demo and the debug log in verbose mode shows this :

Code: Select all

[11721:11721:0319/155317.710266:VERBOSE1:key_storage_linux.cc(116)] Selected backend for OSCrypt: BASIC_TEXT
If I comment the GlobalCEFApp.PasswordStorage line then the debug log shows this :

Code: Select all

[11528:11528:0319/155229.476760:VERBOSE1:key_storage_linux.cc(116)] Selected backend for OSCrypt: GNOME_LIBSECRET
I was using the latest Ubuntu version.
ericktux
Posts: 40
Joined: Thu Oct 29, 2020 10:11 am

Re: Start my application with parameters

Post by ericktux »

Thank you very much, my friend Salvador. I will check it out.
Post Reply