mirror of
https://github.com/quine-global/hyper.git
synced 2026-01-12 20:18:41 -09:00
Fix ts errors in lib/utils
This commit is contained in:
parent
187897a1f0
commit
d2a318d48b
7 changed files with 25 additions and 18 deletions
|
|
@ -1,12 +1,12 @@
|
||||||
import {ipcRenderer, remote} from 'electron';
|
import {ipcRenderer, remote} from 'electron';
|
||||||
|
|
||||||
const plugins = remote.require('./plugins');
|
const plugins = remote.require('./plugins') as typeof import('../../app/plugins');
|
||||||
|
|
||||||
export function getConfig() {
|
export function getConfig() {
|
||||||
return plugins.getDecoratedConfig();
|
return plugins.getDecoratedConfig();
|
||||||
}
|
}
|
||||||
|
|
||||||
export function subscribe(fn) {
|
export function subscribe(fn: (event: Electron.IpcRendererEvent, ...args: any[]) => void) {
|
||||||
ipcRenderer.on('config change', fn);
|
ipcRenderer.on('config change', fn);
|
||||||
ipcRenderer.on('plugins change', fn);
|
ipcRenderer.on('plugins change', fn);
|
||||||
return () => {
|
return () => {
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@
|
||||||
* as the result of an action being triggered.
|
* as the result of an action being triggered.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
export default () => next => action => {
|
export default () => (next: (arg0: any) => any) => (action: {effect: () => void}) => {
|
||||||
const ret = next(action);
|
const ret = next(action);
|
||||||
if (action.effect) {
|
if (action.effect) {
|
||||||
action.effect();
|
action.effect();
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
/* eslint no-new:0 */
|
/* eslint no-new:0 */
|
||||||
export default function notify(title, body, details = {}) {
|
export default function notify(title: string, body: string, details: Record<string, any> = {}) {
|
||||||
//eslint-disable-next-line no-console
|
//eslint-disable-next-line no-console
|
||||||
console.log(`[Notification] ${title}: ${body}`);
|
console.log(`[Notification] ${title}: ${body}`);
|
||||||
if (details.error) {
|
if (details.error) {
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
const valsCache = new WeakMap();
|
const valsCache = new WeakMap();
|
||||||
|
|
||||||
export function values(imm) {
|
export function values(imm: Record<string, any>) {
|
||||||
if (!valsCache.has(imm)) {
|
if (!valsCache.has(imm)) {
|
||||||
valsCache.set(imm, Object.values(imm));
|
valsCache.set(imm, Object.values(imm));
|
||||||
}
|
}
|
||||||
|
|
@ -8,7 +8,7 @@ export function values(imm) {
|
||||||
}
|
}
|
||||||
|
|
||||||
const keysCache = new WeakMap();
|
const keysCache = new WeakMap();
|
||||||
export function keys(imm) {
|
export function keys(imm: Record<string, any>) {
|
||||||
if (!keysCache.has(imm)) {
|
if (!keysCache.has(imm)) {
|
||||||
keysCache.set(imm, Object.keys(imm));
|
keysCache.set(imm, Object.keys(imm));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,12 @@
|
||||||
import {clipboard} from 'electron';
|
import {clipboard} from 'electron';
|
||||||
import plist from 'plist';
|
import plist from 'plist';
|
||||||
|
|
||||||
const getPath = platform => {
|
const getPath = (platform: string) => {
|
||||||
switch (platform) {
|
switch (platform) {
|
||||||
case 'darwin': {
|
case 'darwin': {
|
||||||
if (clipboard.has('NSFilenamesPboardType')) {
|
if (clipboard.has('NSFilenamesPboardType')) {
|
||||||
// Parse plist file containing the path list of copied files
|
// Parse plist file containing the path list of copied files
|
||||||
const list = plist.parse(clipboard.read('NSFilenamesPboardType'));
|
const list = plist.parse(clipboard.read('NSFilenamesPboardType')) as plist.PlistArray;
|
||||||
return "'" + list.join("' '") + "'";
|
return "'" + list.join("' '") + "'";
|
||||||
} else {
|
} else {
|
||||||
return null;
|
return null;
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,11 @@
|
||||||
|
import {EventEmitter} from 'events';
|
||||||
|
import {IpcRenderer, IpcRendererEvent} from 'electron';
|
||||||
|
import electron from 'electron';
|
||||||
export default class Client {
|
export default class Client {
|
||||||
|
emitter: EventEmitter;
|
||||||
|
ipc: IpcRenderer;
|
||||||
|
id!: string;
|
||||||
constructor() {
|
constructor() {
|
||||||
const electron = window.require('electron');
|
|
||||||
const EventEmitter = window.require('events');
|
|
||||||
this.emitter = new EventEmitter();
|
this.emitter = new EventEmitter();
|
||||||
this.ipc = electron.ipcRenderer;
|
this.ipc = electron.ipcRenderer;
|
||||||
this.ipcListener = this.ipcListener.bind(this);
|
this.ipcListener = this.ipcListener.bind(this);
|
||||||
|
|
@ -12,7 +16,7 @@ export default class Client {
|
||||||
this.emitter.emit('ready');
|
this.emitter.emit('ready');
|
||||||
}, 0);
|
}, 0);
|
||||||
} else {
|
} else {
|
||||||
this.ipc.on('init', (ev, uid) => {
|
this.ipc.on('init', (ev: IpcRendererEvent, uid: string) => {
|
||||||
// we cache so that if the object
|
// we cache so that if the object
|
||||||
// gets re-instantiated we don't
|
// gets re-instantiated we don't
|
||||||
// wait for a `init` event
|
// wait for a `init` event
|
||||||
|
|
@ -24,26 +28,26 @@ export default class Client {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ipcListener(event, {ch, data}) {
|
ipcListener(event: any, {ch, data}: {ch: string; data: any}) {
|
||||||
this.emitter.emit(ch, data);
|
this.emitter.emit(ch, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
on(ev, fn) {
|
on(ev: string, fn: (...args: any[]) => void) {
|
||||||
this.emitter.on(ev, fn);
|
this.emitter.on(ev, fn);
|
||||||
}
|
}
|
||||||
|
|
||||||
once(ev, fn) {
|
once(ev: string, fn: (...args: any[]) => void) {
|
||||||
this.emitter.once(ev, fn);
|
this.emitter.once(ev, fn);
|
||||||
}
|
}
|
||||||
|
|
||||||
emit(ev, data) {
|
emit(ev: string, data: any) {
|
||||||
if (!this.id) {
|
if (!this.id) {
|
||||||
throw new Error('Not ready');
|
throw new Error('Not ready');
|
||||||
}
|
}
|
||||||
this.ipc.send(this.id, {ev, data});
|
this.ipc.send(this.id, {ev, data});
|
||||||
}
|
}
|
||||||
|
|
||||||
removeListener(ev, fn) {
|
removeListener(ev: string, fn: (...args: any[]) => void) {
|
||||||
this.emitter.removeListener(ev, fn);
|
this.emitter.removeListener(ev, fn);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -53,6 +57,6 @@ export default class Client {
|
||||||
|
|
||||||
destroy() {
|
destroy() {
|
||||||
this.removeAllListeners();
|
this.removeAllListeners();
|
||||||
this.ipc.removeAllListeners();
|
this.ipc.removeAllListeners(this.id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,7 @@
|
||||||
export default function findBySession(termGroupState, sessionUid) {
|
import {ITermState} from '../hyper';
|
||||||
|
import {Immutable} from 'seamless-immutable';
|
||||||
|
|
||||||
|
export default function findBySession(termGroupState: Immutable<ITermState>, sessionUid: string) {
|
||||||
const {termGroups} = termGroupState;
|
const {termGroups} = termGroupState;
|
||||||
return Object.keys(termGroups)
|
return Object.keys(termGroups)
|
||||||
.map(uid => termGroups[uid])
|
.map(uid => termGroups[uid])
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue