Commit 99468679 authored by wudizhanche1000's avatar wudizhanche1000

apps.json移动到服务端

parent e133d336
...@@ -57,7 +57,7 @@ export class AppsService { ...@@ -57,7 +57,7 @@ export class AppsService {
private downloadService: DownloadService, private ngZone: NgZone) { private downloadService: DownloadService, private ngZone: NgZone) {
} }
get lastVisted(): App|undefined { get lastVisited(): App|undefined {
let id = localStorage.getItem("last_visited"); let id = localStorage.getItem("last_visited");
if (id) { if (id) {
return this.apps.get(id); return this.apps.get(id);
...@@ -65,16 +65,26 @@ export class AppsService { ...@@ -65,16 +65,26 @@ export class AppsService {
return undefined; return undefined;
} }
set lastVisted(app: App|undefined) { set lastVisited(app: App|undefined) {
if (app) { if (app) {
localStorage.setItem("last_visited", app.id); localStorage.setItem("last_visited", app.id);
} }
} }
async loadApps() { async loadApps() {
let data = await let appsURL = 'https://wudizhanche.mycard.moe/downloads/apps.json';
this.http.get('./apps.json').map((response) => response.json()).toPromise(); try {
this.apps = this.loadAppsList(data); let data = await this.http.get(appsURL).map((response) => response.json()).toPromise();
localStorage.setItem("apps_json", appsURL);
this.apps = this.loadAppsList(data);
} catch (e) {
let data = localStorage.getItem("apps_json");
if (data) {
this.apps = this.loadAppsList(data);
} else {
this.apps = new Map();
}
}
return this.apps; return this.apps;
} }
......
...@@ -30,34 +30,42 @@ export class LobbyComponent implements OnInit { ...@@ -30,34 +30,42 @@ export class LobbyComponent implements OnInit {
async ngOnInit() { async ngOnInit() {
this.apps = await this.appsService.loadApps(); this.apps = await this.appsService.loadApps();
for (let app of this.apps.values()) { if (this.apps.size > 0) {
this.appsService.update(app); this.chooseApp(this.appsService.lastVisited || this.apps.get("ygopro")!);
}
this.chooseApp(this.appsService.lastVisted || this.apps.get("ygopro")!);
// 初始化聊天室 // 初始化聊天室
let url = new URL('candy/index.html', location.href); let url = new URL('candy/index.html', location.href);
let params: URLSearchParams = url['searchParams']; // TypeScrpt 缺了 url.searchParams 的定义 let params: URLSearchParams = url['searchParams']; // TypeScrpt 缺了 url.searchParams 的定义
params.set('jid', this.loginService.user.username + '@mycard.moe'); params.set('jid', this.loginService.user.username + '@mycard.moe');
params.set('password', this.loginService.user.external_id.toString()); params.set('password', this.loginService.user.external_id.toString());
params.set('nickname', this.loginService.user.username); params.set('nickname', this.loginService.user.username);
switch (this.settingsService.getLocale()) { switch (this.settingsService.getLocale()) {
case 'zh-CN': case 'zh-CN':
params.set('language', 'cn'); params.set('language', 'cn');
break; break;
default: default:
params.set('language', 'en'); params.set('language', 'en');
} }
if (this.currentApp.conference) { if (this.currentApp.conference) {
params.set('autojoin', this.currentApp.conference + '@conference.mycard.moe'); params.set('autojoin', this.currentApp.conference + '@conference.mycard.moe');
}
this.candy_url = url;
await this.appsService.migrate();
for (let app of this.apps.values()) {
await this.appsService.update(app);
}
} else {
if (confirm("获取程序列表失败,是否重试?")) {
location.reload();
} else {
window.close();
}
} }
this.candy_url = url;
await this.appsService.migrate();
} }
chooseApp(app: App) { chooseApp(app: App) {
this.currentApp = app; this.currentApp = app;
this.appsService.lastVisted = app; this.appsService.lastVisited = app;
if (this.candy && this.currentApp.conference) { if (this.candy && this.currentApp.conference) {
(<WebViewElement>this.candy.nativeElement).send('join', this.currentApp.conference + '@conference.mycard.moe'); (<WebViewElement>this.candy.nativeElement).send('join', this.currentApp.conference + '@conference.mycard.moe');
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment