dynamsoft.webtwain.install.js 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377
  1. // @20210818 160302
  2. (function(){
  3. "use strict";
  4. var screenW = screen.width,
  5. promptDlgWidth = screenW > 550 ? 550 : (screenW - 10),
  6. promptDlgWidth2 = screenW > 680 ? 680 : (screenW - 10),
  7. reconnectTime = 0,
  8. imagesInBase64 = {
  9. icn_download: 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABoAAAAgCAYAAAAMq2gFAAABOklEQVRIie2WTW6DMBCFH4h1l22VqmqPVUEvEJa9gRt6FDhDpfx0FdJj+Arx3nldhEjEdchgWlaM9CSwMZ/fzMgQvX0TwvA+ePOpIsniRIwZGIl/n/8AGs3RWKB4JA4STjUKBo1EivLtGakEkP7Ru6vbpcpONzFxPFsazQloZyxEmkDepsYk0JIhkZGwzngfWRKvd0u1Pwf93k1NoBjg5uN+pbZuHn0gEFgQ2AVAdgTefQVzU9e2nzaplKbMkEhnK2W9oAOAC9IHIO+Yd5U/rJX2QbocnVSSqARuqse1Ki9BumrUp+U1gXkXRAoyBDIC1jNnCWRPG2Wug2SFrkkUnvHieaPqaxCpo3bL104rLySQviDbpNA0Sgl4W9kXfU9vjWPho+ZaHCHfo6r/kumfYUBEL1/jeJpqFBw/d5aBU2kHOMQAAAAASUVORK5CYII=',
  10. icn_install: 'data:image/png;base64,iVBORw0KGgoA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7HRCKAytg/DO9AI0tGlVYDhxy4cEmgdhOgSVdjizGXI03acpcKxCJ/01D1ffwdvgktNuWBV4ZeQc/QmX30BgDkpz4dxmWL0SGjbB9gKY+QNX3sLQ9LLy/bVyuE+qgQdmc5K/Es5vAWcO/A5Dlgo/QjrpyMySpjfW9qkC3QIBs9FNzsGlARj7qZNOzcHlAfgys+zTzS/QpYq+pC3JgqdCOvnLSbg4AN9m0zpW20oeeUMLNZdPhIlktdSPEFwbhIlZ8xgL8Ivgg+i1GBRoTEOFVTRu7NUrz9gq844IrWmoSYXW0l7v7YXdpUn8bjsNrAVqLO9Pa3Yv0veiJRZ78wK1Au0ZnN52gdryvvjyVjMY3Tz6y6EfvTJ0LlPlBHC6oi86vfGKzdfktgjlIlwQIbCEtQxE2pSbkQIotT1i5ou1hUebi+ijbXXEN0X00dYNdFf2e0OpOvwLFunYK2i9bNwAAAAASUVORK5CYII='
  12. },
  13. ua = navigator.userAgent.toLowerCase(),
  14. arm64 = (/arm64|aarch64/g).test(ua),
  15. mips64 = (/mips64/g).test(ua);
  16. function getDebPath (strSuffix) {
  17. var _path = Dynamsoft.DWT.ResourcesPath;
  18. if(Dynamsoft.Lib.isString(_path) && _path.length > 0) {
  19. if (_path[_path.length - 1] != '/') {
  20. _path = _path + '/';
  21. }
  22. } else {
  23. _path = 'Resources/';
  24. }
  25. return [
  26. _path,
  27. 'dist/DynamsoftServiceSetup-',
  28. strSuffix,
  29. '.deb'
  30. ].join('');
  31. }
  32. Dynamsoft.OnWebTwainNotFoundOnWindowsCallback = function (ProductName, InstallerUrl, bHTML5, bIE, bSafari, bSSL, strIEVersion) {
  33. var _this = Dynamsoft, objUrl = { 'default': InstallerUrl };
  34. _this._show_install_dialog(ProductName, objUrl, bHTML5, Dynamsoft.DWT.EnumDWT_PlatformType.enumWindow, bIE, bSafari, bSSL, strIEVersion);
  35. };
  36. Dynamsoft.OnWebTwainNotFoundOnLinuxCallback = function (ProductName, strDebUrl, strRpmUrl, bHTML5, bIE, bSafari, bSSL, strIEVersion) {
  37. var _this = Dynamsoft, objUrl = { 'default': strDebUrl, 'deb': strDebUrl, 'rpm': strRpmUrl };
  38. _this._show_install_dialog(ProductName, objUrl, bHTML5, Dynamsoft.DWT.EnumDWT_PlatformType.enumLinux, bIE, bSafari, bSSL, strIEVersion);
  39. };
  40. Dynamsoft.OnWebTwainNotFoundOnMacCallback = function (ProductName, InstallerUrl, bHTML5, bIE, bSafari, bSSL, strIEVersion) {
  41. var _this = Dynamsoft, objUrl = { 'default': InstallerUrl };
  42. _this._show_install_dialog(ProductName, objUrl, bHTML5, Dynamsoft.DWT.EnumDWT_PlatformType.enumMac, bIE, bSafari, bSSL, strIEVersion);
  43. };
  44. Dynamsoft.dwt_change_install_url = function (url) {
  45. var install = document.getElementById('dwt-btn-install');
  46. if (install)
  47. install.href = url;
  48. };
  49. Dynamsoft.DWT_Reconnect = function () {
  50. var _this = Dynamsoft;
  51. if (((new Date() - reconnectTime) / 1000) > 30) {
  52. // change prompt
  53. var el = document.getElementById('dwt-btn-install');
  54. if (el) {
  55. el.innerHTML = 'Failed to connect to the service, have you run the setup?<br />If not, please run the setup and <a href="javascript:void(0)" onclick="Dynamsoft.DCP_DWT_onclickInstallButton()">click here to connect again</a>.';
  56. }
  57. return;
  58. }
  59. if (_this.DWT) {
  60. _this.DWT.CheckConnectToTheService(function () {
  61. _this.DWT.ConnectToTheService();
  62. }, function () {
  63. setTimeout(Dynamsoft.DWT_Reconnect, 500);
  64. });
  65. } else {
  66. console.log("The Dynamsoft namespace is missing");
  67. }
  68. };
  69. Dynamsoft.DCP_DWT_onclickInstallButton = function () {
  70. var btnInstall = document.getElementById('dwt-btn-install');
  71. if (btnInstall) {
  72. setTimeout(function () {
  73. var install = document.getElementById('dwt-install-url-div');
  74. if (install)
  75. install.style.display = 'none';
  76. var el = document.getElementById('dwt-btn-install');
  77. if (el && el.getAttribute("html5") == "1") {
  78. var pel = el.parentNode,
  79. newDiv = document.createElement('div');
  80. newDiv.id = 'dwt-btn-install';
  81. newDiv.style.textAlign = "center";
  82. newDiv.style.paddingBottom = '15px';
  83. newDiv.innerHTML = 'Connecting to the service...';
  84. newDiv.setAttribute("html5", "1");
  85. pel.removeChild(el);
  86. pel.appendChild(newDiv);
  87. reconnectTime = new Date();
  88. setTimeout(Dynamsoft.DWT_Reconnect, 10);
  89. } else {
  90. var pel = el.parentNode;
  91. pel.removeChild(el);
  92. }
  93. }, 10);
  94. }
  95. return true;
  96. };
  97. Dynamsoft._show_install_dialog = function (ProductName, objInstallerUrl, bHTML5, iPlatform, bIE, bSafari, bSSL, strIEVersion) {
  98. var _this = Dynamsoft, ObjString, title, browserActionNeeded;
  99. title = 'Please complete one-time setup';
  100. ObjString = [
  101. '<div class="dynamsoft-dwt-dlg-title">',
  102. title,
  103. '</div>'];
  104. if (_this.DWT) {
  105. if (iPlatform == Dynamsoft.DWT.EnumDWT_PlatformType.enumLinux || navigator.userAgent.toLowerCase().indexOf("firefox") > -1) {
  106. browserActionNeeded = 'RESTART';
  107. }
  108. else {
  109. browserActionNeeded = 'REFRESH';
  110. }
  111. ObjString.push('<div class="dynamsoft-dwt-installdlg-iconholder"> ');
  112. ObjString.push('<div class="dynamsoft-dwt-installdlg-splitline" style="left: 125px"></div>');
  113. ObjString.push('<div class="dynamsoft-dwt-installdlg-splitline" style="left: 283px"></div>');
  114. ObjString.push('<img style="margin: 0px 134px 0px 0px" src=' + imagesInBase64.icn_download + ' alt="download">');
  115. ObjString.push('<img style="margin: 2px 132px 2px 0px" src=' + imagesInBase64.icn_install + ' alt="install">');
  116. ObjString.push('<img src=' + imagesInBase64.icn_scan + ' alt="scan">');
  117. ObjString.push('<div><span class="dynamsoft-dwt-installdlg-text" style="right: 125px">Download</span>');
  118. ObjString.push('<span class="dynamsoft-dwt-installdlg-text" style="right: 18px">Install</span>');
  119. ObjString.push('<span class="dynamsoft-dwt-installdlg-text" style="left: 105px">Scan</span>');
  120. ObjString.push('</div>');
  121. ObjString.push('</div>');
  122. if (bHTML5 && iPlatform == Dynamsoft.DWT.EnumDWT_PlatformType.enumLinux) {
  123. ObjString.push('<div style="margin:10px 0 0 60px;">');
  124. ObjString.push('<div id="dwt-install-url-div">');
  125. if(arm64 || mips64) {
  126. if(arm64)
  127. objInstallerUrl['default'] = getDebPath('arm64');
  128. else if(mips64)
  129. objInstallerUrl['default'] = getDebPath('mips64el');
  130. } else {
  131. ObjString.push('<div><input id="dwt-install-url-deb" name="dwt-install-url" type="radio" onclick="Dynamsoft.dwt_change_install_url(\'' + objInstallerUrl.deb + '\')" checked="checked" /><label for="dwt-install-url-deb">64 bit .deb (For Ubuntu/Debian/ChromeOS)</label></div>');
  132. ObjString.push('<div><input id="dwt-install-url-rpm" name="dwt-install-url" type="radio" onclick="Dynamsoft.dwt_change_install_url(\'' + objInstallerUrl.rpm + '\')" /><label for="dwt-install-url-rpm">64 bit .rpm (For Fedora)</label></div>');
  133. }
  134. ObjString.push('</div></div>');
  135. }
  136. ObjString.push('<div><a id="dwt-btn-install" target="_blank" href="');
  137. ObjString.push(objInstallerUrl['default']);
  138. ObjString.push('"');
  139. if (bHTML5) {
  140. ObjString.push(' html5="1"');
  141. } else {
  142. ObjString.push(' html5="0"');
  143. }
  144. ObjString.push(' onclick="Dynamsoft.DCP_DWT_onclickInstallButton()"><div class="dynamsoft-dwt-dlg-button">Download</div></a></div>');
  145. if (bHTML5) {
  146. if (bIE) {
  147. ObjString.push('<div class="dynamsoft-dwt-dlg-tail" style="text-align:left; padding-left: 80px">');
  148. ObjString.push('If you still see the dialog after installing the scan service, please<br />');
  149. ObjString.push('1. Add the website to the zone of trusted sites.<br />');
  150. ObjString.push('IE | Tools | Internet Options | Security | Trusted Sites.<br />');
  151. ObjString.push('2. Refresh your browser.');
  152. ObjString.push('</div>');
  153. } else {
  154. if (iPlatform == Dynamsoft.DWT.EnumDWT_PlatformType.enumLinux) {
  155. ObjString.push('<div class="dynamsoft-dwt-dlg-tail">');
  156. ObjString.push('<div class="dynamsoft-dwt-dlg-red">After the installation, please <strong>' + browserActionNeeded + '</strong> your browser.</div>');
  157. ObjString.push('</div>');
  158. }
  159. }
  160. } else {
  161. ObjString.push('<div class="dynamsoft-dwt-dlg-tail" style="text-align:left; padding-left: 80px">');
  162. if (bIE) {
  163. ObjString.push('After the installation, please<br />');
  164. ObjString.push('1. Restart the browser<br />');
  165. ObjString.push('2. Allow "DynamicWebTWAIN" add-on to run by right clicking on the Information Bar in the browser.');
  166. } else {
  167. ObjString.push('<div class="dynamsoft-dwt-dlg-red">After installation, please <strong>REFRESH</strong> your browser.</div>');
  168. }
  169. ObjString.push('</div>');
  170. }
  171. _this.DWT.ShowDialog(promptDlgWidth, 0, ObjString.join(''));
  172. } else {
  173. console.log("The Dynamsoft namespace is missing");
  174. }
  175. };
  176. Dynamsoft.OnWebTwainNeedUpgradeCallback = function (ProductName, objInstallerUrl, bHTML5, iPlatform, bIE, bSafari, bSSL, strIEVersion, bForceUpgrade, bError, strErrorString) {
  177. Dynamsoft._show_install_dialog(ProductName, objInstallerUrl, bHTML5, iPlatform, bIE, bSafari, bSSL, strIEVersion);
  178. };
  179. Dynamsoft.OnWebTwainPreExecuteCallback = function () {
  180. var _this = Dynamsoft;
  181. if (_this.DWT) {
  182. _this.DWT.OnWebTwainPreExecute();
  183. } else {
  184. console.log("The Dynamsoft namespace is missing");
  185. }
  186. };
  187. Dynamsoft.OnWebTwainPostExecuteCallback = function () {
  188. var _this = Dynamsoft;
  189. if (_this.DWT) {
  190. _this.DWT.OnWebTwainPostExecute();
  191. } else {
  192. console.log("The Dynamsoft namespace is missing");
  193. }
  194. };
  195. Dynamsoft.OnRemoteWebTwainNotFoundCallback = function (ProductName, ip, port, bSSL, bMobile) {
  196. var _this = Dynamsoft;
  197. var ObjString;
  198. if(bMobile) {
  199. ObjString = [
  200. '<div class="dynamsoft-dwt-dlg-tips" style="font-size:1.5em">',
  201. 'The Dynamsoft Service is not configured correctly on ',
  202. '"', ip, '". Please check.',
  203. '</div>'
  204. ];
  205. } else {
  206. ObjString = [
  207. '<div class="dynamsoft-dwt-dlg-tips">',
  208. 'Dynamsoft Service is missing a certificate for the following IP/domain <br />',
  209. 'or isn\'t installed on the PC with the following IP/domain <br />',
  210. '"', ip, '".<br />',
  211. 'Please make sure you have put the correct certificate <br />',
  212. 'in the {Dynamsoft Service Directory}<br />',
  213. 'or that Dynamsoft Service is installed on that specified PC.',
  214. '</div>',
  215. '<div class="dynamsoft-dwt-dlg-tail">',
  216. '<div class="dynamsoft-dwt-dlg-red">After installation, please REFRESH your browser.</div></div>'
  217. ];
  218. }
  219. if (_this.DWT) {
  220. _this.DWT.ShowDialog(promptDlgWidth, 0, ObjString.join(''));
  221. } else {
  222. console.log("The Dynamsoft namespace is missing");
  223. }
  224. };
  225. Dynamsoft.OnRemoteWebTwainNeedUpgradeCallback = function (ProductName, ip, port, bSSL) {
  226. var _this = Dynamsoft;
  227. var ObjString = [
  228. '<div class="dynamsoft-dwt-dlg-tips">',
  229. 'Dynamsoft Service is outdated on the PC with IP/domain <br />',
  230. '"', ip, '".<br />',
  231. 'Please open the page on that PC to download and install it.',
  232. '</div>',
  233. '<div class="dynamsoft-dwt-dlg-tail">',
  234. '<div class="dynamsoft-dwt-dlg-red">After installation, please REFRESH your browser.</div></div>'
  235. ];
  236. if (_this.DWT) {
  237. _this.DWT.ShowDialog(promptDlgWidth, 0, ObjString.join(''));
  238. } else {
  239. console.log("The Dynamsoft namespace is missing");
  240. }
  241. };
  242. Dynamsoft.OnWebTWAINDllDownloadSuccessful = function () {
  243. console.log('The Web TWAIN Module was downloaded successfully!');
  244. };
  245. Dynamsoft.OnWebTWAINDllDownloadFailure = function (ProductName, errorCode, errorString) {
  246. var _this = Dynamsoft;
  247. if (_this.DWT) {
  248. if (errorCode == -2371/* EnumDWT_Error.ModuleNotExists*/) {
  249. var ObjString = [
  250. '<div class="dynamsoft-dwt-dlg-tips">',
  251. errorString,
  252. '</div>',
  253. '<div class="dynamsoft-dwt-dlg-tail">',
  254. '<div class="dynamsoft-dwt-dlg-red">You can try <strong>REFRESHING</strong> your browser to try again. <br /> If the issue persists, please contact the website administrator.</div></div>'
  255. ];
  256. _this.DWT.ShowDialog(promptDlgWidth, 0, ObjString.join(''));
  257. }
  258. return true;
  259. } else {
  260. console.log("The Dynamsoft namespace is missing");
  261. }
  262. };
  263. Dynamsoft.OnGetServiceUpdateStatus = function (bError, statusCode, statusString) {
  264. if (statusString != "Update skipped")
  265. console.log(statusString);
  266. };
  267. Dynamsoft.OnWebTWAINModuleDownloadManually = function (objInstallerUrl, iPlatform, bIE, bSafari, bSSL, strIEVersion) {
  268. var _this = Dynamsoft;
  269. return _this._show_install_dialog('', objInstallerUrl, true, iPlatform, bIE, bSafari, bSSL, strIEVersion);
  270. };
  271. Dynamsoft.OnLTSLicenseError = function (message) {
  272. var addMessage = '', ObjString, lexp = Dynamsoft.DWT.licenseException, code = 0;
  273. if(lexp)
  274. code = lexp.code;
  275. if(code == -2440 || // NetworkError
  276. code == -2441 || // Timedout
  277. code == -2443 || // CorsError
  278. code == -2446 || // LtsJsLoadError
  279. message.indexOf('Internet connection')>-1 ||
  280. message.indexOf('Storage')>-1) {
  281. var purchaseUrl = 'https://www.dynamsoft.com/customer/license/trialLicense?product=dwt&deploymenttype=js';
  282. addMessage = '<div>You can register for a free 30-day trial <a href="' + purchaseUrl + '" target="_blank" class="dynamsoft-major-color">here</a>. Make sure to select the product Dynamic Web TWAIN.</div>';
  283. }
  284. ObjString = [
  285. '<div class="dynamsoft-dialog dynamsoft-dialog2">',
  286. '<div class="dynamsoft-dwt-ltsdlg-header"><span style="color:#FFF;line-height:30px;margin-left:10px">Error</span><div class="dynamsoft-dialog-close">x</div></div>',
  287. '<div class="dynamsoft-dwt-ltsdlg-body">',
  288. message,
  289. addMessage,
  290. '</div></div>'
  291. ];
  292. Dynamsoft.Lib.ShowLicenseDialog(ObjString.join(''), {
  293. width: promptDlgWidth2,
  294. height: 0,
  295. bClose: true
  296. });
  297. };
  298. Dynamsoft.OnLTSConnectionFailure = Dynamsoft.OnLTSLicenseError;
  299. Dynamsoft.OnLTSReturnedAnError = Dynamsoft.OnLTSLicenseError;
  300. Dynamsoft.OnLTSUUIDError = Dynamsoft.OnLTSLicenseError;
  301. Dynamsoft.OnLTSConnectionWarning = function () {
  302. var ObjString = [
  303. '<div class="dynamsoft-dialog dynamsoft-dialog2">',
  304. '<div class="dynamsoft-dwt-ltsdlg-header"><span style="color:#FFF;line-height:30px;margin-left:10px">Warning</span><div class="dynamsoft-dialog-close">x</div></div>',
  305. '<div class="dynamsoft-dwt-ltsdlg-body">',
  306. 'Warning: You are seeing this dialog because Dynamic Web TWAIN has failed to connect to the License Tracking Server. ',
  307. 'A cached authorization is being used, and you can continue to use the software as usual. ',
  308. 'Please get connected to the network as soon as possible. ',
  309. Dynamsoft.DWT.isPublicLicense() ? '<a class="dynamsoft-major-color" href="https://www.dynamsoft.com/company/contact/">Contact Dynamsoft</a> ' : 'Contact the site administrator ',
  310. 'for more information.',
  311. '</div></div>'
  312. ].join('');
  313. Dynamsoft.Lib.ShowLicenseDialog(ObjString, {
  314. width: promptDlgWidth2,
  315. height: 0,
  316. bClose: true
  317. });
  318. };
  319. Dynamsoft.OnLTSPublicLicenseMessage = function (message) {
  320. var ObjString = [
  321. '<div class="dynamsoft-dialog dynamsoft-dialog2">',
  322. '<div class="dynamsoft-dwt-ltsdlg-header"><span style="color:#FFF;line-height:30px;margin-left:10px">Warning</span><div class="dynamsoft-dialog-close">x</div></div>',
  323. '<div class="dynamsoft-dwt-ltsdlg-body">',
  324. message,
  325. '</div></div>'
  326. ].join('');
  327. Dynamsoft.Lib.ShowLicenseDialog(ObjString, {
  328. width: promptDlgWidth2,
  329. height: 0,
  330. bClose: true
  331. });
  332. };
  333. })();