UNPKG

@jsjoeio/code-server

Version:

Run VS Code on a remote server.

6 lines (4 loc) 8.04 kB
/*!-------------------------------------------------------- * Copyright (C) Microsoft Corporation. All rights reserved. *--------------------------------------------------------*/(function(){var R=["vs/code/browser/workbench/workbench","require","exports","vs/workbench/workbench.web.api","vs/base/common/uri","vs/base/common/event","vs/base/common/uuid","vs/base/common/cancellation","vs/base/common/buffer","vs/base/common/lifecycle","vs/base/parts/request/browser/request","vs/platform/windows/common/windows","vs/base/common/resources","vs/base/browser/browser","vs/nls!vs/code/browser/workbench/workbench","vs/base/common/network","vs/platform/product/common/product"],N=function(v){for(var l=[],u=0,f=v.length;u<f;u++)l[u]=R[v[u]];return l};define(R[0],N([1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16]),function(v,l,u,f,O,P,T,q,C,A,s,Y,D,w,g,I){"use strict";Object.defineProperty(l,"__esModule",{value:!0}),l.encodePath=void 0;function S(d,e){let t;if(e){let r=0;e.forEach((o,c)=>{t||(t=""),t+=`${r++==0?"":"&"}${c}=${encodeURIComponent(o)}`})}return f.URI.parse(window.location.href).with({path:d,query:t})}const M=d=>d.split("/").map(e=>encodeURIComponent(e)).join("/");l.encodePath=M;class h{constructor(){let e;const t=document.getElementById("vscode-workbench-auth-session"),r=t?t.getAttribute("data-settings"):void 0;if(r)try{e=JSON.parse(r)}catch(o){}e&&(this.setPassword(`${I.default.urlProtocol}.login`,"account",JSON.stringify(e)),this.authService=`${I.default.urlProtocol}-${e.providerId}.login`,this.setPassword(this.authService,"account",JSON.stringify(e.scopes.map(o=>({id:e.id,scopes:o,accessToken:e.accessToken})))))}get credentials(){if(!this._credentials){try{const e=window.localStorage.getItem(h.CREDENTIALS_OPENED_KEY);e&&(this._credentials=JSON.parse(e))}catch(e){}Array.isArray(this._credentials)||(this._credentials=[])}return this._credentials}save(){window.localStorage.setItem(h.CREDENTIALS_OPENED_KEY,JSON.stringify(this.credentials))}async getPassword(e,t){return this.doGetPassword(e,t)}async doGetPassword(e,t){for(const r of this.credentials)if(r.service===e&&(typeof t!="string"||t===r.account))return r.password;return null}async setPassword(e,t,r){this.doDeletePassword(e,t),this.credentials.push({service:e,account:t,password:r}),this.save();try{if(r&&e===this.authService){const o=JSON.parse(r);Array.isArray(o)&&o.length===0&&await this.logout(e)}}catch(o){console.log(o)}}async deletePassword(e,t){const r=await this.doDeletePassword(e,t);if(r&&e===this.authService)try{await this.logout(e)}catch(o){console.log(o)}return r}async doDeletePassword(e,t){let r=!1;return this._credentials=this.credentials.filter(o=>o.service===e&&o.account===t?(r=!0,!1):!0),r&&this.save(),r}async findPassword(e){return this.doGetPassword(e)}async findCredentials(e){return this.credentials.filter(t=>t.service===e).map(({account:t,password:r})=>({account:t,password:r}))}async logout(e){const t=new Map;t.set("logout",String(!0)),t.set("service",e),await A.request({url:S("/auth/logout",t).toString(!0)},T.CancellationToken.None)}}h.CREDENTIALS_OPENED_KEY="credentials.provider";class n extends C.Disposable{constructor(){super(...arguments);this._onCallback=this._register(new O.Emitter),this.onCallback=this._onCallback.event}create(e){const t=new Map,r=P.generateUuid();t.set(n.QUERY_KEYS.REQUEST_ID,r);const{scheme:o,authority:c,path:i,query:U,fragment:m}=e||{scheme:void 0,authority:void 0,path:void 0,query:void 0,fragment:void 0};return o&&t.set(n.QUERY_KEYS.SCHEME,o),c&&t.set(n.QUERY_KEYS.AUTHORITY,c),i&&t.set(n.QUERY_KEYS.PATH,i),U&&t.set(n.QUERY_KEYS.QUERY,U),m&&t.set(n.QUERY_KEYS.FRAGMENT,m),this.periodicFetchCallback(r,Date.now()),S("/callback",t)}async periodicFetchCallback(e,t){const r=new Map;r.set(n.QUERY_KEYS.REQUEST_ID,e);const o=await A.request({url:S("/fetch-callback",r).toString(!0)},T.CancellationToken.None),c=await q.streamToBuffer(o.stream);if(c.byteLength>0){try{this._onCallback.fire(f.URI.revive(JSON.parse(c.toString())))}catch(i){console.error(i)}return}Date.now()-t<n.FETCH_TIMEOUT&&setTimeout(()=>this.periodicFetchCallback(e,t),n.FETCH_INTERVAL)}}n.FETCH_INTERVAL=500,n.FETCH_TIMEOUT=5*60*1e3,n.QUERY_KEYS={REQUEST_ID:"vscode-requestId",SCHEME:"vscode-scheme",AUTHORITY:"vscode-authority",PATH:"vscode-path",QUERY:"vscode-query",FRAGMENT:"vscode-fragment"};class a{constructor(e,t){this.workspace=e,this.payload=t,this.trusted=!0}async open(e,t){if((t==null?void 0:t.reuse)&&!t.payload&&this.isSame(this.workspace,e))return!0;const r=this.createTargetUrl(e,t);if(r){if(t==null?void 0:t.reuse)return window.location.href=r,!0;{let o;return D.isStandalone?o=window.open(r,"_blank","toolbar=no"):o=window.open(r),!!o}}return!1}createTargetUrl(e,t){let r;if(!e)r=`${document.location.origin}${document.location.pathname}?${a.QUERY_PARAM_EMPTY_WINDOW}=true`;else if(s.isFolderToOpen(e)){const o=e.folderUri.scheme===g.Schemas.vscodeRemote?l.encodePath(e.folderUri.path):encodeURIComponent(e.folderUri.toString());r=`${document.location.origin}${document.location.pathname}?${a.QUERY_PARAM_FOLDER}=${o}`}else if(s.isWorkspaceToOpen(e)){const o=e.workspaceUri.scheme===g.Schemas.vscodeRemote?l.encodePath(e.workspaceUri.path):encodeURIComponent(e.workspaceUri.toString());r=`${document.location.origin}${document.location.pathname}?${a.QUERY_PARAM_WORKSPACE}=${o}`}return(t==null?void 0:t.payload)&&(r+=`&${a.QUERY_PARAM_PAYLOAD}=${encodeURIComponent(JSON.stringify(t.payload))}`),r}isSame(e,t){return!e||!t?e===t:s.isFolderToOpen(e)&&s.isFolderToOpen(t)?Y.isEqual(e.folderUri,t.folderUri):s.isWorkspaceToOpen(e)&&s.isWorkspaceToOpen(t)?Y.isEqual(e.workspaceUri,t.workspaceUri):!1}hasRemote(){if(this.workspace){if(s.isFolderToOpen(this.workspace))return this.workspace.folderUri.scheme===g.Schemas.vscodeRemote;if(s.isWorkspaceToOpen(this.workspace))return this.workspace.workspaceUri.scheme===g.Schemas.vscodeRemote}return!0}}a.QUERY_PARAM_EMPTY_WINDOW="ew",a.QUERY_PARAM_FOLDER="folder",a.QUERY_PARAM_WORKSPACE="workspace",a.QUERY_PARAM_PAYLOAD="payload";class Q{constructor(e){this.onDidChange=O.Event.None;let t,r;if(e){let o;s.isFolderToOpen(e)?o=e.folderUri:s.isWorkspaceToOpen(e)&&(o=e.workspaceUri),((o==null?void 0:o.scheme)==="github"||(o==null?void 0:o.scheme)==="codespace")&&([t,r]=o.authority.split("+"))}r&&t?(this.label=w.localize(0,null,t,r),this.tooltip=w.localize(1,null,t,r)):(this.label=w.localize(2,null),this.tooltip=w.localize(3,null))}}(function(){var d;const e=document.getElementById("vscode-workbench-web-configuration"),t=e?e.getAttribute("data-settings"):void 0;if(!e||!t)throw new Error("Missing web configuration element");const r=Object.assign({webviewEndpoint:`${window.location.origin}${window.location.pathname.replace(/\/+$/,"")}/webview`},JSON.parse(t)),o=E=>E.replace(/^https?:\/\//,"");r.remoteAuthority&&(r.remoteAuthority=o(r.remoteAuthority)),r.workspaceUri&&r.workspaceUri.authority&&(r.workspaceUri.authority=o(r.workspaceUri.authority)),r.folderUri&&r.folderUri.authority&&(r.folderUri.authority=o(r.folderUri.authority));let c=!1,i,U=((d=r.workspaceProvider)===null||d===void 0?void 0:d.payload)||Object.create(null);c||(r.folderUri?i={folderUri:f.URI.revive(r.folderUri)}:r.workspaceUri?i={workspaceUri:f.URI.revive(r.workspaceUri)}:i=void 0);const m=new a(i,U);let $;m.hasRemote()||($=new Q(i));const _=E=>{let y=`quality=${E}`;new URL(document.location.href).searchParams.forEach((b,p)=>{p!=="quality"&&(y+=`&${p}=${b}`)}),window.location.href=`${window.location.origin}?${y}`},k=r.settingsSyncOptions?{enabled:r.settingsSyncOptions.enabled,enablementHandler:E=>{let y=`settingsSync=${E?"true":"false"}`;new URL(document.location.href).searchParams.forEach((b,p)=>{p!=="settingsSync"&&(y+=`&${p}=${b}`)}),window.location.href=`${window.location.origin}?${y}`}}:void 0;u.create(document.body,Object.assign(Object.assign({},r),{settingsSyncOptions:k,windowIndicator:$,productQualityChangeHandler:_,workspaceProvider:m,urlCallbackProvider:new n,credentialsProvider:new h}))})()})}).call(this); //# sourceMappingURL=workbench.js.map