-
Notifications
You must be signed in to change notification settings - Fork 110
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Adds working drag and drop service * Fixes Typescript error about iterables * Adds basic drop files support * Some refactoring * Adds tests
- Loading branch information
Showing
11 changed files
with
132 additions
and
29 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
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
7 changes: 7 additions & 0 deletions
7
src/app/services/event-listener/base-event-listener.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,7 @@ | ||
import { Observable } from 'rxjs'; | ||
|
||
export abstract class BaseEventListenerService { | ||
public abstract argumentsReceived$: Observable<string[]>; | ||
public abstract filesDropped$: Observable<string[]>; | ||
public abstract listenToEvents(): void; | ||
} |
20 changes: 20 additions & 0 deletions
20
src/app/services/event-listener/event-listener.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,20 @@ | ||
import { BaseEventListenerService } from './base-event-listener.service'; | ||
import { EventListenerService } from './event-listener.service'; | ||
|
||
describe('EventListenerService', () => { | ||
function createSut(): BaseEventListenerService { | ||
return new EventListenerService(); | ||
} | ||
|
||
describe('constructor', () => { | ||
it('should create', () => { | ||
// Arrange | ||
|
||
// Act | ||
const sut: BaseEventListenerService = createSut(); | ||
|
||
// Assert | ||
expect(sut).toBeDefined(); | ||
}); | ||
}); | ||
}); |
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,39 @@ | ||
import { ipcRenderer } from 'electron'; | ||
import { Observable, Subject } from 'rxjs'; | ||
import { BaseEventListenerService } from './base-event-listener.service'; | ||
|
||
export class EventListenerService implements BaseEventListenerService { | ||
private argumentsReceived: Subject<string[]> = new Subject(); | ||
private filesDropped: Subject<string[]> = new Subject(); | ||
|
||
public argumentsReceived$: Observable<string[]> = this.argumentsReceived.asObservable(); | ||
public filesDropped$: Observable<string[]> = this.filesDropped.asObservable(); | ||
|
||
public listenToEvents(): void { | ||
ipcRenderer.on('arguments-received', (event, argv: string[] | undefined) => { | ||
this.argumentsReceived.next(argv); | ||
}); | ||
|
||
document.addEventListener('dragover', (e) => { | ||
e.preventDefault(); | ||
e.stopPropagation(); | ||
}); | ||
|
||
document.addEventListener('drop', (event) => { | ||
event.preventDefault(); | ||
event.stopPropagation(); | ||
|
||
if (event.dataTransfer == undefined) { | ||
return; | ||
} | ||
|
||
const filePaths: string[] = []; | ||
|
||
for (const f of event.dataTransfer.files) { | ||
filePaths.push(f.path); | ||
} | ||
|
||
this.filesDropped.next(filePaths); | ||
}); | ||
} | ||
} |
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