-
Notifications
You must be signed in to change notification settings - Fork 106
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
experimental features for zram and reset tor (#2299)
* experimental features for zram and reset tor * zram backend --------- Co-authored-by: Aiden McClelland <me@drbonez.dev>
- Loading branch information
Showing
17 changed files
with
320 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
...ects/ui/src/app/pages/server-routes/experimental-features/experimental-features.module.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { NgModule } from '@angular/core' | ||
import { CommonModule } from '@angular/common' | ||
import { Routes, RouterModule } from '@angular/router' | ||
import { IonicModule } from '@ionic/angular' | ||
import { ExperimentalFeaturesPage } from './experimental-features.page' | ||
import { EmverPipesModule } from '@start9labs/shared' | ||
|
||
const routes: Routes = [ | ||
{ | ||
path: '', | ||
component: ExperimentalFeaturesPage, | ||
}, | ||
] | ||
|
||
@NgModule({ | ||
imports: [ | ||
CommonModule, | ||
IonicModule, | ||
RouterModule.forChild(routes), | ||
EmverPipesModule, | ||
], | ||
declarations: [ExperimentalFeaturesPage], | ||
}) | ||
export class ExperimentalFeaturesPageModule {} |
36 changes: 36 additions & 0 deletions
36
...ects/ui/src/app/pages/server-routes/experimental-features/experimental-features.page.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<ion-header> | ||
<ion-toolbar> | ||
<ion-buttons slot="start"> | ||
<ion-back-button defaultHref="system"></ion-back-button> | ||
</ion-buttons> | ||
<ion-title>Experimental Features</ion-title> | ||
</ion-toolbar> | ||
</ion-header> | ||
|
||
<ion-content class="with-widgets"> | ||
<ion-item-group *ngIf="server$ | async as server"> | ||
<ion-item button (click)="presentAlertResetTor()"> | ||
<ion-icon slot="start" name="reload"></ion-icon> | ||
<ion-label> | ||
<h2>Reset Tor</h2> | ||
<p> | ||
Reset the Tor deamon on your server may resolve Tor connectivity | ||
issues. | ||
</p> | ||
</ion-label> | ||
</ion-item> | ||
<ion-item button (click)="presentAlertZram(server.zram)"> | ||
<ion-icon | ||
slot="start" | ||
[name]="server.zram ? 'flash-off-outline' : 'flash-outline'" | ||
></ion-icon> | ||
<ion-label> | ||
<h2>{{ server.zram ? 'Disable' : 'Enable' }} zram</h2> | ||
<p> | ||
Enabling zram may improve server performance, especially on low RAM | ||
devices | ||
</p> | ||
</ion-label> | ||
</ion-item> | ||
</ion-item-group> | ||
</ion-content> |
Empty file.
156 changes: 156 additions & 0 deletions
156
...ojects/ui/src/app/pages/server-routes/experimental-features/experimental-features.page.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,156 @@ | ||
import { ChangeDetectionStrategy, Component } from '@angular/core' | ||
import { | ||
AlertController, | ||
LoadingController, | ||
ToastController, | ||
} from '@ionic/angular' | ||
import { PatchDB } from 'patch-db-client' | ||
import { ApiService } from 'src/app/services/api/embassy-api.service' | ||
import { ConfigService } from 'src/app/services/config.service' | ||
import { DataModel } from 'src/app/services/patch-db/data-model' | ||
import { ErrorToastService } from '@start9labs/shared' | ||
|
||
@Component({ | ||
selector: 'experimental-features', | ||
templateUrl: './experimental-features.page.html', | ||
styleUrls: ['./experimental-features.page.scss'], | ||
changeDetection: ChangeDetectionStrategy.OnPush, | ||
}) | ||
export class ExperimentalFeaturesPage { | ||
readonly server$ = this.patch.watch$('server-info') | ||
|
||
constructor( | ||
private readonly toastCtrl: ToastController, | ||
private readonly patch: PatchDB<DataModel>, | ||
private readonly config: ConfigService, | ||
private readonly alertCtrl: AlertController, | ||
private readonly loadingCtrl: LoadingController, | ||
private readonly api: ApiService, | ||
private readonly errToast: ErrorToastService, | ||
) {} | ||
|
||
async presentAlertResetTor() { | ||
const isTor = this.config.isTor() | ||
const shared = | ||
'Optionally wipe state to forcibly acquire new guard nodes. It is recommended to try without wiping state first.' | ||
const alert = await this.alertCtrl.create({ | ||
header: isTor ? 'Warning' : 'Confirm', | ||
message: isTor | ||
? `You are currently connected over Tor. If you reset the Tor daemon, you will loose connectivity until it comes back online.<br/><br/>${shared}` | ||
: `Reset Tor?<br/><br/>${shared}`, | ||
inputs: [ | ||
{ | ||
label: 'Wipe state', | ||
type: 'checkbox', | ||
value: 'wipe', | ||
handler: val => { | ||
console.error(val) | ||
}, | ||
}, | ||
], | ||
buttons: [ | ||
{ | ||
text: 'Cancel', | ||
role: 'cancel', | ||
}, | ||
{ | ||
text: 'Reset', | ||
handler: (value: string[]) => { | ||
console.error(value) | ||
this.resetTor(value.some(v => 'wipe')) | ||
}, | ||
cssClass: 'enter-click', | ||
}, | ||
], | ||
cssClass: isTor ? 'alert-warning-message' : '', | ||
}) | ||
await alert.present() | ||
} | ||
|
||
async presentAlertZram(enabled: boolean) { | ||
const alert = await this.alertCtrl.create({ | ||
header: enabled ? 'Confirm' : 'Warning', | ||
message: enabled | ||
? 'Are you sure you want to disable zram?' | ||
: 'zram on StartOS is experimental. It may increase performance of you server, especially if it is a low RAM device.', | ||
buttons: [ | ||
{ | ||
text: 'Cancel', | ||
role: 'cancel', | ||
}, | ||
{ | ||
text: enabled ? 'Disable' : 'Enable', | ||
handler: () => { | ||
this.toggleZram(enabled) | ||
}, | ||
cssClass: 'enter-click', | ||
}, | ||
], | ||
cssClass: enabled ? '' : 'alert-warning-message', | ||
}) | ||
await alert.present() | ||
} | ||
|
||
private async resetTor(wipeState: boolean) { | ||
const loader = await this.loadingCtrl.create({ | ||
message: 'Resetting Tor...', | ||
}) | ||
await loader.present() | ||
|
||
try { | ||
await this.api.resetTor({ | ||
'wipe-state': wipeState, | ||
reason: 'User triggered', | ||
}) | ||
const toast = await this.toastCtrl.create({ | ||
header: 'Tor reset in progress', | ||
position: 'bottom', | ||
duration: 4000, | ||
buttons: [ | ||
{ | ||
side: 'start', | ||
icon: 'close', | ||
handler: () => { | ||
return true | ||
}, | ||
}, | ||
], | ||
}) | ||
await toast.present() | ||
} catch (e: any) { | ||
this.errToast.present(e) | ||
} finally { | ||
loader.dismiss() | ||
} | ||
} | ||
|
||
private async toggleZram(enabled: boolean) { | ||
const loader = await this.loadingCtrl.create({ | ||
message: enabled ? 'Disabling zram...' : 'Enabling zram', | ||
}) | ||
await loader.present() | ||
|
||
try { | ||
await this.api.toggleZram({ enable: !enabled }) | ||
const toast = await this.toastCtrl.create({ | ||
header: `Zram ${enabled ? 'disabled' : 'enabled'}`, | ||
position: 'bottom', | ||
duration: 4000, | ||
buttons: [ | ||
{ | ||
side: 'start', | ||
icon: 'close', | ||
handler: () => { | ||
return true | ||
}, | ||
}, | ||
], | ||
}) | ||
await toast.present() | ||
} catch (e: any) { | ||
this.errToast.present(e) | ||
} finally { | ||
loader.dismiss() | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.