Skip to content

Commit

Permalink
Merge pull request #9 from wakatime/development
Browse files Browse the repository at this point in the history
Hotfix
  • Loading branch information
diegomgarcia authored Sep 29, 2023
2 parents ed6cf96 + 3f00b15 commit 91461c9
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 15 deletions.
4 changes: 3 additions & 1 deletion src/WakaTimeCLIInstallerThread.pas
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
20 changes: 12 additions & 8 deletions src/WakaTimeNotifier.pas
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ procedure TIDENotifier.AfterCompile(Succeeded: Boolean);
EditorServices: IOTAEditorServices;
EditBuffer: IOTAEditBuffer;
SourceEditor: IOTASourceEditor;
SourceEditorNotifier: IOTAEditorNotifier;
begin
Project := GetActiveProject;

Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -268,6 +270,7 @@ procedure TIDENotifier.FileNotification(NotifyCode: TOTAFileNotification; const
EditorServices: IOTAEditorServices;
EditBuffer: IOTAEditBuffer;
SourceEditor: IOTASourceEditor;
SourceEditorNotifier: IOTAEditorNotifier;
Project: IOTAProject;
ProjectName: string;
begin
Expand Down Expand Up @@ -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;
Expand Down
10 changes: 5 additions & 5 deletions src/WakaTimeSendHeartbeatThread.pas
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/WakaTimeSettings.pas
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ constructor TWakaTimeSettings.Create;

destructor TWakaTimeSettings.Destroy;
begin
FreeAndNil(FWakaTimeInstaller);
FWakaTimeInstaller := nil;
inherited;
end;

Expand Down

0 comments on commit 91461c9

Please sign in to comment.