Skip to content

Commit a2ccd85

Browse files
authored
Disable IDLE menu while PyManager is working. (#114)
Also fixes error refreshing installs. Fixes #79
1 parent e3b6475 commit a2ccd85

File tree

2 files changed

+58
-17
lines changed

2 files changed

+58
-17
lines changed

src/manage/install_command.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -554,6 +554,8 @@ def _fatal_install_error(cmd, ex):
554554
def execute(cmd):
555555
LOGGER.debug("BEGIN install_command.execute: %r", cmd.args)
556556

557+
cmd.tags = []
558+
557559
if cmd.refresh:
558560
if cmd.args:
559561
LOGGER.warn("Ignoring arguments; --refresh always refreshes all installs.")
@@ -580,7 +582,6 @@ def execute(cmd):
580582
download_index = {"versions": []}
581583

582584
if not cmd.by_id:
583-
cmd.tags = []
584585
for arg in cmd.args:
585586
if arg.casefold() == "default".casefold():
586587
LOGGER.debug("Replacing 'default' with '%s'", cmd.default_tag)

src/pyshellext/shellext.cpp

Lines changed: 56 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -335,9 +335,45 @@ class DECLSPEC_UUID(CLSID_COMMAND_ENUMERATOR) CommandEnumerator
335335
};
336336

337337

338+
class PyManagerOperationInProgress
339+
{
340+
HANDLE hGlobalSem;
341+
bool busy;
342+
343+
bool _create() {
344+
hGlobalSem = CreateSemaphoreExW(NULL, 0, 1,
345+
L"PyManager-OperationInProgress", 0, SEMAPHORE_MODIFY_STATE | SYNCHRONIZE);
346+
347+
return (hGlobalSem && GetLastError() != ERROR_ALREADY_EXISTS);
348+
}
349+
350+
public:
351+
PyManagerOperationInProgress()
352+
{
353+
busy = _create();
354+
}
355+
356+
~PyManagerOperationInProgress()
357+
{
358+
if (hGlobalSem) {
359+
if (!busy) {
360+
ReleaseSemaphore(hGlobalSem, 1, NULL);
361+
}
362+
CloseHandle(hGlobalSem);
363+
}
364+
}
365+
366+
operator bool()
367+
{
368+
return hGlobalSem && !busy;
369+
}
370+
};
371+
372+
338373
class DECLSPEC_UUID(CLSID_IDLE_COMMAND) IdleCommand
339374
: public RuntimeClass<RuntimeClassFlags<ClassicCom>, IExplorerCommand, IObjectWithSite>
340375
{
376+
PyManagerOperationInProgress busy;
341377
std::vector<IdleData> idles;
342378
std::wstring iconPath;
343379
std::wstring title;
@@ -356,19 +392,21 @@ class DECLSPEC_UUID(CLSID_IDLE_COMMAND) IdleCommand
356392
iconPath += L",-4";
357393
}
358394

359-
hr = ReadAllIdleInstalls(idles, HKEY_LOCAL_MACHINE, L"Software\\Python", KEY_WOW64_32KEY);
360-
if (SUCCEEDED(hr)) {
361-
hr = ReadAllIdleInstalls(idles, HKEY_LOCAL_MACHINE, L"Software\\Python", KEY_WOW64_64KEY);
362-
}
363-
if (SUCCEEDED(hr)) {
364-
hr = ReadAllIdleInstalls(idles, HKEY_CURRENT_USER, L"Software\\Python", 0);
365-
}
395+
if (!busy) {
396+
hr = ReadAllIdleInstalls(idles, HKEY_LOCAL_MACHINE, L"Software\\Python", KEY_WOW64_32KEY);
397+
if (SUCCEEDED(hr)) {
398+
hr = ReadAllIdleInstalls(idles, HKEY_LOCAL_MACHINE, L"Software\\Python", KEY_WOW64_64KEY);
399+
}
400+
if (SUCCEEDED(hr)) {
401+
hr = ReadAllIdleInstalls(idles, HKEY_CURRENT_USER, L"Software\\Python", 0);
402+
}
366403

367-
if (FAILED(hr)) {
368-
wchar_t buffer[512];
369-
swprintf_s(buffer, L"IdleCommand error 0x%08X", (DWORD)hr);
370-
OutputDebugStringW(buffer);
371-
idles.clear();
404+
if (FAILED(hr)) {
405+
wchar_t buffer[512];
406+
swprintf_s(buffer, L"IdleCommand error 0x%08X", (DWORD)hr);
407+
OutputDebugStringW(buffer);
408+
idles.clear();
409+
}
372410
}
373411
}
374412

@@ -387,10 +425,12 @@ class DECLSPEC_UUID(CLSID_IDLE_COMMAND) IdleCommand
387425
iconPath += L",-4";
388426
}
389427

390-
hr = ReadAllIdleInstalls(idles, hive, root, 0);
428+
if (!busy) {
429+
hr = ReadAllIdleInstalls(idles, hive, root, 0);
391430

392-
if (FAILED(hr)) {
393-
idles.clear();
431+
if (FAILED(hr)) {
432+
idles.clear();
433+
}
394434
}
395435
}
396436
#endif
@@ -429,7 +469,7 @@ class DECLSPEC_UUID(CLSID_IDLE_COMMAND) IdleCommand
429469

430470
IFACEMETHODIMP GetState(IShellItemArray *psiItemArray, BOOL fOkToBeSlow, EXPCMDSTATE *pCmdState)
431471
{
432-
*pCmdState = idles.size() ? ECS_ENABLED : ECS_HIDDEN;
472+
*pCmdState = idles.size() ? ECS_ENABLED : ECS_DISABLED;
433473
return S_OK;
434474
}
435475

0 commit comments

Comments
 (0)