diff --git a/src/calibre/utils/windows/wintest.py b/src/calibre/utils/windows/wintest.py index 611ac7f304..8a0c0521d5 100644 --- a/src/calibre/utils/windows/wintest.py +++ b/src/calibre/utils/windows/wintest.py @@ -30,6 +30,9 @@ class TestWinutil(unittest.TestCase): def test_special_folder_path(self): self.assertEqual(os.path.expanduser('~'), self.winutil.special_folder_path(self.winutil.CSIDL_PROFILE)) + def test_associations_changed(self): + self.assertIsNone(self.winutil.notify_associations_changed()) + def find_tests(): return unittest.defaultTestLoader.loadTestsFromTestCase(TestWinutil) diff --git a/src/calibre/utils/windows/winutil.c b/src/calibre/utils/windows/winutil.c index 38b5a87e75..6a404d22ed 100644 --- a/src/calibre/utils/windows/winutil.c +++ b/src/calibre/utils/windows/winutil.c @@ -377,6 +377,7 @@ winutil_strftime(PyObject *self, PyObject *args) static char winutil_doc[] = "Defines utility methods to interface with windows."; extern PyObject *add_to_recent_docs(PyObject *self, PyObject *args); extern PyObject *file_association(PyObject *self, PyObject *args); +extern PyObject *notify_associations_changed(PyObject *self, PyObject *args); static PyMethodDef winutil_methods[] = { {"special_folder_path", winutil_folder_path, METH_VARARGS, @@ -452,6 +453,10 @@ be a unicode string. Returns unicode strings." "file_association()\n\nGet the executable associated with the given file extension" }, + {"notify_associations_changed", (PyCFunction)notify_associations_changed, METH_VARARGS, + "notify_associations_changed()\n\nNotify the OS that file associations have changed" + }, + {NULL, NULL, 0, NULL} }; diff --git a/src/calibre/utils/windows/winutilpp.cpp b/src/calibre/utils/windows/winutilpp.cpp index 23cd6a7c0b..741804e0d5 100644 --- a/src/calibre/utils/windows/winutilpp.cpp +++ b/src/calibre/utils/windows/winutilpp.cpp @@ -72,4 +72,10 @@ file_association(PyObject *self, PyObject *args) { return Py_BuildValue("u#", buf, (int)sz); } +PyObject * +notify_associations_changed(PyObject *self, PyObject *args) { + SHChangeNotify(SHCNE_ASSOCCHANGED, SHCNF_DWORD | SHCNF_FLUSH, NULL, NULL); + Py_RETURN_NONE; +} + } diff --git a/src/calibre/utils/winreg/default_programs.py b/src/calibre/utils/winreg/default_programs.py index 57e04548ed..6080a8e004 100644 --- a/src/calibre/utils/winreg/default_programs.py +++ b/src/calibre/utils/winreg/default_programs.py @@ -12,7 +12,7 @@ from threading import Thread import winerror from calibre import guess_type, prints -from calibre.constants import is64bit, isportable, isfrozen, __version__, DEBUG +from calibre.constants import is64bit, isportable, isfrozen, __version__, DEBUG, plugins from calibre.utils.winreg.lib import Key, HKEY_CURRENT_USER, HKEY_LOCAL_MACHINE from polyglot.builtins import iteritems, itervalues @@ -131,8 +131,8 @@ def register(): with Key(r'Software\RegisteredApplications') as key: key.set(data['name'], capabilities_path) - from win32com.shell import shell, shellcon - shell.SHChangeNotify(shellcon.SHCNE_ASSOCCHANGED, shellcon.SHCNF_DWORD | shellcon.SHCNF_FLUSH, 0, 0) + winutil = plugins['winutil'][0] + winutil.notify_associations_changed() def unregister():