mirror of
https://github.com/bitwarden/directory-connector
synced 2025-12-15 07:43:27 +00:00
reduce menu. added gsuite file picker
This commit is contained in:
@@ -65,20 +65,9 @@ export class AppComponent implements OnInit {
|
|||||||
private componentFactoryResolver: ComponentFactoryResolver, private messagingService: MessagingService) { }
|
private componentFactoryResolver: ComponentFactoryResolver, private messagingService: MessagingService) { }
|
||||||
|
|
||||||
ngOnInit() {
|
ngOnInit() {
|
||||||
this.ngZone.runOutsideAngular(() => {
|
|
||||||
window.setTimeout(async () => {
|
|
||||||
await this.updateAppMenu();
|
|
||||||
}, 1000);
|
|
||||||
});
|
|
||||||
|
|
||||||
this.broadcasterService.subscribe(BroadcasterSubscriptionId, async (message: any) => {
|
this.broadcasterService.subscribe(BroadcasterSubscriptionId, async (message: any) => {
|
||||||
this.ngZone.run(async () => {
|
this.ngZone.run(async () => {
|
||||||
switch (message.command) {
|
switch (message.command) {
|
||||||
case 'loggedIn':
|
|
||||||
case 'unlocked':
|
|
||||||
case 'loggedOut':
|
|
||||||
this.updateAppMenu();
|
|
||||||
break;
|
|
||||||
case 'logout':
|
case 'logout':
|
||||||
this.logOut(!!message.expired);
|
this.logOut(!!message.expired);
|
||||||
break;
|
break;
|
||||||
@@ -92,12 +81,6 @@ export class AppComponent implements OnInit {
|
|||||||
this.broadcasterService.unsubscribe(BroadcasterSubscriptionId);
|
this.broadcasterService.unsubscribe(BroadcasterSubscriptionId);
|
||||||
}
|
}
|
||||||
|
|
||||||
private async updateAppMenu() {
|
|
||||||
this.messagingService.send('updateAppMenu', {
|
|
||||||
isAuthenticated: await this.userService.isAuthenticated(),
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
private async logOut(expired: boolean) {
|
private async logOut(expired: boolean) {
|
||||||
const userId = await this.userService.getUserId();
|
const userId = await this.userService.getUserId();
|
||||||
|
|
||||||
|
|||||||
@@ -87,10 +87,15 @@
|
|||||||
<small class="text-muted form-text">{{'ex' | i18n}} 39204722352</small>
|
<small class="text-muted form-text">{{'ex' | i18n}} 39204722352</small>
|
||||||
</div>
|
</div>
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
|
<label for="keyFile">{{'jsonKeyFile' | i18n}}</label>
|
||||||
|
<input type="file" class="form-control-file" id="keyFile" accept=".json" (change)="parseKeyFile()">
|
||||||
|
<small class="text-muted form-text">{{'ex' | i18n}} My Project-jksd3jd223.json</small>
|
||||||
|
</div>
|
||||||
|
<div class="form-group" [hidden]="!gsuite.clientEmail">
|
||||||
<label for="clientEmail">{{'clientEmail' | i18n}}</label>
|
<label for="clientEmail">{{'clientEmail' | i18n}}</label>
|
||||||
<input type="text" class="form-control" id="clientEmail" name="ClientEmail" [(ngModel)]="gsuite.clientEmail">
|
<input type="text" class="form-control" id="clientEmail" name="ClientEmail" [(ngModel)]="gsuite.clientEmail">
|
||||||
</div>
|
</div>
|
||||||
<div class="form-group">
|
<div class="form-group" [hidden]="!gsuite.privateKey">
|
||||||
<label for="privateKey">{{'privateKey' | i18n}}</label>
|
<label for="privateKey">{{'privateKey' | i18n}}</label>
|
||||||
<textarea class="form-control text-monospace" id="privateKey" name="PrivateKey" [(ngModel)]="gsuite.privateKey">
|
<textarea class="form-control text-monospace" id="privateKey" name="PrivateKey" [(ngModel)]="gsuite.privateKey">
|
||||||
</textarea>
|
</textarea>
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
import {
|
import {
|
||||||
|
ChangeDetectorRef,
|
||||||
Component,
|
Component,
|
||||||
|
NgZone,
|
||||||
OnDestroy,
|
OnDestroy,
|
||||||
OnInit,
|
OnInit,
|
||||||
} from '@angular/core';
|
} from '@angular/core';
|
||||||
@@ -28,7 +30,8 @@ export class SettingsComponent implements OnInit, OnDestroy {
|
|||||||
sync = new SyncConfiguration();
|
sync = new SyncConfiguration();
|
||||||
directoryOptions: any[];
|
directoryOptions: any[];
|
||||||
|
|
||||||
constructor(private i18nService: I18nService, private configurationService: ConfigurationService) {
|
constructor(private i18nService: I18nService, private configurationService: ConfigurationService,
|
||||||
|
private changeDetectorRef: ChangeDetectorRef, private ngZone: NgZone) {
|
||||||
this.directoryOptions = [
|
this.directoryOptions = [
|
||||||
{ name: i18nService.t('select'), value: null },
|
{ name: i18nService.t('select'), value: null },
|
||||||
{ name: 'Active Directory / LDAP', value: DirectoryType.Ldap },
|
{ name: 'Active Directory / LDAP', value: DirectoryType.Ldap },
|
||||||
@@ -72,4 +75,32 @@ export class SettingsComponent implements OnInit, OnDestroy {
|
|||||||
await this.configurationService.saveDirectory(DirectoryType.AzureActiveDirectory, this.azure);
|
await this.configurationService.saveDirectory(DirectoryType.AzureActiveDirectory, this.azure);
|
||||||
await this.configurationService.saveSync(this.sync);
|
await this.configurationService.saveSync(this.sync);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async parseKeyFile() {
|
||||||
|
const filePicker = (document.getElementById('keyFile') as HTMLInputElement);
|
||||||
|
if (filePicker.files == null || filePicker.files.length < 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const reader = new FileReader();
|
||||||
|
reader.readAsText(filePicker.files[0], 'utf-8');
|
||||||
|
reader.onload = (evt) => {
|
||||||
|
this.ngZone.run(async () => {
|
||||||
|
try {
|
||||||
|
const result = JSON.parse((evt.target as FileReader).result);
|
||||||
|
if (result.client_email != null && result.private_key != null) {
|
||||||
|
this.gsuite.clientEmail = result.client_email;
|
||||||
|
this.gsuite.privateKey = result.private_key;
|
||||||
|
}
|
||||||
|
} catch { }
|
||||||
|
this.changeDetectorRef.detectChanges();
|
||||||
|
});
|
||||||
|
|
||||||
|
// reset file input
|
||||||
|
// ref: https://stackoverflow.com/a/20552042
|
||||||
|
filePicker.type = '';
|
||||||
|
filePicker.type = 'file';
|
||||||
|
filePicker.value = '';
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -231,8 +231,8 @@
|
|||||||
"view": {
|
"view": {
|
||||||
"message": "View"
|
"message": "View"
|
||||||
},
|
},
|
||||||
"file": {
|
"jsonKeyFile": {
|
||||||
"message": "File"
|
"message": "JSON Key File"
|
||||||
},
|
},
|
||||||
"edit": {
|
"edit": {
|
||||||
"message": "Edit"
|
"message": "Edit"
|
||||||
|
|||||||
@@ -10,7 +10,6 @@ import { BaseMenu } from 'jslib/electron/baseMenu';
|
|||||||
|
|
||||||
export class MenuMain extends BaseMenu {
|
export class MenuMain extends BaseMenu {
|
||||||
menu: Menu;
|
menu: Menu;
|
||||||
logOut: MenuItem;
|
|
||||||
|
|
||||||
constructor(main: Main) {
|
constructor(main: Main) {
|
||||||
super(main.i18nService, main.windowMain, main.i18nService.t('bitwardenDirectoryConnector'),
|
super(main.i18nService, main.windowMain, main.i18nService.t('bitwardenDirectoryConnector'),
|
||||||
@@ -21,21 +20,10 @@ export class MenuMain extends BaseMenu {
|
|||||||
this.initProperties();
|
this.initProperties();
|
||||||
this.initContextMenu();
|
this.initContextMenu();
|
||||||
this.initApplicationMenu();
|
this.initApplicationMenu();
|
||||||
|
|
||||||
this.logOut = this.menu.getMenuItemById('logOut');
|
|
||||||
this.updateApplicationMenuState(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
updateApplicationMenuState(isAuthenticated: boolean) {
|
|
||||||
this.logOut.enabled = isAuthenticated;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private initApplicationMenu() {
|
private initApplicationMenu() {
|
||||||
const template: MenuItemConstructorOptions[] = [
|
const template: MenuItemConstructorOptions[] = [
|
||||||
{
|
|
||||||
label: this.i18nService.t('file'),
|
|
||||||
submenu: [this.logOutMenuItemOptions],
|
|
||||||
},
|
|
||||||
this.editMenuItemOptions,
|
this.editMenuItemOptions,
|
||||||
{
|
{
|
||||||
label: this.i18nService.t('view'),
|
label: this.i18nService.t('view'),
|
||||||
@@ -44,54 +32,21 @@ export class MenuMain extends BaseMenu {
|
|||||||
this.windowMenuItemOptions,
|
this.windowMenuItemOptions,
|
||||||
];
|
];
|
||||||
|
|
||||||
const firstMenuOptions: MenuItemConstructorOptions[] = [
|
|
||||||
{ type: 'separator' },
|
|
||||||
{
|
|
||||||
label: this.i18nService.t('settings'),
|
|
||||||
id: 'settings',
|
|
||||||
click: () => { /* Something */ },
|
|
||||||
},
|
|
||||||
];
|
|
||||||
|
|
||||||
const updateMenuItem = {
|
|
||||||
label: this.i18nService.t('checkForUpdates'),
|
|
||||||
click: () => { /* Something */ },
|
|
||||||
id: 'checkForUpdates',
|
|
||||||
};
|
|
||||||
|
|
||||||
if (process.platform === 'darwin') {
|
if (process.platform === 'darwin') {
|
||||||
const firstMenuPart: MenuItemConstructorOptions[] = [
|
const firstMenuPart: MenuItemConstructorOptions[] = [
|
||||||
{
|
{
|
||||||
label: this.i18nService.t('aboutBitwarden'),
|
label: this.i18nService.t('aboutBitwarden'),
|
||||||
role: 'about',
|
role: 'about',
|
||||||
},
|
},
|
||||||
updateMenuItem,
|
|
||||||
];
|
];
|
||||||
|
|
||||||
template.unshift({
|
template.unshift({
|
||||||
label: this.appName,
|
label: this.appName,
|
||||||
submenu: firstMenuPart.concat(firstMenuOptions, [
|
submenu: firstMenuPart.concat(this.macAppMenuItemOptions),
|
||||||
{ type: 'separator' },
|
|
||||||
], this.macAppMenuItemOptions),
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// Window menu
|
// Window menu
|
||||||
template[template.length - 1].submenu = this.macWindowSubmenuOptions;
|
template[template.length - 1].submenu = this.macWindowSubmenuOptions;
|
||||||
} else {
|
|
||||||
// File menu
|
|
||||||
template[0].submenu = (template[0].submenu as MenuItemConstructorOptions[]).concat(
|
|
||||||
firstMenuOptions);
|
|
||||||
|
|
||||||
// About menu
|
|
||||||
const aboutMenuAdditions: MenuItemConstructorOptions[] = [
|
|
||||||
{ type: 'separator' },
|
|
||||||
updateMenuItem,
|
|
||||||
];
|
|
||||||
|
|
||||||
aboutMenuAdditions.push(this.aboutMenuItemOptions);
|
|
||||||
|
|
||||||
template[template.length - 1].submenu =
|
|
||||||
(template[template.length - 1].submenu as MenuItemConstructorOptions[]).concat(aboutMenuAdditions);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
this.menu = Menu.buildFromTemplate(template);
|
this.menu = Menu.buildFromTemplate(template);
|
||||||
|
|||||||
@@ -24,9 +24,6 @@ export class MessagingMain {
|
|||||||
case 'scheduleNextSync':
|
case 'scheduleNextSync':
|
||||||
this.scheduleNextSync();
|
this.scheduleNextSync();
|
||||||
break;
|
break;
|
||||||
case 'updateAppMenu':
|
|
||||||
this.menuMain.updateApplicationMenuState(message.isAuthenticated);
|
|
||||||
break;
|
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -43,11 +43,7 @@ h4 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
app-root > #loading {
|
app-root > #loading {
|
||||||
display: flex;
|
|
||||||
text-align: center;
|
text-align: center;
|
||||||
justify-content: center;
|
margin-top: 20px;
|
||||||
align-items: center;
|
|
||||||
height: 100%;
|
|
||||||
width: 100%;
|
|
||||||
color: $text-muted;
|
color: $text-muted;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user