add initial macOS support #40

This commit is contained in:
undergroundwires
2021-01-13 16:31:20 +01:00
parent 2428de23ee
commit 8a8b7319d5
99 changed files with 2663 additions and 1135 deletions

View File

@@ -1,4 +1,6 @@
import { IEventSubscription } from './ISubscription';
export interface ISignal<T> {
on(handler: (data: T) => void): void;
off(handler: (data: T) => void): void;
on(handler: EventHandler<T>): IEventSubscription;
}
export type EventHandler<T> = (data: T) => void;

View File

@@ -0,0 +1,3 @@
export interface IEventSubscription {
unsubscribe(): void;
}

View File

@@ -1,18 +1,28 @@
import { ISignal } from './ISignal';
export { ISignal };
import { EventHandler, ISignal } from './ISignal';
import { IEventSubscription } from './ISubscription';
export class Signal<T> implements ISignal<T> {
private handlers: Array<(data: T) => void> = [];
private handlers = new Map<number, EventHandler<T>>();
public on(handler: (data: T) => void): void {
this.handlers.push(handler);
}
public off(handler: (data: T) => void): void {
this.handlers = this.handlers.filter((h) => h !== handler);
public on(handler: EventHandler<T>): IEventSubscription {
const id = this.getUniqueEventHandlerId();
this.handlers.set(id, handler);
return {
unsubscribe: () => this.handlers.delete(id),
};
}
public notify(data: T) {
this.handlers.slice(0).forEach((h) => h(data));
for (const handler of Array.from(this.handlers.values())) {
handler(data);
}
}
private getUniqueEventHandlerId(): number {
const id = Math.random();
if (this.handlers.has(id)) {
return this.getUniqueEventHandlerId();
}
return id;
}
}

View File

@@ -2,6 +2,7 @@ import fileSaver from 'file-saver';
export enum FileType {
BatchFile,
ShellScript,
}
export class SaveFileDialog {
public static saveFile(text: string, fileName: string, type: FileType): void {
@@ -11,7 +12,8 @@ export class SaveFileDialog {
private static readonly mimeTypes = new Map<FileType, string>([
// Some browsers (including firefox + IE) require right mime type
// otherwise they ignore extension and save the file as text.
[ FileType.BatchFile, 'application/bat' ], // https://en.wikipedia.org/wiki/Batch_file
[ FileType.BatchFile, 'application/bat' ], // https://en.wikipedia.org/wiki/Batch_file
[ FileType.ShellScript, 'text/x-shellscript' ], // https://de.wikipedia.org/wiki/Shellskript#MIME-Typ
]);
private static saveBlob(file: BlobPart, fileType: string, fileName: string): void {