From c71accd08144d6acad5e8081e011c0f2f9a11a55 Mon Sep 17 00:00:00 2001 From: EdgeNeko Date: Tue, 25 Feb 2020 19:04:39 +0800 Subject: [PATCH 01/71] feat: support connecting to community server --- src/app/Controllers/about.component.ts | 9 +++- src/app/Controllers/signin.component.ts | 69 +++++++++++++++++++++--- src/app/Models/ServerConfig.ts | 10 ++++ src/app/Services/ApiService.ts | 11 ++-- src/app/Services/InitService.ts | 18 ++++++- src/app/Styles/button.scss | 4 +- src/app/Styles/signin.scss | 71 +++++++++++++++++++++---- src/app/Views/about.html | 23 ++++---- src/app/Views/signin.html | 52 +++++++++++++----- src/main.ts | 2 - 10 files changed, 220 insertions(+), 49 deletions(-) create mode 100644 src/app/Models/ServerConfig.ts diff --git a/src/app/Controllers/about.component.ts b/src/app/Controllers/about.component.ts index ff9ef7bb..1c3c1714 100644 --- a/src/app/Controllers/about.component.ts +++ b/src/app/Controllers/about.component.ts @@ -1,6 +1,7 @@ import { Component } from '@angular/core'; import { CheckService } from '../Services/CheckService'; import { Values } from '../values'; +import { ApiService } from '../Services/ApiService'; @Component({ templateUrl: '../Views/about.html', @@ -12,12 +13,18 @@ import { Values } from '../values'; export class AboutComponent { public sourceCodeURL = Values.sourceCodeURL; + constructor( - public checkService: CheckService + public checkService: CheckService, + public apiService: ApiService ) { } public check(): void { this.checkService.checkVersion(true); } + + public getCurrentYear(): number { + return new Date().getFullYear(); + } } diff --git a/src/app/Controllers/signin.component.ts b/src/app/Controllers/signin.component.ts index 10b885e8..8c04d0c3 100644 --- a/src/app/Controllers/signin.component.ts +++ b/src/app/Controllers/signin.component.ts @@ -1,18 +1,73 @@ -import { Component } from '@angular/core'; -import { ApiService } from '../Services/ApiService'; +import { Component, OnInit } from '@angular/core'; import { ElectronService } from 'ngx-electron'; +import { ApiService } from '../Services/ApiService'; +import { InitService } from '../Services/InitService'; +import Swal from 'sweetalert2'; +import { HttpClient } from '@angular/common/http'; +import { ServerConfig } from '../Models/ServerConfig'; @Component({ templateUrl: '../Views/signin.html', styleUrls: ['../Styles/signin.scss', - '../Styles/button.scss'] + '../Styles/button.scss'] }) -export class SignInComponent { - public OAuthURL: string; +export class SignInComponent implements OnInit { + + public changingServer = false; + public serverAddr; constructor( public _electronService: ElectronService, - ) { - this.OAuthURL = ApiService.serverAddress; + public apiService: ApiService, + public initService: InitService, + public http: HttpClient, + ) { + } + + public clearCommunityServerData() { + localStorage.removeItem('serverConfig'); + this.changingServer = false; + this.initService.init(); + } + + public connectCommunity() { + if (!this.serverAddr) { + Swal.fire('Please input an valid server url!', '', 'error'); + return; } + if (!this.serverAddr.match(/^https?:\/\/.+/g)) { + this.serverAddr = 'https://' + this.serverAddr; + } + + Swal.fire({ + icon: 'info', + title: 'Fetching manifest from your community server...', + text: this.serverAddr, + showConfirmButton: false, + showCancelButton: false + }); + Swal.showLoading(); + this.http.get(this.serverAddr).subscribe({ + next: t => { + Swal.close(); + if (t.code !== 0) { + this.fireFailed(); + return; + } + t.officialServer = false; + t.serverUrl = this.serverAddr; + localStorage.setItem('serverConfig', JSON.stringify(t)); + this.changingServer = false; + this.initService.init(); + }, + error: _t => this.fireFailed() + }); + } + + fireFailed() { + Swal.fire('Failed to fetch manifest from server.', 'Check syntax, then contract the server\'s owner.', 'error'); + } + + ngOnInit(): void { + } } diff --git a/src/app/Models/ServerConfig.ts b/src/app/Models/ServerConfig.ts new file mode 100644 index 00000000..99828a37 --- /dev/null +++ b/src/app/Models/ServerConfig.ts @@ -0,0 +1,10 @@ +import { AiurProtocal } from './AiurProtocal'; + +export class ServerConfig extends AiurProtocal { + public serverUrl: string; + public apiVersion: string; + public vapidPublicKey: string; + public serverName: string; + public mode: string; + public officialServer: boolean; +} diff --git a/src/app/Services/ApiService.ts b/src/app/Services/ApiService.ts index bfcfd205..8f6b29c9 100644 --- a/src/app/Services/ApiService.ts +++ b/src/app/Services/ApiService.ts @@ -3,10 +3,13 @@ import { Observable } from 'rxjs/'; import { ParamService } from './ParamService'; import { HttpClient, HttpHeaders } from '@angular/common/http'; import { catchError } from 'rxjs/operators'; +import { ServerConfig } from '../Models/ServerConfig'; -@Injectable() +@Injectable({ + providedIn: 'root' +}) export class ApiService { - public static serverAddress; + public serverConfig: ServerConfig; private _headers: HttpHeaders = new HttpHeaders({ @@ -19,14 +22,14 @@ export class ApiService { } public Get(address: string): Observable { - return this.http.get(`${ApiService.serverAddress}${address}`, { + return this.http.get(`${this.serverConfig.serverUrl}${address}`, { headers: this._headers, withCredentials: true }).pipe(catchError(this.handleError)); } public Post(address: string, data: any): Observable { - return this.http.post(`${ApiService.serverAddress}${address}`, this.paramTool.param(data), { + return this.http.post(`${this.serverConfig.serverUrl}${address}`, this.paramTool.param(data), { headers: this._headers, withCredentials: true }).pipe(catchError(this.handleError)); diff --git a/src/app/Services/InitService.ts b/src/app/Services/InitService.ts index 1d73872f..1da64a04 100644 --- a/src/app/Services/InitService.ts +++ b/src/app/Services/InitService.ts @@ -10,6 +10,8 @@ import { DevicesApiService } from './DevicesApiService'; import { ThemeService } from './ThemeService'; import Swal from 'sweetalert2'; import { ProbeService } from './ProbeService'; +import { ServerConfig } from '../Models/ServerConfig'; +import { ApiService } from './ApiService'; @Injectable({ providedIn: 'root' @@ -25,10 +27,11 @@ export class InitService { private closeWebSocket = false; private options = { userVisibleOnly: true, - applicationServerKey: this.urlBase64ToUint8Array(environment.applicationServerKey) + applicationServerKey: null }; constructor( + private apiService: ApiService, private checkService: CheckService, private authApiService: AuthApiService, private router: Router, @@ -42,6 +45,19 @@ export class InitService { } public init(): void { + // load server config + if (localStorage.getItem('serverConfig')) { + const communityServerConfig = JSON.parse(localStorage.getItem('serverConfig')) as ServerConfig; + this.apiService.serverConfig = communityServerConfig; + this.options.applicationServerKey = this.urlBase64ToUint8Array(communityServerConfig.vapidPublicKey); + } else { + const serv = new ServerConfig(); + serv.serverUrl = environment.server; + serv.vapidPublicKey = environment.applicationServerKey; + serv.officialServer = true; + this.apiService.serverConfig = serv; + this.options.applicationServerKey = this.urlBase64ToUint8Array(serv.vapidPublicKey); + } this.online = navigator.onLine; this.closeWebSocket = false; this.checkService.checkVersion(false); diff --git a/src/app/Styles/button.scss b/src/app/Styles/button.scss index f8563f50..3c7a26a7 100644 --- a/src/app/Styles/button.scss +++ b/src/app/Styles/button.scss @@ -85,11 +85,11 @@ button, background-color: #f5f5f5; color: black; - &:hover:enabled { + &:hover { background-color: #e9e9e9; } - &:focus:enabled { + &:active { background-color: #bbb; } } diff --git a/src/app/Styles/signin.scss b/src/app/Styles/signin.scss index 72fee272..677a7483 100644 --- a/src/app/Styles/signin.scss +++ b/src/app/Styles/signin.scss @@ -1,3 +1,12 @@ +%header { + color: #339bf9; + font-weight: 400; + text-transform: uppercase; + font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, Helvetica, sans-serif; + text-shadow: 2px 2px 10px rgba(0, 0, 0, 0.2); + margin: 0; +} + .signin-back { width: 100%; height: 100%; @@ -25,21 +34,13 @@ overflow: hidden; } - h1, h3 { - color: #339bf9; - font-weight: 400; - text-transform: uppercase; - font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, Helvetica, sans-serif; - text-shadow: 2px 2px 10px rgba(0, 0, 0, 0.2); - margin: 0; - overflow: hidden; - } - h1 { + @extend %header; font-size: 2em; } h3 { + @extend %header; font-size: 1.5em; } } @@ -64,7 +65,7 @@ } p { - margin: 0 auto 8% auto; + margin: 4px 0 4px 0; } a { @@ -76,3 +77,51 @@ a { padding: 0 !important; margin-top: 8%; } + +.split-bar { + @extend %header; + clear: both; + user-select: none; + margin: 32px 0 32px 0; + position: relative; + display: inline-block; + font-size: 1.5em; + + &::before, &::after { + content: ' '; + display: block; + position: absolute; + top: 50%; + left: -120px; + width: 100px; // 100px line on either side + border-bottom: 2px solid #339bf9; + } + + &::after { + left: auto; + right: -120px; + } +} + +.text-warn { + color: #c62828; + font-size: 13px; +} + +.text-secure { + color: #5cb85c; + font-size: 13px; +} + +.inputAddr { + border: 1px solid var(--text-input-border-color); + color: var(--default-textcolor); + background-color: var(--text-input-bg); + border-radius: 6px; + height: 35px; + padding: 6px 12px; + font-size: 14px; + box-sizing: border-box; + outline: none; + width: 100%; +} diff --git a/src/app/Views/about.html b/src/app/Views/about.html index 23035472..d9213c48 100644 --- a/src/app/Views/about.html +++ b/src/app/Views/about.html @@ -41,17 +41,22 @@

Kahla {{checkService.version}}

Update history
- -
Download Kahla App
- Terms - | - Privacy Policy - | - Feedback -

Copyright © 2018 Aiursoft Corporation

+

Server connected: {{apiService.serverConfig.serverName}} ({{apiService.serverConfig.serverUrl}})

+

An aiursoft official server.

+

A community server.

+

+ Terms + | + Privacy Policy + | + Feedback +

+

Copyright © {{getCurrentYear()}} Aiursoft Corporation

diff --git a/src/app/Views/signin.html b/src/app/Views/signin.html index 05d7deb1..fa873128 100644 --- a/src/app/Views/signin.html +++ b/src/app/Views/signin.html @@ -3,19 +3,47 @@

Kahla

+

Select server

+

Login

-
-
- - - Forgot password? -
+
+ + + Forgot password? + +

+ You are connecting to {{this.apiService.serverConfig.serverUrl}} + {{this.apiService.serverConfig.officialServer ? '(Aiursoft official server)' : '(Not an official server)'}} + .

+ + +
+ +
+ +
community server
+
+ + +
+
+

Aiursoft CANNOT prove the community server is secure. You should NEVER connect to a server you don't + trust.

+

Chat data in community server will never be synced with one in official server.

+
diff --git a/src/main.ts b/src/main.ts index 6a474323..801054aa 100644 --- a/src/main.ts +++ b/src/main.ts @@ -1,12 +1,10 @@ import { enableProdMode } from '@angular/core'; import { platformBrowserDynamic } from '@angular/platform-browser-dynamic'; import { AppModule } from './app/app.module'; -import { ApiService } from './app/Services/ApiService'; import { environment } from './environments/environment'; if (environment.production) { enableProdMode(); } -ApiService.serverAddress = environment.server; platformBrowserDynamic().bootstrapModule(AppModule); From 4d5767f2a9cb006acf70519a1540ab2ba54c7a0c Mon Sep 17 00:00:00 2001 From: Anduin2017 Date: Mon, 2 Mar 2020 10:03:00 +0800 Subject: [PATCH 02/71] Downgrade Kahla version. --- package-lock.json | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/package-lock.json b/package-lock.json index bd79fabd..3283bede 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "kahla", - "version": "4.0.0", + "version": "3.9.3", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index 0f185589..6b1942a0 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "kahla", - "version": "4.0.0", + "version": "3.9.3", "description": "Kahla is a cross-platform business messaging app.", "author": "Aiursoft (https://www.aiursoft.com/)", "build": { From fca725bf22b32d3c79216e9e0fea4efeb7b610a6 Mon Sep 17 00:00:00 2001 From: Anduin Xue Date: Mon, 2 Mar 2020 10:53:13 +0800 Subject: [PATCH 03/71] Update package.json --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 6b1942a0..0f185589 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "kahla", - "version": "3.9.3", + "version": "4.0.0", "description": "Kahla is a cross-platform business messaging app.", "author": "Aiursoft (https://www.aiursoft.com/)", "build": { From 04eefd82b3b51f01f0e3e215c534980b2d8be748 Mon Sep 17 00:00:00 2001 From: EdgeNeko Date: Tue, 3 Mar 2020 00:08:28 +0800 Subject: [PATCH 04/71] feat: fetching official server config by server list api --- src/app/Controllers/signin.component.ts | 3 +- src/app/Models/ServerConfig.ts | 5 +- src/app/Services/ApiService.ts | 11 +++- src/app/Services/InitService.ts | 84 ++++++++++++++----------- src/app/Views/about.html | 2 +- src/app/Views/header.html | 4 +- src/app/Views/signin.html | 8 +-- src/environments/environment.ts | 5 +- 8 files changed, 70 insertions(+), 52 deletions(-) diff --git a/src/app/Controllers/signin.component.ts b/src/app/Controllers/signin.component.ts index 8c04d0c3..bd224061 100644 --- a/src/app/Controllers/signin.component.ts +++ b/src/app/Controllers/signin.component.ts @@ -50,12 +50,11 @@ export class SignInComponent implements OnInit { this.http.get(this.serverAddr).subscribe({ next: t => { Swal.close(); - if (t.code !== 0) { + if (t.code !== 0 || t.domain.server !== this.serverAddr) { this.fireFailed(); return; } t.officialServer = false; - t.serverUrl = this.serverAddr; localStorage.setItem('serverConfig', JSON.stringify(t)); this.changingServer = false; this.initService.init(); diff --git a/src/app/Models/ServerConfig.ts b/src/app/Models/ServerConfig.ts index 99828a37..489b4067 100644 --- a/src/app/Models/ServerConfig.ts +++ b/src/app/Models/ServerConfig.ts @@ -1,10 +1,13 @@ import { AiurProtocal } from './AiurProtocal'; export class ServerConfig extends AiurProtocal { - public serverUrl: string; public apiVersion: string; public vapidPublicKey: string; public serverName: string; public mode: string; public officialServer: boolean; + public domain: { + server: string, + client: string, + }; } diff --git a/src/app/Services/ApiService.ts b/src/app/Services/ApiService.ts index 8f6b29c9..7d6e5da1 100644 --- a/src/app/Services/ApiService.ts +++ b/src/app/Services/ApiService.ts @@ -9,6 +9,7 @@ import { ServerConfig } from '../Models/ServerConfig'; providedIn: 'root' }) export class ApiService { + public readonly STORAGE_SERVER_CONFIG = 'serverConfig'; public serverConfig: ServerConfig; private _headers: HttpHeaders = @@ -22,14 +23,18 @@ export class ApiService { } public Get(address: string): Observable { - return this.http.get(`${this.serverConfig.serverUrl}${address}`, { + return this.GetByFullUrl(`${this.serverConfig.domain.server}${address}`); + } + + public GetByFullUrl(address: string, withCredentials = true): Observable { + return this.http.get(address, { headers: this._headers, - withCredentials: true + withCredentials: withCredentials }).pipe(catchError(this.handleError)); } public Post(address: string, data: any): Observable { - return this.http.post(`${this.serverConfig.serverUrl}${address}`, this.paramTool.param(data), { + return this.http.post(`${this.serverConfig.domain.server}${address}`, this.paramTool.param(data), { headers: this._headers, withCredentials: true }).pipe(catchError(this.handleError)); diff --git a/src/app/Services/InitService.ts b/src/app/Services/InitService.ts index 1da64a04..e6ac2f8b 100644 --- a/src/app/Services/InitService.ts +++ b/src/app/Services/InitService.ts @@ -45,22 +45,6 @@ export class InitService { } public init(): void { - // load server config - if (localStorage.getItem('serverConfig')) { - const communityServerConfig = JSON.parse(localStorage.getItem('serverConfig')) as ServerConfig; - this.apiService.serverConfig = communityServerConfig; - this.options.applicationServerKey = this.urlBase64ToUint8Array(communityServerConfig.vapidPublicKey); - } else { - const serv = new ServerConfig(); - serv.serverUrl = environment.server; - serv.vapidPublicKey = environment.applicationServerKey; - serv.officialServer = true; - this.apiService.serverConfig = serv; - this.options.applicationServerKey = this.urlBase64ToUint8Array(serv.vapidPublicKey); - } - this.online = navigator.onLine; - this.closeWebSocket = false; - this.checkService.checkVersion(false); if (navigator.userAgent.match(/MSIE|Trident/)) { Swal.fire( 'Oops, it seems that you are opening Kahla in IE.', @@ -70,28 +54,56 @@ export class InitService { 'or Microsoft Edge.' ); } + + // load server config + if (localStorage.getItem(this.apiService.STORAGE_SERVER_CONFIG)) { + const communityServerConfig = JSON.parse(localStorage.getItem(this.apiService.STORAGE_SERVER_CONFIG)) as ServerConfig; + this.apiService.serverConfig = communityServerConfig; + } else { + this.router.navigate(['/signin'], {replaceUrl: true}); + this.apiService.GetByFullUrl>(environment.officialServerList, false).subscribe(servers => { + const target = servers.find(t => t.domain.client === window.location.origin); + if (target) { + target.officialServer = true; + this.apiService.serverConfig = target; + localStorage.setItem(this.apiService.STORAGE_SERVER_CONFIG, JSON.stringify(target)); + } + this.init(); + }); + return; + } + + this.online = navigator.onLine; + this.closeWebSocket = false; this.cacheService.initCache(); - this.authApiService.SignInStatus().subscribe(signInStatus => { - if (signInStatus.value === false) { - this.router.navigate(['/signin'], { replaceUrl: true }); - } else { - this.authApiService.Me().subscribe(p => { - if (p.code === 0) { - this.cacheService.cachedData.me = p.value; - this.cacheService.cachedData.me.avatarURL = this.probeService.encodeProbeFileUrl(p.value.iconFilePath); - this.themeService.ApplyThemeFromRemote(p.value); - if (!this._electronService.isElectronApp && navigator.serviceWorker) { - this.subscribeUser(); - this.updateSubscription(); + + if (this.apiService.serverConfig) { + this.options.applicationServerKey = this.urlBase64ToUint8Array(this.apiService.serverConfig.vapidPublicKey); + this.checkService.checkVersion(false); + this.authApiService.SignInStatus().subscribe(signInStatus => { + if (signInStatus.value === false) { + this.router.navigate(['/signin'], {replaceUrl: true}); + } else { + this.authApiService.Me().subscribe(p => { + if (p.code === 0) { + this.cacheService.cachedData.me = p.value; + this.cacheService.cachedData.me.avatarURL = this.probeService.encodeProbeFileUrl(p.value.iconFilePath); + this.themeService.ApplyThemeFromRemote(p.value); + if (!this._electronService.isElectronApp && navigator.serviceWorker) { + this.subscribeUser(); + this.updateSubscription(); + } + this.loadPusher(false); + this.cacheService.updateConversation(); + this.cacheService.updateFriends(); + this.cacheService.updateRequests(); } - this.loadPusher(false); - this.cacheService.updateConversation(); - this.cacheService.updateFriends(); - this.cacheService.updateRequests(); - } - }); - } - }); + }); + } + }); + } else { + this.router.navigate(['/signin'], {replaceUrl: true}); + } } private loadPusher(reconnect: boolean): void { diff --git a/src/app/Views/about.html b/src/app/Views/about.html index 507c4511..9b75012d 100644 --- a/src/app/Views/about.html +++ b/src/app/Views/about.html @@ -49,7 +49,7 @@

Kahla {{checkService.version}}

{{electronService.isElectronApp ? 'Open Kahla official site' : 'Download Kahla App'}}
-

Server connected: {{apiService.serverConfig.serverName}} ({{apiService.serverConfig.serverUrl}})

+

Server connected: {{apiService.serverConfig.serverName}} ({{apiService.serverConfig.domain.server}})

An aiursoft official server.

A community server.

diff --git a/src/app/Views/header.html b/src/app/Views/header.html index aaac7f38..60327eae 100644 --- a/src/app/Views/header.html +++ b/src/app/Views/header.html @@ -27,7 +27,7 @@

+ *ngIf="((!this.returnButton || !homeService.wideScreenEnabled) && initService.connecting)">
Connecting... @@ -35,7 +35,7 @@
+ *ngIf="((!this.returnButton || !homeService.wideScreenEnabled) && (!initService.online && !initService.connecting))">
Disconnected diff --git a/src/app/Views/signin.html b/src/app/Views/signin.html index fa873128..1d5c8001 100644 --- a/src/app/Views/signin.html +++ b/src/app/Views/signin.html @@ -6,12 +6,12 @@

Kahla

Select server

Login

-
- - @@ -19,7 +19,7 @@

Login

target="_blank" rel="noopener noreferrer">Forgot password?

- You are connecting to {{this.apiService.serverConfig.serverUrl}} + You are connecting to {{this.apiService.serverConfig.domain.server}} {{this.apiService.serverConfig.officialServer ? '(Aiursoft official server)' : '(Not an official server)'}} .

diff --git a/src/environments/environment.ts b/src/environments/environment.ts index 1b9d6efd..ba8c7e0d 100644 --- a/src/environments/environment.ts +++ b/src/environments/environment.ts @@ -1,5 +1,4 @@ export const environment = { - production: false, - server: 'https://dev.server.kahla.app', - applicationServerKey: 'BJOTNmtE1V5GyDiYtoUzWbWLiaVMyfdnXFTvneJCbi9mwpw7FAVgQgIR9JN43TWkpT7ezBes1fPYr4nPqV6qXA0' + production: false, + officialServerList: 'https://staging.kahla.app/servers', }; From b3d66021dce958a22f46d89a14ea1f68a40392e7 Mon Sep 17 00:00:00 2001 From: EdgeNeko Date: Tue, 3 Mar 2020 08:08:34 +0800 Subject: [PATCH 05/71] Correct version num. --- package-lock.json | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/package-lock.json b/package-lock.json index 3283bede..bd79fabd 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "kahla", - "version": "3.9.3", + "version": "4.0.0", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index 6b1942a0..0f185589 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "kahla", - "version": "3.9.3", + "version": "4.0.0", "description": "Kahla is a cross-platform business messaging app.", "author": "Aiursoft (https://www.aiursoft.com/)", "build": { From b287e0a215d13d830e46a8a6c09335067f9269bc Mon Sep 17 00:00:00 2001 From: EdgeNeko Date: Tue, 3 Mar 2020 15:54:32 +0800 Subject: [PATCH 06/71] Check if server version is outdated. --- src/app/Services/CheckService.ts | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/app/Services/CheckService.ts b/src/app/Services/CheckService.ts index 2fc5a368..57b7251e 100644 --- a/src/app/Services/CheckService.ts +++ b/src/app/Services/CheckService.ts @@ -3,6 +3,7 @@ import { AuthApiService } from './AuthApiService'; import Swal from 'sweetalert2'; import { versions } from '../../environments/versions'; import { ElectronService } from 'ngx-electron'; +import { ApiService } from './ApiService'; @Injectable({ providedIn: 'root' @@ -16,7 +17,8 @@ export class CheckService { constructor( private authApiService: AuthApiService, - private _electronService: ElectronService + private _electronService: ElectronService, + private apiService: ApiService ) { if (this.checkSwCache()) { navigator.serviceWorker.addEventListener('message', (t: MessageEvent) => { @@ -56,6 +58,12 @@ export class CheckService { latestAPIVersion[1] > currentVersion[1]) { Swal.fire('API version mismatch', 'API level is too far from client! You have to upgrade now!', 'warning'); this.redirectToDownload(downloadAddress, true); + } else if (latestVersion[0] < currentVersion[0] || + latestVersion[1] < currentVersion[1] || + latestVersion[2] < currentVersion[2] || + !this.apiService.serverConfig.officialServer) { + Swal.fire('Community server outdated!', 'The Client version is newer then the Server version.\n' + + 'Consider contact the host of the server for updating the kahla.server version to latest.', 'warning'); } else if (showAlert) { Swal.fire('Success', 'You are running the latest version of Kahla!', 'success'); } From 6aa671b422849705084ebe700a97284859dfcdc1 Mon Sep 17 00:00:00 2001 From: EdgeNeko Date: Tue, 3 Mar 2020 17:19:29 +0800 Subject: [PATCH 07/71] Fix the misreport of server outdated --- src/app/Services/CheckService.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/app/Services/CheckService.ts b/src/app/Services/CheckService.ts index 57b7251e..84b3e165 100644 --- a/src/app/Services/CheckService.ts +++ b/src/app/Services/CheckService.ts @@ -58,9 +58,9 @@ export class CheckService { latestAPIVersion[1] > currentVersion[1]) { Swal.fire('API version mismatch', 'API level is too far from client! You have to upgrade now!', 'warning'); this.redirectToDownload(downloadAddress, true); - } else if (latestVersion[0] < currentVersion[0] || + } else if ((latestVersion[0] < currentVersion[0] || latestVersion[1] < currentVersion[1] || - latestVersion[2] < currentVersion[2] || + latestVersion[2] < currentVersion[2]) && !this.apiService.serverConfig.officialServer) { Swal.fire('Community server outdated!', 'The Client version is newer then the Server version.\n' + 'Consider contact the host of the server for updating the kahla.server version to latest.', 'warning'); From b865d04cb6667f9acf4bebd359a5e55e4112ae78 Mon Sep 17 00:00:00 2001 From: EdgeNeko Date: Tue, 3 Mar 2020 17:27:17 +0800 Subject: [PATCH 08/71] Better server choose UI --- src/app/Views/signin.html | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/app/Views/signin.html b/src/app/Views/signin.html index 1d5c8001..201eda77 100644 --- a/src/app/Views/signin.html +++ b/src/app/Views/signin.html @@ -19,13 +19,17 @@

Login

target="_blank" rel="noopener noreferrer">Forgot password?

- You are connecting to {{this.apiService.serverConfig.domain.server}} + Server + connected: {{this.apiService.serverConfig.serverName}} + ({{this.apiService.serverConfig.domain.server}}) +

+

{{this.apiService.serverConfig.officialServer ? '(Aiursoft official server)' : '(Not an official server)'}} - .

+

- +
From abe0b8176f62ee3f4c33c611b35c23b5e8b1b2d2 Mon Sep 17 00:00:00 2001 From: EdgeNeko Date: Wed, 4 Mar 2020 10:43:54 +0800 Subject: [PATCH 09/71] Simplify server change UI --- src/app/Controllers/signin.component.ts | 3 +++ src/app/Styles/signin.scss | 2 +- src/app/Views/signin.html | 17 +++++------------ 3 files changed, 9 insertions(+), 13 deletions(-) diff --git a/src/app/Controllers/signin.component.ts b/src/app/Controllers/signin.component.ts index bd224061..0b668e36 100644 --- a/src/app/Controllers/signin.component.ts +++ b/src/app/Controllers/signin.component.ts @@ -68,5 +68,8 @@ export class SignInComponent implements OnInit { } ngOnInit(): void { + if (this.apiService.serverConfig && !this.apiService.serverConfig.officialServer) { + this.serverAddr = this.apiService.serverConfig.domain.server; + } } } diff --git a/src/app/Styles/signin.scss b/src/app/Styles/signin.scss index 677a7483..4bb4ca7c 100644 --- a/src/app/Styles/signin.scss +++ b/src/app/Styles/signin.scss @@ -56,7 +56,7 @@ color: #2391D3 !important; } -.forgetPassword { +.actionLink { margin: 5% auto; display: block; text-decoration: underline; diff --git a/src/app/Views/signin.html b/src/app/Views/signin.html index 201eda77..ecd848e1 100644 --- a/src/app/Views/signin.html +++ b/src/app/Views/signin.html @@ -4,7 +4,6 @@

Kahla

Select server

-

Login

@@ -38,7 +30,8 @@

Login

community server
- + From 8f01b876b2bc76e5518f0ac938425402ade8f3f4 Mon Sep 17 00:00:00 2001 From: EdgeNeko Date: Wed, 4 Mar 2020 10:57:05 +0800 Subject: [PATCH 10/71] minimal useless info when connecting to official server --- src/app/Styles/signin.scss | 5 ----- src/app/Views/signin.html | 4 ++-- 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/src/app/Styles/signin.scss b/src/app/Styles/signin.scss index 4bb4ca7c..503f014c 100644 --- a/src/app/Styles/signin.scss +++ b/src/app/Styles/signin.scss @@ -108,11 +108,6 @@ a { font-size: 13px; } -.text-secure { - color: #5cb85c; - font-size: 13px; -} - .inputAddr { border: 1px solid var(--text-input-border-color); color: var(--default-textcolor); diff --git a/src/app/Views/signin.html b/src/app/Views/signin.html index ecd848e1..5563a6eb 100644 --- a/src/app/Views/signin.html +++ b/src/app/Views/signin.html @@ -19,8 +19,8 @@

Select server

Server: {{this.apiService.serverConfig.serverName}} -

- {{this.apiService.serverConfig.officialServer ? '(Aiursoft official server)' : '(Not an official server)'}} +

+ (Not an official server)

From 3d7b35ad82c2ad3c10fd044ced9d649fceb1845a Mon Sep 17 00:00:00 2001 From: EdgeNeko Date: Sat, 7 Mar 2020 12:07:43 +0800 Subject: [PATCH 11/71] fix: don't make the user scare when switching server close #811 --- src/app/Controllers/signin.component.ts | 41 ++++++++++++++++++++----- src/app/Styles/signin.scss | 5 --- src/app/Views/signin.html | 17 +++------- 3 files changed, 38 insertions(+), 25 deletions(-) diff --git a/src/app/Controllers/signin.component.ts b/src/app/Controllers/signin.component.ts index 0b668e36..9f6bd0da 100644 --- a/src/app/Controllers/signin.component.ts +++ b/src/app/Controllers/signin.component.ts @@ -5,6 +5,7 @@ import { InitService } from '../Services/InitService'; import Swal from 'sweetalert2'; import { HttpClient } from '@angular/common/http'; import { ServerConfig } from '../Models/ServerConfig'; +import { environment } from '../../environments/environment'; @Component({ templateUrl: '../Views/signin.html', @@ -38,7 +39,6 @@ export class SignInComponent implements OnInit { if (!this.serverAddr.match(/^https?:\/\/.+/g)) { this.serverAddr = 'https://' + this.serverAddr; } - Swal.fire({ icon: 'info', title: 'Fetching manifest from your community server...', @@ -48,16 +48,41 @@ export class SignInComponent implements OnInit { }); Swal.showLoading(); this.http.get(this.serverAddr).subscribe({ - next: t => { - Swal.close(); - if (t.code !== 0 || t.domain.server !== this.serverAddr) { + next: serverConfig => { + if (serverConfig.code !== 0 || serverConfig.domain.server !== this.serverAddr) { + Swal.close(); this.fireFailed(); return; } - t.officialServer = false; - localStorage.setItem('serverConfig', JSON.stringify(t)); - this.changingServer = false; - this.initService.init(); + this.apiService.GetByFullUrl>(environment.officialServerList, false).subscribe(officialServer => { + Swal.close(); + const last = () => { + localStorage.setItem('serverConfig', JSON.stringify(serverConfig)); + this.changingServer = false; + this.initService.init(); + }; + if (officialServer.map(t => t.domain.server).includes(serverConfig.domain.server)) { + // an official server + serverConfig.officialServer = true; + last(); + } else { + Swal.fire({ + title: 'Connecting to a community server...', + text: 'Aiursoft CANNOT prove the community server is secure.\n' + + ' You should NEVER connect to a server you don\'t trust.\n' + + 'Chat data in community server will never be synced with one in official server.', + icon: 'warning', + showCancelButton: true, + confirmButtonText: 'Continue' + }).then(res => { + if (res.dismiss) { + return; + } + serverConfig.officialServer = false; + last(); + }); + } + }); }, error: _t => this.fireFailed() }); diff --git a/src/app/Styles/signin.scss b/src/app/Styles/signin.scss index 503f014c..780e459e 100644 --- a/src/app/Styles/signin.scss +++ b/src/app/Styles/signin.scss @@ -103,11 +103,6 @@ a { } } -.text-warn { - color: #c62828; - font-size: 13px; -} - .inputAddr { border: 1px solid var(--text-input-border-color); color: var(--default-textcolor); diff --git a/src/app/Views/signin.html b/src/app/Views/signin.html index 5563a6eb..4a44a68a 100644 --- a/src/app/Views/signin.html +++ b/src/app/Views/signin.html @@ -29,18 +29,11 @@

Select server

Aiursoft official server
community server
-
- - -
-
-

Aiursoft CANNOT prove the community server is secure. You should NEVER connect to a server you don't - trust.

-

Chat data in community server will never be synced with one in official server.

-
+ +
From 63f1254ccef9a79f46d2abdf948fa738ca004bbc Mon Sep 17 00:00:00 2001 From: EdgeNeko Date: Sun, 8 Mar 2020 13:00:36 +0800 Subject: [PATCH 12/71] feat: Allow set `Broswer Default` accent color. --- src/app/Controllers/theme.component.ts | 8 ++++---- src/app/Models/Themes.ts | 5 +++++ src/app/Services/ThemeService.ts | 10 +++++++++- src/app/Styles/menu.scss | 1 + src/app/Views/theme.html | 6 +++++- 5 files changed, 24 insertions(+), 6 deletions(-) diff --git a/src/app/Controllers/theme.component.ts b/src/app/Controllers/theme.component.ts index 1b08a749..40480df0 100644 --- a/src/app/Controllers/theme.component.ts +++ b/src/app/Controllers/theme.component.ts @@ -12,18 +12,18 @@ export class ThemeComponent implements OnInit { ) { } - public currentTheme: Themes = Themes.kahlaLight; + public currentTheme: Themes = Themes.kahlaAuto; public primaryColor: number; public accentColor: number; ngOnInit(): void { this.currentTheme = this.themeService.LocalThemeSetting; - this.primaryColor = Math.floor(this.currentTheme / 2); - this.accentColor = this.currentTheme % 2; + this.primaryColor = Math.floor(this.currentTheme / 3); + this.accentColor = this.currentTheme % 3; } public applyTheme() { - this.changeTheme(this.primaryColor * 2 + this.accentColor); + this.changeTheme(this.primaryColor * 3 + this.accentColor); } public changeTheme(theme: Themes) { diff --git a/src/app/Models/Themes.ts b/src/app/Models/Themes.ts index 602515f3..b578140d 100644 --- a/src/app/Models/Themes.ts +++ b/src/app/Models/Themes.ts @@ -1,12 +1,17 @@ export enum Themes { + kahlaAuto, kahlaLight, kahlaDark, + sakuraAuto, sakuraLight, sakuraDark, + violetAuto, violetLight, violetDark, + communistAuto, communistLight, communistDark, + grassAuto, grassLight, grassDark } diff --git a/src/app/Services/ThemeService.ts b/src/app/Services/ThemeService.ts index b52f8e08..05bda445 100644 --- a/src/app/Services/ThemeService.ts +++ b/src/app/Services/ThemeService.ts @@ -22,7 +22,15 @@ export class ThemeService { } ApplyTheme(theme: Themes) { - switch (theme) { + let themeComputed = theme; + if (theme % 3 === 0) { + if (matchMedia('(prefers-color-scheme: dark)').matches) { + themeComputed = theme + 2; + } else { + themeComputed = theme + 1; + } + } + switch (themeComputed) { case Themes.sakuraLight: document.body.className = 'theme-sakura-light'; document.querySelector('meta[name=theme-color]') diff --git a/src/app/Styles/menu.scss b/src/app/Styles/menu.scss index 55fb37b4..9d1d70b8 100644 --- a/src/app/Styles/menu.scss +++ b/src/app/Styles/menu.scss @@ -154,6 +154,7 @@ a { .select-button-group { margin: 4px 10px 4px 10px; + display: flex; } .select-button { diff --git a/src/app/Views/theme.html b/src/app/Views/theme.html index a65e5793..1bab161b 100644 --- a/src/app/Views/theme.html +++ b/src/app/Views/theme.html @@ -31,11 +31,15 @@
+ Browser default + + + Light - + Dark From 459c1466a9701ab223041d91d789eec313d57c1f Mon Sep 17 00:00:00 2001 From: EdgeNeko Date: Sun, 8 Mar 2020 19:52:10 +0800 Subject: [PATCH 13/71] fix: change accent color instantly when the system color changed. --- src/app/Services/ThemeService.ts | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/src/app/Services/ThemeService.ts b/src/app/Services/ThemeService.ts index 05bda445..5c304508 100644 --- a/src/app/Services/ThemeService.ts +++ b/src/app/Services/ThemeService.ts @@ -3,12 +3,17 @@ import { AuthApiService } from './AuthApiService'; import { Themes } from '../Models/Themes'; import { KahlaUser } from '../Models/KahlaUser'; -@Injectable() +@Injectable({ + providedIn: 'root', +}) export class ThemeService { constructor( private authApiService: AuthApiService, - ) { } + ) { + } + + public mediaListener: MediaQueryList; ApplyThemeFromRemote(remoteInfo: KahlaUser) { if (this.LocalThemeSetting !== remoteInfo.themeId) { @@ -24,11 +29,21 @@ export class ThemeService { ApplyTheme(theme: Themes) { let themeComputed = theme; if (theme % 3 === 0) { - if (matchMedia('(prefers-color-scheme: dark)').matches) { + if (!this.mediaListener) { + this.mediaListener = matchMedia('(prefers-color-scheme: dark)'); + this.mediaListener.onchange = () => this.ApplyThemeFromLocal(); + } + if (this.mediaListener.matches) { themeComputed = theme + 2; } else { themeComputed = theme + 1; } + } else { + // make sure all media listener detached + if (this.mediaListener) { + this.mediaListener.onchange = null; + this.mediaListener = null; + } } switch (themeComputed) { case Themes.sakuraLight: From 414f2df885e4a38f3b61429bf4408db29d9dd341 Mon Sep 17 00:00:00 2001 From: Anduin2017 Date: Mon, 9 Mar 2020 09:56:17 +0800 Subject: [PATCH 14/71] Rename advanced settings button. --- src/app/Views/settings.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/app/Views/settings.html b/src/app/Views/settings.html index 44f43c76..6f92a6be 100644 --- a/src/app/Views/settings.html +++ b/src/app/Views/settings.html @@ -60,7 +60,7 @@
-
Advanced Setting
+
Settings