wppconnect-team / WPP4Delphi

WPP4Delphi is an open-source project with the aim of exporting functions from WhatsApp Web for Delphi, which can be used to support the creation of any interaction.
Apache License 2.0
187 stars 62 forks source link

⚠️ Executável só fecha se for no gerenciador de tarefas📍Executable only closes in task manager #16

Closed fraurino closed 1 year ago

fraurino commented 1 year ago

segue correção do fechamento da aplicação, que era necessário encerrar no gerenciador de tarefas, pois ficava em execução após encerramento da aplicação. a correção está relacionado à unit ..\WPP4Delphi\trunk\Source\Services\uTWPPConnect.pas no procedure ShutDown ;


following correction of closing the application, which was necessary to close in the task manager, as it was running after closing the application. the fix is related to the unit ..\WPP4Delphi\trunk\Source\Services\uTWPPConnect.pas in the ShutDown procedure;


👉🏽 procedure TWPPConnect.ShutDown(PWarning:Boolean);


function MensagemDlgBR(txtMsg:String):boolean; //alteração em 17/07/2022📍
{http://www.planetadelphi.com.br/dica/4365/funcao-para-traduzir-mbyes,-mbno-do-messagedlg}
var Mensagem:TForm;
begin
  {Cria a janela de mensagem}
  Mensagem:=createmessagedialog(txtMsg,MtConfirmation,[MbYes,MbNo]);
  {Trazur o titulo da mensagem}
  Mensagem.Caption:='Confirmação';
  {Traduz os botões da caixa de mensagem}
  (Mensagem.FindComponent('Yes') as TButton).Caption:='Sim';
  (Mensagem.FindComponent('Yes') as TButton).Cursor := crHandPoint;
  (Mensagem.FindComponent('No') as TButton).Caption:='Não';
  (Mensagem.FindComponent('No') as TButton).Cursor := crHandPoint;
  {Exibr a caixa de mensagem}
  Mensagem.ShowModal;
  {Verifica aqul botão foi pressionado}
  If Mensagem.ModalResult=MrYes then
  result:=true;{Botão Sim}
  If Mensagem.ModalResult=MrNo then
  result:=false;
  {Botão Não}
end;

Var
  LForm  : Tform;
  LPanel1: Tpanel;
  LAbel1 : TLabel;
  LActivityIndicator1: TActivityIndicator;
begin
  if PWarning then
  Begin
    //if MessageDlg(Text_FrmClose_WarningClose, mtConfirmation, [mbYes, mbNo], 0) <> mrYes then  Abort;
    if not MensagemDlgBR (Text_FrmClose_WarningClose) then  Abort; //alteração em 17/07/2022📍
  end;

  LForm := Tform.Create(Nil);
  try
    LForm.BorderStyle                 := bsDialog;
    LForm.BorderIcons                 := [biMinimize,biMaximize];
    LForm.FormStyle                   := fsStayOnTop;
    LForm.Caption                     := Text_FrmClose_Caption;
    LForm.Height                      := 124;
    LForm.Width                       := 500;
    LForm.Position                    := poScreenCenter;
    LForm.Visible                     := False;
    LForm.OnCloseQuery                := OnCLoseFrmInt;

    LPanel1                           := Tpanel.Create(LForm);
    LPanel1.Parent                    := LForm;
    LPanel1.ShowCaption               := False;
    LPanel1.BevelOuter                := bvNone;
    LPanel1.Width                     := 81;
    LPanel1.Align                     := alLeft;

    LActivityIndicator1               := TActivityIndicator.Create(LPanel1);
    LActivityIndicator1.Parent        := LPanel1;
    LActivityIndicator1.IndicatorSize := aisXLarge;
    LActivityIndicator1.Animate       := True;
    LActivityIndicator1.Left          := (LPanel1.Width  - LActivityIndicator1.Width)  div 2;
    LActivityIndicator1.Top           := (LPanel1.Height - LActivityIndicator1.Height) div 2;

    LAbel1                            := TLabel.Create(LForm);
    LAbel1.Parent                     := LForm;
    LAbel1.Align                      := alClient;
    LAbel1.Alignment                  := taCenter;
    LAbel1.Layout                     := tlCenter;
    LAbel1.Font.Size                  := 10;
    LAbel1.WordWrap                   := True;
    LAbel1.Caption                    := Text_FrmClose_Label;
    LAbel1.AlignWithMargins           := true;
    LForm.Visible                     := True;
    SleepNoFreeze(2000);               //alteração em 17/07/2022 📍
    Application.MainForm.Visible      := False;
    LForm.Show;

    Disconnect;
    LForm.close;

    try {morte forcada hehe}  //alteração em 17/07/2022📍
      WinExec(PAnsiChar('TaskKill -f -im '+Application.ExeName+'.exe'), SW_HIDE);
      Application.Terminate;
    finally
      WinExec(PAnsiChar('TaskKill -f -im '+Application.ExeName+'.exe'), SW_HIDE);
      Application.Terminate;
    end;

  finally
    FreeAndNil(LForm);
    FreeAndNil(GlobalCEFApp);  {descomentado}   //alteração em 17/07/2022📍
    //if CallTerminateProcs then PostQuitMessage(0);
  end
end;
fraurino commented 1 year ago

e na unit wTPPConnect.constante foi adicionado a mensagem ao fechar a aplicação:

Text_FrmClose_WarningClose = 'Fechar a aplicação?';