95 |
96 |
96 def __load(self): |
97 def __load(self): |
97 """ |
98 """ |
98 Private method to load the registered protocol handlers. |
99 Private method to load the registered protocol handlers. |
99 """ |
100 """ |
100 try: |
101 with contextlib.suppress(OSError): |
101 with open(self.__protocolHandlersFileName(), |
102 with open(self.__protocolHandlersFileName(), |
102 "r") as protocolHandlersFile: |
103 "r") as protocolHandlersFile: |
103 protocolHandlersData = json.load(protocolHandlersFile) |
104 protocolHandlersData = json.load(protocolHandlersFile) |
104 |
105 |
105 if protocolHandlersData: |
106 if protocolHandlersData: |
106 self.__protocolHandlers = {} |
107 self.__protocolHandlers = {} |
107 for scheme, urlStr in protocolHandlersData.items(): |
108 for scheme, urlStr in protocolHandlersData.items(): |
108 url = QUrl(urlStr) |
109 url = QUrl(urlStr) |
109 self.__protocolHandlers[scheme] = url |
110 self.__protocolHandlers[scheme] = url |
110 self.__registerHandler(scheme, url) |
111 self.__registerHandler(scheme, url) |
111 except OSError: |
|
112 # ignore issues silently |
|
113 pass |
|
114 |
112 |
115 def __save(self): |
113 def __save(self): |
116 """ |
114 """ |
117 Private method to save the protocol handlers. |
115 Private method to save the protocol handlers. |
118 """ |
116 """ |
134 """ |
132 """ |
135 urlStr = url.toString().replace("%25s", "%s") |
133 urlStr = url.toString().replace("%25s", "%s") |
136 |
134 |
137 page = QWebEnginePage(self) |
135 page = QWebEnginePage(self) |
138 page.loadFinished.connect(page.deleteLater) |
136 page.loadFinished.connect(page.deleteLater) |
139 try: |
137 page.registerProtocolHandlerRequested.connect( |
140 # for Qt >= 5.11 |
138 lambda r: r.accept()) |
141 page.registerProtocolHandlerRequested.connect( |
|
142 lambda r: r.accept()) |
|
143 except AttributeError: |
|
144 pass |
|
145 page.setHtml( |
139 page.setHtml( |
146 "<script>navigator.registerProtocolHandler('{0}', '{1}', '')" |
140 "<script>navigator.registerProtocolHandler('{0}', '{1}', '')" |
147 "</script>".format(scheme, urlStr), |
141 "</script>".format(scheme, urlStr), |
148 url) |
142 url) |
149 |
143 |