diff --git a/src/WakaTimeCLIInstallerThread.pas b/src/WakaTimeCLIInstallerThread.pas index 78920a0..07c215f 100644 --- a/src/WakaTimeCLIInstallerThread.pas +++ b/src/WakaTimeCLIInstallerThread.pas @@ -22,12 +22,14 @@ constructor TWakaTimeCLIInstallerThread.Create(const CLIPath: string); begin inherited Create(False); // Create the thread in suspended state FreeOnTerminate := True; // Automatically deallocate memory on finish + FInstaller := TWakaTimeCLIInstaller.Create(CLIPath); end; destructor TWakaTimeCLIInstallerThread.Destroy; begin - FInstaller.Free; + if Assigned(FInstaller) then + FInstaller.Free; inherited; end; diff --git a/src/WakaTimeNotifier.pas b/src/WakaTimeNotifier.pas index b27de56..2e898f8 100644 --- a/src/WakaTimeNotifier.pas +++ b/src/WakaTimeNotifier.pas @@ -224,6 +224,7 @@ procedure TIDENotifier.AfterCompile(Succeeded: Boolean); EditorServices: IOTAEditorServices; EditBuffer: IOTAEditBuffer; SourceEditor: IOTASourceEditor; + SourceEditorNotifier: IOTAEditorNotifier; begin Project := GetActiveProject; @@ -239,10 +240,9 @@ procedure TIDENotifier.AfterCompile(Succeeded: Boolean); if Assigned(EditBuffer) and Supports(EditBuffer, IOTASourceEditor, SourceEditor) then begin - TSourceEditorNotifier.Create(SourceEditor, - ProjectName).SendHeartbeat(SourceEditor.FileName, + if Supports(EditBuffer, IOTAEditorNotifier, SourceEditorNotifier) then + TSourceEditorNotifier(SourceEditorNotifier).SendHeartbeat(SourceEditor.FileName, SourceEditor.GetLinesInBuffer, False); - SourceEditor := nil; end; end; end; @@ -251,12 +251,14 @@ procedure TIDENotifier.BeforeCompile(const Project: IOTAProject; var Cancel: Boolean); var SourceEditor: IOTASourceEditor; + SourceEditorNotifier: IOTAEditorNotifier; begin if Assigned(Project) then begin SourceEditor := Project.CurrentEditor as IOTASourceEditor; - TSourceEditorNotifier.Create(SourceEditor, - Project.FileName).SendHeartbeat(Project.FileName, + + if Supports(SourceEditor, IOTAEditorNotifier, SourceEditorNotifier) then + TSourceEditorNotifier(SourceEditorNotifier).SendHeartbeat(Project.FileName, SourceEditor.GetLinesInBuffer, False); end; end; @@ -268,6 +270,7 @@ procedure TIDENotifier.FileNotification(NotifyCode: TOTAFileNotification; const EditorServices: IOTAEditorServices; EditBuffer: IOTAEditBuffer; SourceEditor: IOTASourceEditor; + SourceEditorNotifier: IOTAEditorNotifier; Project: IOTAProject; ProjectName: string; begin @@ -310,9 +313,10 @@ procedure TIDENotifier.FileNotification(NotifyCode: TOTAFileNotification; const begin EditBuffer := EditorServices.TopBuffer; if Assigned(EditBuffer) and Supports(EditBuffer, IOTASourceEditor, SourceEditor) then - begin - TSourceEditorNotifier.Create(SourceEditor, ProjectName).SendHeartbeat(SourceEditor.FileName, SourceEditor.GetLinesInBuffer, False); - end; + begin + if Supports(EditBuffer, IOTAEditorNotifier, SourceEditorNotifier) then + TSourceEditorNotifier(SourceEditorNotifier).SendHeartbeat(SourceEditor.FileName, SourceEditor.GetLinesInBuffer, False); + end; end; end; end; diff --git a/src/WakaTimeSendHeartbeatThread.pas b/src/WakaTimeSendHeartbeatThread.pas index c56ddc6..c295bdb 100644 --- a/src/WakaTimeSendHeartbeatThread.pas +++ b/src/WakaTimeSendHeartbeatThread.pas @@ -123,7 +123,7 @@ constructor TSendHeartbeatThread.Create(CLIPath, APIKey, FileName, procedure TSendHeartbeatThread.Execute; var Commands: TStringList; - CommandLine, executable: string; + CommandLine, CLIFileName: string; Operation: PChar; FileName: PChar; Parameters: PChar; @@ -136,7 +136,7 @@ procedure TSendHeartbeatThread.Execute; exit; end; - executable := Format('"%swakatime-cli.exe"', [FCLIPath]); + CLIFileName := Format('"%swakatime-cli.exe"', [FCLIPath]); // Prepare the command line Commands := TStringList.Create; @@ -147,19 +147,19 @@ procedure TSendHeartbeatThread.Execute; Commands.Add('--plugin "' + UserAgent + '"'); CommandLine := ReplaceStr(Commands.Text, '=', ''); - CommandLine := ReplaceStr(Commands.Text, #13#10, ' '); + CommandLine := ReplaceStr(CommandLine, #13#10, ' '); if FIsWrite then CommandLine := CommandLine + ' --write'; // Set the parameters for ShellExecute Operation := 'open'; - FileName := PChar(executable); + FileName := PChar(CLIFileName); Parameters := PChar(CommandLine); Directory := nil; ShowCommand := SW_HIDE; // Use SW_SHOW to show the command prompt window - TWakaTimeLogger.Log('Running: ' + executable); + TWakaTimeLogger.Log('Running: ' + CLIFileName); TWakaTimeLogger.Log('With commands: ' + CommandLine); try // Execute the command diff --git a/src/WakaTimeSettings.pas b/src/WakaTimeSettings.pas index da37eba..4d19430 100644 --- a/src/WakaTimeSettings.pas +++ b/src/WakaTimeSettings.pas @@ -142,7 +142,7 @@ constructor TWakaTimeSettings.Create; destructor TWakaTimeSettings.Destroy; begin - FreeAndNil(FWakaTimeInstaller); + FWakaTimeInstaller := nil; inherited; end;