Start at login setting implementation

This commit is contained in:
everoddandeven 2024-10-21 23:34:32 +02:00
parent d306c11086
commit b6ec37e767
6 changed files with 57 additions and 3 deletions

View file

@ -89,7 +89,7 @@ contextBridge.exposeInMainWorld('electronAPI', {
ipcRenderer.invoke('is-auto-launch-enabled'); ipcRenderer.invoke('is-auto-launch-enabled');
}, },
onIsAutoLaunchEnabled: (callback) => { onIsAutoLaunchEnabled: (callback) => {
ipcRenderer.on('on-is-auto-enabled', callback); ipcRenderer.on('on-is-auto-launch-enabled', callback);
}, },
onEnableAutoLaunchError: (callback) => { onEnableAutoLaunchError: (callback) => {
ipcRenderer.on('on-enable-auto-launch-error', callback); ipcRenderer.on('on-enable-auto-launch-error', callback);

View file

@ -303,7 +303,17 @@ export class DaemonService {
const db = await this.openDbPromise; const db = await this.openDbPromise;
const result = await db.get(this.storeName, 1); const result = await db.get(this.storeName, 1);
if (result) { if (result) {
return DaemonSettings.parse(result); const settings = DaemonSettings.parse(result);
const enabled = await this.electronService.isAutoLaunchEnabled();
settings.startAtLogin = enabled;
if (!enabled) {
settings.startAtLoginMinimized = false;
}
return settings;
} }
else else
{ {

View file

@ -46,6 +46,19 @@
<small class="text-body-secondary">Maximum number of connections allowed from the same IP address</small> <small class="text-body-secondary">Maximum number of connections allowed from the same IP address</small>
</div> </div>
<div *ngIf="!isAppImage" class="form-check form-switch col-md-6">
<label for="start-at-login" class="form-check-label">Start at login</label>
<input class="form-control form-check-input" type="checkbox" role="switch" id="start-at-login" [checked]="currentSettings.startAtLogin" [(ngModel)]="currentSettings.startAtLogin" [ngModelOptions]="{standalone: true}">
<br>
<small class="text-body-secondary">Start monero daemon at login</small>
</div>
<div *ngIf="!isAppImage" class="form-check form-switch col-md-6">
<label for="start-minimized" class="form-check-label">Start minimized</label>
<input class="form-control form-check-input" type="checkbox" role="switch" id="start-minimized" [checked]="currentSettings.startAtLoginMinimized" [(ngModel)]="currentSettings.startAtLoginMinimized" [ngModelOptions]="{standalone: true}">
<br>
<small class="text-body-secondary">Start monero daemon at login as tray icon</small>
</div>
<div class="form-check form-switch col-md-6"> <div class="form-check form-switch col-md-6">
<label for="regtest" class="form-check-label">Regtest</label> <label for="regtest" class="form-check-label">Regtest</label>

View file

@ -2,6 +2,7 @@ import { Component, NgZone } from '@angular/core';
import { NavbarLink } from '../../shared/components/navbar/navbar.model'; import { NavbarLink } from '../../shared/components/navbar/navbar.model';
import { DaemonSettings } from '../../../common/DaemonSettings'; import { DaemonSettings } from '../../../common/DaemonSettings';
import { DaemonService } from '../../core/services/daemon/daemon.service'; import { DaemonService } from '../../core/services/daemon/daemon.service';
import { ElectronService } from '../../core/services';
@Component({ @Component({
selector: 'app-settings', selector: 'app-settings',
@ -24,7 +25,7 @@ export class SettingsComponent {
public networkType: 'mainnet' | 'testnet' | 'stagenet' = 'mainnet'; public networkType: 'mainnet' | 'testnet' | 'stagenet' = 'mainnet';
constructor(private daemonService: DaemonService, private ngZone: NgZone) { constructor(private daemonService: DaemonService, private electronService: ElectronService, private ngZone: NgZone) {
this.loading = true; this.loading = true;
this.navbarLinks = [ this.navbarLinks = [
@ -55,12 +56,16 @@ export class SettingsComponent {
}); });
} }
public isAppImage: boolean = true;
private async load(): Promise<void> { private async load(): Promise<void> {
console.log("getting settings"); console.log("getting settings");
this.originalSettings = await this.daemonService.getSettings(); this.originalSettings = await this.daemonService.getSettings();
this.currentSettings = this.originalSettings.clone(); this.currentSettings = this.originalSettings.clone();
this.loading = false; this.loading = false;
this.isAppImage = await this.electronService.isAppImage();
this.networkType = this.currentSettings.mainnet ? 'mainnet' : this.currentSettings.testnet ? 'testnet' : this.currentSettings.stagenet ? 'stagenet' : 'mainnet'; this.networkType = this.currentSettings.mainnet ? 'mainnet' : this.currentSettings.testnet ? 'testnet' : this.currentSettings.stagenet ? 'stagenet' : 'mainnet';
} }
@ -134,6 +139,21 @@ export class SettingsComponent {
} }
} }
private async refreshAutoLanch(): Promise<void> {
if (await this.electronService.isAppImage()) {
return;
}
const enabled = await this.electronService.isAutoLaunchEnabled();
if (this.originalSettings.startAtLogin && !enabled) {
await this.electronService.enableAutoLaunch();
}
else if (!this.originalSettings.startAtLogin && enabled) {
await this.electronService.disableAutoLaunch();
}
}
public async OnSave(): Promise<void> { public async OnSave(): Promise<void> {
if (!this.modified) { if (!this.modified) {
return; return;
@ -150,6 +170,12 @@ export class SettingsComponent {
this.originalSettings = this.currentSettings.clone(); this.originalSettings = this.currentSettings.clone();
try {
await this.refreshAutoLanch();
} catch(error: any) {
console.error(error);
}
this.savingChangesError = ``; this.savingChangesError = ``;
this.savingChangesSuccess = true; this.savingChangesSuccess = true;
} }

View file

@ -1,6 +1,9 @@
export class DaemonSettings { export class DaemonSettings {
public monerodPath: string = ''; public monerodPath: string = '';
public startAtLogin: boolean = false;
public startAtLoginMinimized: boolean = false;
public syncOnWifi: boolean = true; public syncOnWifi: boolean = true;
public syncPeriodEnabled: boolean = false; public syncPeriodEnabled: boolean = false;
public syncPeriodFrom: string = '00:00'; public syncPeriodFrom: string = '00:00';

2
ubuntu-noble-fix.sh Executable file
View file

@ -0,0 +1,2 @@
sudo chown root ./node_modules/electron/dist/chrome-sandbox
sudo chmod 04755 ./node_modules/electron/dist/chrome-sandbox