Repository navigation
Expand file tree
/
Copy pathLSPInstallSupport.js
More file actions
1 lines (1 loc) · 2.13 KB
/
Copy pathLSPInstallSupport.js
File metadata and controls
1 lines (1 loc) · 2.13 KB
1
define(function(require,exports,module){const TaskManager=require("features/TaskManager"),Dialogs=require("widgets/Dialogs"),Strings=require("strings"),_=require("thirdparty/lodash");function today(){const now=new Date;return now.getFullYear()+"-"+(now.getMonth()+1)+"-"+now.getDate()}function create(id,title,iconHTML){const storageKey="lsp-install-"+id;let recoveryTask=null;function readState(){try{const state=JSON.parse(PhStore.getItem(storageKey)||"null");return state&&"object"==typeof state?state:{}}catch(err){return{}}}function canAutoInstall(){return readState().date!==today()}function clearTask(){recoveryTask&&(recoveryTask.close(),recoveryTask=null)}function recordAttempt(){clearTask(),PhStore.setItem(storageKey,JSON.stringify({date:today()}))}function showDetails(){const error=readState().error;if(!error)return;const dialog=Dialogs.showModalDialog("lsp-install-error",title,"<p>"+_.escape(Strings.LSP_INSTALL_ERROR_DETAILS)+'</p><pre style="white-space:pre-wrap;overflow-wrap:anywhere;max-height:300px;overflow:auto;">'+_.escape(error)+"</pre>",[{className:"left",id:"copy",text:Strings.COPY_ERROR},{className:"primary",id:Dialogs.DIALOG_BTN_OK,text:Strings.OK}],!1);dialog.getElement().on("buttonClick",function(event,buttonId){"copy"===buttonId?Phoenix.app.copyToClipboard(error):dialog.close()})}function showManualInstall(install){recoveryTask||((recoveryTask=TaskManager.addNewTask(title,Strings.LSP_INSTALL_MANUAL,iconHTML,{noSpinnerNotification:!0,hideProgressBar:!0,onRetryClick:function(){clearTask(),install()},onStopClick:clearTask,onSelect:showDetails})).showRestartIcon(Strings.LSP_INSTALL_NOW),recoveryTask.showStopIcon(Strings.CLOSE))}function showFailure(task,error){const state=readState();state.error=error&&error.message||String(error),PhStore.setItem(storageKey,JSON.stringify(state)),recoveryTask=task,task.onSelect=showDetails,task.onStopClick=clearTask,task.setFailed(),task.setMessage(Strings.LSP_INSTALL_FAILED),task.showRestartIcon(Strings.LSP_INSTALL_NOW),task.showStopIcon(Strings.CLOSE)}return{canAutoInstall:canAutoInstall,recordAttempt:recordAttempt,showManualInstall:showManualInstall,showFailure:showFailure}}exports.create=create});