UNPKG

homebridge-config-ui-x

Version:

A web based management, configuration and control platform for Homebridge.

2 lines (1 loc) • 14 kB
import{a as me}from"./chunk-GAHGBZ7U.js";import{F as _e,c as ue,j as ge}from"./chunk-NAG4LCT2.js";import{a as te}from"./chunk-VYTJCKZA.js";import{a as K}from"./chunk-IL6HHVES.js";import{d as ee}from"./chunk-LKBXKG4K.js";import{C as de,D as ce,c as ie,d as $,e as ne,f as re,g as oe,j as M,m as se,r as ae,s as le,z as pe}from"./chunk-BQZ376DP.js";import{b as Z}from"./chunk-RFCSHRPV.js";import"./chunk-3APJQTJL.js";import{$c as X,Ea as n,Jb as V,Kb as z,Lc as j,Mb as p,Nb as x,Ob as _,Ra as H,Xc as A,Yc as J,Zc as Q,_b as G,aa as h,ab as q,cb as E,cd as I,db as T,dc as a,dd as Y,ec as l,fa as C,ga as v,ib as w,jb as s,kb as r,la as L,lb as m,o as N,qa as b,vb as P,xb as S,y as R,za as O,zb as g}from"./chunk-LTGI3NYM.js";import{a as W,b as D,h as F}from"./chunk-B4AJQJMI.js";var he=()=>["restoring","restarting","restore-complete"];function be(t,f){if(t&1){let e=P();s(0,"div",5)(1,"h4",6),p(2),a(3,"translate"),r(),m(4,"div",7),a(5,"translate"),s(6,"button",8),S("click",function(){C(e);let i=g();return v(i.onClickGettingStarted())}),p(7),a(8,"translate"),r(),s(9,"button",9),S("click",function(){C(e);let i=g();return v(i.onClickRestoreBackup())}),p(10),a(11,"translate"),r()()}t&2&&(n(2),x(l(3,4,"setup.welcome_to_homebridge")),n(2),w("innerHTML",l(5,6,"setup.intro"),O),n(3),_(" ",l(8,8,"setup.button_get_started")," "),n(3),_(" ",l(11,10,"setup_wizard_restore")," "))}function we(t,f){if(t&1){let e=P();s(0,"div",5)(1,"h4",6),p(2),a(3,"translate"),r(),s(4,"div",10),p(5),a(6,"translate"),r(),s(7,"div",11)(8,"form",12),S("ngSubmit",function(){C(e);let i=g();return v(i.createFirstUser())}),s(9,"div",13)(10,"span",14),m(11,"i",15),r(),m(12,"input",16),a(13,"translate"),r(),s(14,"div",13)(15,"span",14),m(16,"i",17),r(),m(17,"input",18),a(18,"translate"),r(),s(19,"div",13)(20,"span",14),m(21,"i",17),r(),m(22,"input",19),a(23,"translate"),r(),s(24,"div",20)(25,"button",21),S("click",function(){C(e);let i=g();return v(i.onClickCancelRestore())}),p(26),a(27,"translate"),r(),s(28,"button",22),p(29),a(30,"translate"),r()()()()()}if(t&2){let e=g();n(2),x(l(3,25,"setup.create_account")),n(3),x(l(6,27,"setup_wizard_create_info")),n(3),w("formGroup",e.createUserForm),n(4),z("is-valid",e.createUserForm.controls.username.dirty&&e.createUserForm.controls.username.valid)("is-invalid",e.createUserForm.controls.username.dirty&&e.createUserForm.controls.username.invalid),w("readonly",e.loading())("placeholder",l(13,29,"users.label_username")),n(5),z("is-valid",e.createUserForm.controls.password.dirty&&e.createUserForm.controls.password.valid)("is-invalid",e.createUserForm.controls.password.dirty&&e.createUserForm.controls.password.errors),w("readonly",e.loading())("placeholder",l(18,31,"users.label_password")),n(5),z("is-valid",e.createUserForm.controls.passwordConfirm.dirty&&e.createUserForm.controls.passwordConfirm.valid)("is-invalid",e.createUserForm.controls.passwordConfirm.dirty&&e.createUserForm.controls.passwordConfirm.errors),w("readonly",e.loading())("placeholder",l(23,33,"users.label_confirm_password")),n(3),w("disabled",e.restoreUploading()),n(),_(" ",l(27,35,"form.button_back")," "),n(2),w("disabled",e.createUserForm.invalid||e.loading()),n(),_(" ",l(30,37,"form.button_continue")," ")}}function xe(t,f){t&1&&(m(0,"i",25),p(1),a(2,"translate")),t&2&&(n(),_(" ",l(2,1,"backup.label_uploading")," "))}function Ce(t,f){t&1&&(p(0),a(1,"translate")),t&2&&_(" ",l(1,1,"form.button_continue")," ")}function ve(t,f){if(t&1){let e=P();s(0,"div",5)(1,"h4",6),p(2),a(3,"translate"),r(),s(4,"div",10),p(5),a(6,"translate"),r(),s(7,"input",23),S("change",function(i){C(e);let u=g();return v(u.handleRestoreFileInput(i))}),r(),s(8,"div",20)(9,"button",21),S("click",function(){C(e);let i=g();return v(i.onClickCancelRestore())}),p(10),a(11,"translate"),r(),s(12,"button",24),S("click",function(){C(e);let i=g();return v(i.onRestoreBackupClick())}),E(13,xe,3,3)(14,Ce,2,3),r()()()}if(t&2){let e=g();n(2),x(l(3,6,"setup_wizard_restore")),n(3),x(l(6,8,"backup.restore_help_one")),n(4),w("disabled",e.restoreUploading()),n(),_(" ",l(11,10,"form.button_back")," "),n(2),w("disabled",e.restoreUploading()||!e.selectedFile()),n(),T(e.restoreUploading()?13:14)}}function Se(t,f){t&1&&(p(0),a(1,"translate")),t&2&&_(" ",l(1,1,"setup_wizard_restoring")," ")}function ye(t,f){t&1&&(p(0),a(1,"translate")),t&2&&_(" ",l(1,1,"setup_wizard_starting")," ")}function ke(t,f){t&1&&(p(0),a(1,"translate")),t&2&&_(" ",l(1,1,"setup_wizard_complete")," ")}function ze(t,f){t&1&&(s(0,"a",27),p(1),a(2,"translate"),r()),t&2&&(n(),x(l(2,1,"form.button_continue")))}function Fe(t,f){if(t&1&&(s(0,"div",5)(1,"h4",6),E(2,Se,2,3)(3,ye,2,3)(4,ke,2,3),r(),m(5,"div",26),E(6,ze,3,3,"a",27),r()),t&2){let e=g();n(2),T(e.step()==="restoring"?2:e.step()==="restarting"?3:e.step()==="restore-complete"?4:-1),n(4),T(e.step()==="restore-complete"?6:-1)}}function Ee(t,f){t&1&&(s(0,"div",5)(1,"h4",28),p(2),a(3,"translate"),r(),s(4,"div",10),p(5),a(6,"translate"),r(),s(7,"a",29),p(8),a(9,"translate"),r()()),t&2&&(n(2),x(l(3,3,"setup_wizard_complete_title")),n(3),x(l(6,5,"setup_wizard_completed")),n(3),x(l(9,7,"form.button_continue")))}var Qe=(()=>{class t{$api=h(Y);$auth=h(ee);$errors=h(te);$settings=h(Z);$title=h(A);$toastr=h(X);$translate=h(J);$ws=h(me);destroyRef=h(L);step=b("welcome");backgroundStyle=b(void 0);progress=b(1);restoreInProgress=b(!1);restoreStarted=b(!1);restoreFailed=b(!1);loading=b(!1);selectedFile=b(void 0);restoreUploading=b(!1);io;createUserForm=new oe({username:new M("",[$.required]),password:new M("",[$.required,$.minLength(4)]),passwordConfirm:new M("",[$.required])},this.matchPassword);ngOnInit(){this.$title.setTitle(this.$translate.instant("setup_wizard_page_title")),this.setBackground()}onClickGettingStarted(){this.step.set("create-account"),this.progress.set(50)}onClickRestoreBackup(){this.step.set("restore-backup"),this.progress.set(20)}onClickCancelRestore(){this.selectedFile.set(void 0),this.step.set("welcome"),this.progress.set(1)}createFirstUser(){return F(this,null,function*(){this.loading.set(!0),this.progress.set(75);let e=this.createUserForm.getRawValue();e.name=e.username;try{yield this.$api.post("/setup-wizard/create-first-user",e),this.$settings.env.setupWizardComplete=!0,this.progress.set(100),this.loading.set(!1),yield this.$auth.login({username:e.username,password:e.password}),this.step.set("setup-complete")}catch(o){this.loading.set(!1),this.progress.set(50),console.error(o),this.$toastr.error(this.$errors.toToastMessage(o),this.$translate.instant("toast.title_error"))}})}handleRestoreFileInput(e){let o=e.target.files;if(o?.length){let i=o[0];if(i.size>globalThis.backup.maxBackupSize){e.target.value="",this.selectedFile.set(void 0),this.progress.set(20),this.$toastr.error(this.$translate.instant("backup.backup_exceeds_max_size",{maxBackupSizeText:globalThis.backup.maxBackupSizeText,size:`${(i.size/(1024*1024)).toFixed(1)}MB`}),this.$translate.instant("toast.title_error"));return}this.selectedFile.set(i),this.progress.set(40)}else this.selectedFile.set(void 0),this.progress.set(20)}onRestoreBackupClick(){return F(this,null,function*(){this.restoreUploading.set(!0),this.step.set("restoring"),this.progress.set(60);try{let e=yield this.$api.get("/setup-wizard/get-setup-wizard-token");window.localStorage.setItem(I.jwt.tokenKey,e.access_token),this.$auth.token=e.access_token,this.progress.set(65);let o=new FormData,i=this.selectedFile();o.append("restoreArchive",i,i.name),yield this.$api.post("/backup/restore",o),this.progress.set(70),this.io=this.$ws.connectToNamespace("backup");let u=document.getElementById("output"),d=null;this.io.socket.on("stdout",c=>{c.split(ge).forEach(y=>{if(!y)return;let B=y.replace(ue,"").trim();if(!B)return;if(_e.test(B))d||(d=document.createElement("div"),u.appendChild(d)),d.textContent=B;else{d&&(d.remove(),d=null);let k=document.createElement("div");k.textContent=B,y.includes("[0;31m")?k.classList.add("red-text"):y.includes("[0;32m")?k.classList.add("green-text"):y.includes("[0;33m")?k.classList.add("orange-text"):y.includes("[0;36m")&&k.classList.add("cyan-text"),u.appendChild(k)}u.scrollTop=u.scrollHeight})}),this.restoreStarted.set(!0),this.restoreInProgress.set(!0),this.progress.set(75),yield N(this.io.request("do-restore")),this.progress.set(80),this.restoreInProgress.set(!1),yield this.$api.put("/backup/restart",{}),this.step.set("restarting"),this.progress.set(85),window.localStorage.removeItem(I.jwt.tokenKey),this.$auth.token=null;let U=document.createElement("div");U.classList.add("orange-text"),U.innerHTML="Starting Homebridge, please wait...",u.appendChild(U),u.scrollTop=u.scrollHeight,yield new Promise(c=>setTimeout(c,3e3)),this.progress.set(88),yield new Promise(c=>setTimeout(c,3e3)),this.progress.set(91),yield new Promise(c=>setTimeout(c,3e3)),this.progress.set(94),yield new Promise(c=>setTimeout(c,3e3)),this.progress.set(97),yield new Promise(c=>setTimeout(c,3e3)),this.progress.set(99);let fe=R(1e3).pipe(K(this.destroyRef)).subscribe(()=>F(this,null,function*(){try{yield this.$api.get("/auth/settings"),fe.unsubscribe(),this.progress.set(100),this.restoreUploading.set(!1),this.step.set("restore-complete")}catch(c){}}))}catch(e){console.error(e),this.restoreUploading.set(!1),this.restoreFailed.set(!0),this.progress.set(20),this.step.set("restore-backup"),this.$toastr.error(this.$errors.toToastMessage(e),this.$translate.instant("toast.title_error"))}finally{this.io&&this.io.end?.()}})}setBackground(){return F(this,null,function*(){if(this.$settings.settingsLoaded||(yield N(this.$settings.onSettingsLoaded)),this.$settings.env.customWallpaperHash){let e=`${I.api.base}/auth/wallpaper/${this.$settings.env.customWallpaperHash}`;this.backgroundStyle.set(`url('${e}') center/cover`)}})}matchPassword(e){let o=e.get("passwordConfirm"),i=e.get("password").value,u=o.value,d=W({},o.errors??{});return delete d.matchPassword,i!==u?(o.setErrors(D(W({},d),{matchPassword:!0})),{matchPassword:!0}):(o.setErrors(Object.keys(d).length?d:null),null)}static \u0275fac=function(o){return new(o||t)};static \u0275cmp=H({type:t,selectors:[["app-setup-wizard"]],decls:10,vars:11,consts:[[1,"setup-container","gradient","d-flex","align-items-start","justify-content-center"],[1,"w-100","setup-card","d-flex","py-4","flex-column"],["ngSrc","assets/homebridge-color-round.webp","alt","Homebridge Logo","height","100","width","100","priority","true",1,"homebridge-logo","mx-auto","my-3"],[1,"progress","w-100","my-4"],["role","progressbar","aria-valuemin","0","aria-valuemax","100",1,"progress-bar","progress-bar-striped","bg-success"],[1,"w-100","d-flex","flex-column","align-items-center","mb-2"],[1,"mb-3","text-center"],[1,"mb-4","small","grey-text","text-center",3,"innerHTML"],["type","button",1,"btn","btn-lg","btn-primary","mb-4",3,"click"],["type","button",1,"btn","btn-link","grey-text","p-0",3,"click"],[1,"mb-4","small","grey-text","text-center"],[1,"w-100"],["novalidate","",3,"ngSubmit","formGroup"],[1,"input-group","mb-4"],[1,"input-group-text","custom-input"],["aria-hidden","true",1,"fas","fa-user","primary-text","fa-lg"],["formControlName","username","type","text","id","form-username","autocomplete","username","autocapitalize","none","tabindex","0","required","",1,"form-control","custom-input",3,"readonly","placeholder"],["aria-hidden","true",1,"fas","fa-lock","primary-text","fa-lg"],["formControlName","password","type","password","id","form-pass","autocomplete","new-password","tabindex","0","required","",1,"form-control","custom-input",3,"readonly","placeholder"],["formControlName","passwordConfirm","type","password","id","form-pass-confirm","autocomplete","new-password","tabindex","0","required","",1,"form-control","custom-input",3,"readonly","placeholder"],[1,"mt-3","w-100","d-flex","justify-content-between"],["type","button",1,"btn","btn-elegant","ms-0",3,"click","disabled"],["type","submit",1,"btn","btn-primary",3,"disabled"],["type","file","id","restoreFileUpload","accept","application/gzip, .gz",1,"form-control","custom-input","mb-3",3,"change"],["type","button",1,"btn","btn-primary","me-0",3,"click","disabled"],["aria-hidden","true",1,"fas","fa-circle-notch","fa-spin"],["id","output",1,"font-monospace","small","alert","alert-info","w-100","text-start","mt-1","mb-0"],["href","/login",1,"btn","btn-lg","btn-primary","mt-4"],[1,"mb-3"],["href","/",1,"btn","btn-lg","btn-primary"]],template:function(o,i){o&1&&(s(0,"div",0)(1,"div",1),m(2,"img",2),s(3,"div",3),m(4,"div",4),r(),E(5,be,12,12,"div",5)(6,we,31,39,"div",5)(7,ve,15,12,"div",5)(8,Fe,7,2,"div",5)(9,Ee,10,9,"div",5),r()()),o&2&&(V("background",i.backgroundStyle()),z("anim",!i.backgroundStyle()),n(4),V("width",`${i.progress()}%`),z("progress-bar-animated",i.loading()||i.restoreUploading()),q("aria-valuenow",i.progress()),n(),T(i.step()==="welcome"?5:i.step()==="create-account"?6:i.step()==="restore-backup"?7:G(10,he).includes(i.step())?8:i.step()==="setup-complete"?9:-1))},dependencies:[j,de,se,ie,ne,re,pe,ce,le,ae,Q],styles:[".setup-container[_ngcontent-%COMP%]{z-index:-1;padding-top:2em;padding-bottom:2em;min-height:100%;background-size:300% 300%}.anim[_ngcontent-%COMP%]{-webkit-animation:_ngcontent-%COMP%_gradient 20s ease infinite;-moz-animation:gradient 20s ease infinite;animation:_ngcontent-%COMP%_gradient 20s ease infinite}@keyframes _ngcontent-%COMP%_gradient{0%{background-position:0 50%}50%{background-position:100% 50%}to{background-position:0 50%}}.setup-card[_ngcontent-%COMP%]{max-width:550px;border-radius:1rem;padding-right:25px;padding-left:25px;background-color:#ffffffe6}.setup-card[_ngcontent-%COMP%] .form-control[_ngcontent-%COMP%]:focus{background-color:inherit!important}@media screen and (max-width:575px){.setup-card[_ngcontent-%COMP%]{margin-left:1em;margin-right:1em}}.homebridge-logo[_ngcontent-%COMP%]{margin-bottom:10px}.progress[_ngcontent-%COMP%]{background-color:#ddd}#output[_ngcontent-%COMP%]{height:200px;overflow-y:scroll;white-space:pre-wrap}"],changeDetection:0})}return t})();export{Qe as SetupWizardComponent};