Use Theme type instead of any

This commit is contained in:
Aya Morisawa 2019-06-04 18:41:55 +09:00
parent 0fd0b4f466
commit f6f493536c
No known key found for this signature in database
GPG key ID: 3E64865D70D579F2
8 changed files with 24 additions and 17 deletions

View file

@ -14,6 +14,7 @@ import { program } from '../argv';
import { showMachineInfo } from '../misc/show-machine-info'; import { showMachineInfo } from '../misc/show-machine-info';
import { initDb } from '../db/postgre'; import { initDb } from '../db/postgre';
import Xev from 'xev'; import Xev from 'xev';
import { Theme } from '../theme';
const logger = new Logger('core', 'cyan'); const logger = new Logger('core', 'cyan');
const bootLogger = logger.createSubLogger('boot', 'magenta', false); const bootLogger = logger.createSubLogger('boot', 'magenta', false);
@ -116,7 +117,7 @@ function showEnvironment(): void {
} }
const pluginService = { const pluginService = {
registerTheme(theme: any) { registerTheme(theme: Theme) {
const ev = new Xev(); const ev = new Xev();
ev.emit('registerPluginTheme', theme); ev.emit('registerPluginTheme', theme);
} }

View file

@ -2,6 +2,7 @@ import * as cluster from 'cluster';
import { initDb } from '../db/postgre'; import { initDb } from '../db/postgre';
import Xev from 'xev'; import Xev from 'xev';
import { registerTheme } from '../pluginThemes'; import { registerTheme } from '../pluginThemes';
import { Theme } from '../theme';
const ev = new Xev(); const ev = new Xev();
@ -21,7 +22,7 @@ export async function workerMain() {
// Send a 'ready' message to parent process // Send a 'ready' message to parent process
process.send!('ready'); process.send!('ready');
ev.on('registerPluginTheme', theme => { ev.on('registerPluginTheme', (theme: Theme) => {
registerTheme(theme); registerTheme(theme);
}); });
} }

View file

@ -123,7 +123,8 @@
<script lang="ts"> <script lang="ts">
import Vue from 'vue'; import Vue from 'vue';
import i18n from '../../../../i18n'; import i18n from '../../../../i18n';
import { lightTheme, darkTheme, applyTheme, Theme } from '../../../../theme'; import { lightTheme, darkTheme, applyTheme } from '../../../../theme';
import { Theme } from '../../../../../../theme';
import { Chrome } from 'vue-color'; import { Chrome } from 'vue-color';
import * as uuid from 'uuid'; import * as uuid from 'uuid';
import * as tinycolor from 'tinycolor2'; import * as tinycolor from 'tinycolor2';

View file

@ -9,7 +9,8 @@ import Progress from './common/scripts/loading';
import Err from './common/views/components/connect-failed.vue'; import Err from './common/views/components/connect-failed.vue';
import Stream from './common/scripts/stream'; import Stream from './common/scripts/stream';
import { Theme, builtinThemes } from './theme'; import { builtinThemes } from './theme';
import { Theme } from '../../theme';
import { concat } from '../../prelude/array'; import { concat } from '../../prelude/array';
//#region api requests //#region api requests

View file

@ -1,14 +1,5 @@
import * as tinycolor from 'tinycolor2'; import * as tinycolor from 'tinycolor2';
import { Theme } from '../../theme';
export type Theme = {
id: string;
name: string;
author: string;
desc?: string;
base?: 'dark' | 'light';
vars: { [key: string]: string };
props: { [key: string]: string };
};
export const lightTheme: Theme = require('../themes/light.json5'); export const lightTheme: Theme = require('../themes/light.json5');
export const darkTheme: Theme = require('../themes/dark.json5'); export const darkTheme: Theme = require('../themes/dark.json5');

View file

@ -1,6 +1,8 @@
const themes: any[] = []; import { Theme } from './theme';
export function registerTheme(theme: any) { const themes: Theme[] = [];
export function registerTheme(theme: Theme) {
themes.push(theme); themes.push(theme);
} }

View file

@ -1,12 +1,13 @@
require('json5/lib/register'); require('json5/lib/register');
import * as fs from 'fs'; import * as fs from 'fs';
import { Theme } from '../../theme';
export function onActivate(service: any) { export function onActivate(service: any) {
const fileNames = fs.readdirSync(`${__dirname}/themes`) const fileNames = fs.readdirSync(`${__dirname}/themes`)
.filter(f => fs.statSync(`${__dirname}/themes/${f}`).isFile()); .filter(f => fs.statSync(`${__dirname}/themes/${f}`).isFile());
for (const fileName of fileNames) { for (const fileName of fileNames) {
const theme = require(`${__dirname}/themes/${fileName}`); const theme = require(`${__dirname}/themes/${fileName}`) as Theme;
service.registerTheme(theme); service.registerTheme(theme);
} }
} }

9
src/theme.ts Normal file
View file

@ -0,0 +1,9 @@
export type Theme = {
id: string;
name: string;
author: string;
desc?: string;
base?: 'dark' | 'light';
vars: { [key: string]: string };
props: { [key: string]: string };
};