This repository has been archived by the owner on Oct 25, 2023. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #194 from app-outlet/feature/180
Feature/180
- Loading branch information
Showing
12 changed files
with
151 additions
and
34 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
require('./application/ApplicationInterface'); | ||
require('./settings/SettingsInterface'); | ||
require('./synchronization/SynchronizationInterface'); |
21 changes: 21 additions & 0 deletions
21
core/interface/synchronization/SynchronizationInterface.js
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,21 @@ | ||
const synchronizationService = require('../../service/synchronization/SynchornizationService'); | ||
const { ipcMain } = require('electron'); | ||
const InterfaceChannel = require('../InterfaceChannel'); | ||
|
||
let isSynchronizingCache = false; | ||
|
||
synchronizationService | ||
.getSynchronizationStatus() | ||
.subscribe((isSynchronizing) => { | ||
if (isSynchronizing) { | ||
isSynchronizingCache = isSynchronizing; | ||
} | ||
ipcMain.emit( | ||
InterfaceChannel.synchronization.isRunning, | ||
isSynchronizing, | ||
); | ||
}); | ||
|
||
ipcMain?.handle(InterfaceChannel.synchronization.isRunningSync, () => { | ||
return isSynchronizingCache; | ||
}); |
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
src/app/service/synchronization/synchronization.service.spec.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 { SynchronizationService } from './synchronization.service'; | ||
|
||
describe('SynchronizationService', () => { | ||
let service: SynchronizationService; | ||
|
||
const mockCoreService = { | ||
invoke: jest.fn(), | ||
}; | ||
|
||
beforeEach(() => { | ||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment | ||
// @ts-ignore | ||
service = new SynchronizationService(mockCoreService); | ||
}); | ||
|
||
it('should be created', () => { | ||
expect(service).toBeTruthy(); | ||
}); | ||
|
||
it('should get current synchronization status', async () => { | ||
mockCoreService.invoke.mockReturnValue(Promise.resolve(true)); | ||
expect(await service.getCurrentSynchronizationStatus()).toBeTruthy(); | ||
}); | ||
}); |
14 changes: 14 additions & 0 deletions
14
src/app/service/synchronization/synchronization.service.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,14 @@ | ||
import { Injectable } from '@angular/core'; | ||
import { CoreService } from '../core/core.service'; | ||
import * as InterfaceChannel from '../../../../core/interface/InterfaceChannel'; | ||
|
||
@Injectable() | ||
export class SynchronizationService { | ||
constructor(private coreService: CoreService) {} | ||
|
||
getCurrentSynchronizationStatus(): Promise<boolean> { | ||
return this.coreService.invoke<boolean>( | ||
InterfaceChannel.synchronization.isRunningSync, | ||
); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,35 @@ | ||
import { ComponentFixture, TestBed } from '@angular/core/testing'; | ||
|
||
import { MainComponent } from './main.component'; | ||
import { MainMenuModule } from '../../components/main-menu/main-menu.module'; | ||
import { NbLayoutModule, NbSidebarModule, NbThemeModule } from '@nebular/theme'; | ||
import { NbEvaIconsModule } from '@nebular/eva-icons'; | ||
import { RouterModule } from '@angular/router'; | ||
import { APP_BASE_HREF } from '@angular/common'; | ||
import { TranslateModule } from '@ngx-translate/core'; | ||
import { ToolbarModule } from '../../components/toolbar/toolbar.module'; | ||
|
||
describe('MainComponent', () => { | ||
let component: MainComponent; | ||
let fixture: ComponentFixture<MainComponent>; | ||
|
||
beforeEach(async () => { | ||
await TestBed.configureTestingModule({ | ||
imports: [ | ||
MainMenuModule, | ||
NbLayoutModule, | ||
NbEvaIconsModule, | ||
NbSidebarModule.forRoot(), | ||
RouterModule.forRoot([]), | ||
NbThemeModule.forRoot(), | ||
TranslateModule.forRoot(), | ||
ToolbarModule, | ||
], | ||
declarations: [MainComponent], | ||
providers: [{ provide: APP_BASE_HREF, useValue: './' }], | ||
}).compileComponents(); | ||
}); | ||
const mockSynchronizationService = { | ||
getCurrentSynchronizationStatus: jest.fn(), | ||
}; | ||
|
||
beforeEach(() => { | ||
fixture = TestBed.createComponent(MainComponent); | ||
component = fixture.componentInstance; | ||
fixture.detectChanges(); | ||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment | ||
// @ts-ignore | ||
component = new MainComponent(mockSynchronizationService); | ||
}); | ||
|
||
it('should create', () => { | ||
expect(component).toBeTruthy(); | ||
}); | ||
|
||
it('should get current synchronization status', (done) => { | ||
mockSynchronizationService.getCurrentSynchronizationStatus.mockReturnValue( | ||
Promise.resolve(true), | ||
); | ||
component.ngOnInit(); | ||
setTimeout(() => { | ||
expect(component.isSynchronizationRunning).toBeTruthy(); | ||
done(); | ||
}, 0); | ||
}); | ||
|
||
it('should hide synchronization message', () => { | ||
component.closeSynchronizationMessage(); | ||
expect(component.shouldShowSynchronizationMessage).toBeFalsy(); | ||
}); | ||
}); |
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 |
---|---|---|
@@ -1,8 +1,30 @@ | ||
import { Component } from '@angular/core'; | ||
import { Component, OnInit } from '@angular/core'; | ||
import { SynchronizationService } from '../../../service/synchronization/synchronization.service'; | ||
|
||
@Component({ | ||
selector: 'app-main', | ||
templateUrl: './main.component.html', | ||
styleUrls: ['./main.component.scss'], | ||
}) | ||
export class MainComponent {} | ||
export class MainComponent implements OnInit { | ||
shouldShowSynchronizationMessage = true; | ||
isSynchronizationRunning = false; | ||
|
||
constructor(private synchronizationService: SynchronizationService) {} | ||
|
||
ngOnInit(): void { | ||
this.getCurrentSynchronizationStatus(); | ||
} | ||
|
||
private getCurrentSynchronizationStatus(): void { | ||
this.synchronizationService | ||
.getCurrentSynchronizationStatus() | ||
.then((status) => { | ||
this.isSynchronizationRunning = status; | ||
}); | ||
} | ||
|
||
closeSynchronizationMessage(): void { | ||
this.shouldShowSynchronizationMessage = false; | ||
} | ||
} |
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