Skip to content

Commit

Permalink
fix(Windows): Automatically remove file when no audio has been written.
Browse files Browse the repository at this point in the history
fixes #266
  • Loading branch information
llfbandit committed Dec 29, 2024
1 parent 37548ed commit f6bd26b
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 7 deletions.
1 change: 1 addition & 0 deletions record_windows/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
## 1.0.5
* fix: Send messages on main thread (workaround).
* fix: Automatically remove file when no audio has been written.

## 1.0.4
* fix: Process path as wide string (UTF-16).
Expand Down
23 changes: 23 additions & 0 deletions record_windows/windows/record.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,11 @@ namespace record_windows

HRESULT Recorder::Stop()
{
if (m_dataWritten == 0)
{
return Cancel();
}

HRESULT hr = EndRecording();

if (SUCCEEDED(hr))
Expand All @@ -195,6 +200,24 @@ namespace record_windows
return hr;
}

HRESULT Recorder::Cancel()
{
auto recordingPath = GetRecordingPath();
HRESULT hr = EndRecording();

if (SUCCEEDED(hr))
{
UpdateState(RecordState::stop);

if (!recordingPath.empty())
{
DeleteFile(recordingPath.c_str());
}
}

return hr;
}

bool Recorder::IsPaused()
{
switch (m_recordState)
Expand Down
1 change: 1 addition & 0 deletions record_windows/windows/record.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ namespace record_windows
HRESULT Pause();
HRESULT Resume();
HRESULT Stop();
HRESULT Cancel();
bool IsPaused();
bool IsRecording();
HRESULT Dispose();
Expand Down
10 changes: 3 additions & 7 deletions record_windows/windows/record_windows_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -214,18 +214,14 @@ namespace record_windows {
}
else if (method_call.method_name().compare("cancel") == 0)
{
auto recordingPath = recorder->GetRecordingPath();
HRESULT hr = recorder->Stop();
HRESULT hr = recorder->Cancel();

if (SUCCEEDED(hr))
{
if (!recordingPath.empty()) {
DeleteFile(recordingPath.c_str());
}

result->Success(EncodableValue());
}
else {
else
{
ErrorFromHR(hr, *result);
}
}
Expand Down

0 comments on commit f6bd26b

Please sign in to comment.