Skip to content

Commit 1ae6381

Browse files
committed
chore: refactor types
1 parent af66c41 commit 1ae6381

File tree

13 files changed

+108
-97
lines changed

13 files changed

+108
-97
lines changed

extension/common/config.ts

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,13 @@
11
import $ from 'jquery';
2-
import { JSONSchema4Type } from 'json-schema';
32
import _ from 'underscore';
43
import { browser } from 'webextension-polyfill-ts';
54

65
import defaultGeneral from 'conf/general';
76
import Steward from 'main/Steward';
87
import { getPlugins } from 'plugins';
9-
import { Plugin } from 'plugins/type';
108

11-
import util, { SimpleCommand } from './util';
12-
13-
export type PartialPlugin = Pick<
14-
Plugin,
15-
'name' | 'version' | 'canDisabled' | 'icon' | 'disabled' | 'optionsSchema' | 'defaultOptions'
16-
> & {
17-
commands: SimpleCommand[];
18-
options: JSONSchema4Type
19-
};
9+
import util from './util';
10+
import { AppConfig, PartialPlugin, PluginsData, SimpleCommand } from './type';
2011

2112
const manifest = chrome.runtime.getManifest();
2213
const version = manifest.version;
@@ -59,10 +50,6 @@ function getPluginData() {
5950
return plugins;
6051
}
6152

62-
export interface PluginsData {
63-
[prop: string]: PartialPlugin;
64-
}
65-
6653
function mergePluginData(plugin: PartialPlugin, cachePlugins: PluginsData) {
6754
const name = plugin.name;
6855
let cachePlugin = cachePlugins[name];
@@ -103,12 +90,6 @@ function mergePluginData(plugin: PartialPlugin, cachePlugins: PluginsData) {
10390
}
10491
}
10592

106-
export interface AppConfig {
107-
general: typeof defaultGeneral;
108-
plugins: PluginsData;
109-
version: string;
110-
}
111-
11293
function getDefaultConfig() {
11394
return {
11495
general: defaultGeneral,

extension/common/type.ts

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@ import { AppState } from 'main/type';
1010
import { Command, Plugin } from 'plugins/type';
1111
import storage from 'utils/storage';
1212

13-
import { AppConfig } from './config';
13+
import defaultGeneral from 'conf/general';
1414
import util from './util';
15+
import { JSONSchema4Type } from 'json-schema';
1516

1617
declare global {
1718
var EXT_TYPE: string;
@@ -24,6 +25,7 @@ declare global {
2425
slogs: string[];
2526
matchedSite: Website | null;
2627
parentHost?: string;
28+
componentHelper: any;
2729
}
2830

2931
interface RegExp {
@@ -98,4 +100,24 @@ export interface WallpaperSource {
98100
api: (...args: any[]) => any;
99101
handle: (result: any) => any;
100102
weight: number;
101-
}
103+
}
104+
105+
export type PartialPlugin = Pick<
106+
Plugin,
107+
'name' | 'version' | 'canDisabled' | 'icon' | 'disabled' | 'optionsSchema' | 'defaultOptions'
108+
> & {
109+
commands: SimpleCommand[];
110+
options: JSONSchema4Type
111+
};
112+
113+
export type SimpleCommand = Pick<Command, 'key' | 'orkey'>;
114+
115+
export interface PluginsData {
116+
[prop: string]: PartialPlugin;
117+
}
118+
119+
export interface AppConfig {
120+
general: typeof defaultGeneral;
121+
plugins: PluginsData;
122+
version: string;
123+
}

extension/common/util.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { getURL } from 'helper/extension.helper';
88
import { t } from 'helper/i18n.helper';
99
import stewardCache from 'main/cache';
1010
import { Command, KeyStatus, ResultItem, Type } from 'plugins/type';
11+
import { SimpleCommand } from './type';
1112

1213
function getPinyin(name: string): string {
1314
return pinyin(name, {
@@ -40,8 +41,6 @@ function guid(): string {
4041
return `${s4()}${s4()}-${s4()}-${s4()}-${s4()}-${s4()}${s4()}${s4()}`;
4142
}
4243

43-
export type SimpleCommand = Pick<Command, 'key' | 'orkey'>;
44-
4544
const simpleCommand = (command: Command) => {
4645
return {
4746
key: command.key,

extension/helper/action.helper.ts

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,8 @@
1+
import { Action } from 'plugins/type';
12
import { browser } from 'webextension-polyfill-ts';
23

34
import { PageCommand } from '../enum';
45

5-
export interface Action {
6-
title: string;
7-
actionType: string;
8-
desc?: string;
9-
extend?: {
10-
template?: string;
11-
protected?: boolean;
12-
};
13-
enable: boolean;
14-
}
15-
166
const defaultActions: Action[] = [
177
{
188
title: 'Copy title as a markdown link',

extension/helper/alias.helper.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { browser } from 'webextension-polyfill-ts';
22

33
import util from 'common/util';
4-
import { ResultItem } from 'plugins/type';
4+
import { ResultItem, TextAliasType } from 'plugins/type';
55

66
import { getURL } from './extension.helper';
77

@@ -45,7 +45,7 @@ function parseLine(line) {
4545

4646
const STORAGE_KEY = 'text_alias';
4747

48-
export const TextAlias = {
48+
export const TextAlias: TextAliasType = {
4949
items: null,
5050

5151
resolveItems(text) {
@@ -87,8 +87,6 @@ export const TextAlias = {
8787
},
8888
};
8989

90-
export type TextAliasType = typeof TextAlias;
91-
9290
export function getTextAlias() {
9391
return browser.storage.sync.get(STORAGE_KEY).then(resp => {
9492
return resp[STORAGE_KEY] || '';

extension/helper/component.helper.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -213,12 +213,6 @@ export const componentHelper = {
213213
},
214214
};
215215

216-
declare global {
217-
interface Window {
218-
componentHelper: any;
219-
}
220-
}
221-
222216
window.componentHelper = componentHelper;
223217

224218
export function registerComponents(Vue, components = []) {

extension/helper/plugin.helper.ts

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { CustomPlugin as CustomPluginModel, CustomPluginList } from 'collection/
88
import { StewardApp } from 'common/type';
99
import constant from 'constant/index';
1010
import Steward from 'main/Steward';
11-
import { Plugin as PluginModel } from 'plugins/type';
11+
import { Plugin as PluginModel, PluginClass } from 'plugins/type';
1212

1313
import { replaceURL } from '../pages/content/pageService';
1414
import { getURL } from './extension.helper';
@@ -116,20 +116,9 @@ PluginHelper.prototype = {
116116

117117
export default PluginHelper;
118118

119-
class Plugin {
120-
errors = [];
121-
commands = [];
122-
_id: string;
123-
valid: boolean;
124-
uid?: string;
125-
version?: string;
126-
name: string;
127-
category?: string;
128-
icon?: string;
129-
title?: string;
130-
source?: string;
131-
author?: string;
119+
class Plugin extends PluginClass {
132120
constructor(options = {}) {
121+
super()
133122
this.errors = [];
134123
this.commands = [];
135124
this.init(options);

extension/helper/wallpaper.helper.ts

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,10 @@ import util from 'common/util';
55
import STORAGE from 'constant/storage';
66

77
import { t } from './i18n.helper';
8-
9-
export type ACTION_TYPE = 'save' | 'remove'
10-
export interface ACTION {
11-
action: ACTION_TYPE;
12-
msg: string
13-
}
8+
import { WALLPAPER_ACTION, WALLPAPER_ACTION_TYPE } from 'main/type';
149

1510
export const WALLPAPER_ACTIONS: {
16-
[props: string]: ACTION
11+
[props: string]: WALLPAPER_ACTION
1712
} = {
1813
save: {
1914
action: 'save',
@@ -26,7 +21,7 @@ export const WALLPAPER_ACTIONS: {
2621
},
2722
};
2823

29-
export function saveWallpaperLink(url: string, action: ACTION_TYPE = 'save') {
24+
export function saveWallpaperLink(url: string, action: WALLPAPER_ACTION_TYPE = 'save') {
3025
return util.isStorageSafe(STORAGE.WALLPAPERS).then(() => {
3126
return browser.storage.sync
3227
.get(STORAGE.WALLPAPERS)

extension/helper/websites.helper.ts

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { addNetworkRecord, generateSocialUrls } from '../lib/social-share-urls';
1212
import { getGlobalActions } from './action.helper';
1313
import { getURL } from './extension.helper';
1414
import * as ResultHelper from './result.helper';
15+
import { WebsiteClass } from 'plugins/type';
1516

1617
const websiteList = new WebsiteList();
1718

@@ -113,28 +114,9 @@ function handlePaths(paths, vars) {
113114
});
114115
}
115116

116-
export class Website {
117-
name: string;
118-
type: string;
119-
icon: string;
120-
host: string;
121-
parentWindow: any;
122-
navs: string;
123-
outlineScope: string;
124-
paths: any[];
125-
customPaths: any[];
126-
anchors: any[];
127-
anchorsConfig: any[];
128-
isDefault: boolean;
129-
meta: any[];
130-
urls: any[];
131-
outline: any[];
132-
iframes: any[];
133-
pageMeta: any;
134-
shareUrls: any[];
135-
config: any;
136-
actions: any[];
117+
export class Website extends WebsiteClass {
137118
constructor(options, parentWindow, pageMeta, generalConfig) {
119+
super();
138120
this.name = options.name;
139121
this.type = 'search';
140122
this.icon = options.icon;

extension/main/main.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,18 @@ import orderBy from 'lodash.orderby';
55
import Toast from 'toastr';
66
import _ from 'underscore';
77

8-
import { AppConfig, PluginsData } from 'common/config';
98
import storage from 'common/storage';
10-
import { AppData, PluginCommand, StewardCache } from 'common/type';
9+
import { AppConfig, AppData, PluginCommand, PluginsData, StewardCache } from 'common/type';
1110
import util from 'common/util';
1211
import defaultGeneral from 'conf/general';
1312
import CONST from 'constant';
14-
import { TextAlias, TextAliasType } from 'helper/alias.helper';
13+
import { TextAlias } from 'helper/alias.helper';
1514
import { getComponentsConfig } from 'helper/component.helper';
1615
import { helpers } from 'helper/index';
1716
import { getCustomPlugins } from 'helper/plugin.helper';
1817
import { Website } from 'helper/websites.helper';
1918
import { fixNumber, fixNumbers, parseWorkflow } from 'helper/workflow.helper';
20-
import { KeyStatus, Plugin, ResultItem, SearchOnInputFunc } from 'plugins/type';
19+
import { KeyStatus, Plugin, ResultItem, SearchOnInputFunc, TextAliasType } from 'plugins/type';
2120

2221
import { getPlugins } from '../plugins';
2322
import * as recordsController from '../server/controller/recordsController';

0 commit comments

Comments
 (0)