Skip to content
This repository has been archived by the owner on Jun 26, 2019. It is now read-only.

Commit

Permalink
refactor: clean up codes(First Round)
Browse files Browse the repository at this point in the history
  • Loading branch information
hiroppy committed Feb 5, 2018
1 parent 6c56bef commit f909838
Show file tree
Hide file tree
Showing 87 changed files with 757 additions and 300 deletions.
1 change: 1 addition & 0 deletions .eslintrc
@@ -1,5 +1,6 @@
{
"rules": {
"no-console": 0,
"max-len": [2, { "code": 100}],
"import/order": 0,
"no-underscore-dangle": [
Expand Down
1 change: 1 addition & 0 deletions .flowconfig
Expand Up @@ -11,3 +11,4 @@
module.file_ext=.js
module.file_ext=.css
esproposal.class_static_fields=enable
suppress_comment= \\(.\\|\n\\)*\\$FlowFixMe
47 changes: 47 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 2 additions & 3 deletions src/main/autoupdater.js
@@ -1,5 +1,4 @@
// @flow
/* eslint-disable no-console */

'use strict';

Expand All @@ -17,8 +16,8 @@ autoUpdater.on('update-downloaded', () => {
console.log('downloaded');

const index = dialog.showMessageBox({
message: 'アップデートあり',
detail : '再起動してインストールできます。',
detail : '再起動してインストールできます',
message: 'アップデートがあります',
buttons: ['再起動', '後で']
});

Expand Down
20 changes: 9 additions & 11 deletions src/main/main.js
@@ -1,6 +1,4 @@
// @flow
/* eslint-disable no-console */

'use strict';

const path = require('path');
Expand Down Expand Up @@ -85,9 +83,9 @@ function createWindow() {

// Install redux-devtools and react-developer-tools.
const {
default: installExtension,
REDUX_DEVTOOLS,
REACT_DEVELOPER_TOOLS
default: installExtension,
REDUX_DEVTOOLS,
REACT_DEVELOPER_TOOLS
} = require('electron-devtools-installer');

installExtension([
Expand All @@ -99,15 +97,15 @@ function createWindow() {
}

mainWindow = windowManager.open('main', 'NicoHaco', html, false, {
frame : false,
frame : false, // TODO: windowの時、ダメ
width : 1250,
height: 800,
minWidth: 850,
minHeight: 450,
resizable: true,
alwaysOnTop : false,
showDevTools: process.env.NODE_ENV !== 'production',
titleBarStyle : 'hidden',
titleBarStyle : 'hidden', // TODO: windowsの時、ダメ?
webPreferences: {
webSecurity: false
}
Expand All @@ -119,13 +117,13 @@ function createWindow() {
});

// block ads
const filter = { urls: ['http://ads.nicovideo.jp/*'] };

session.defaultSession.webRequest.onBeforeSendHeaders(filter, (details, callback) => {
session.defaultSession.webRequest.onBeforeSendHeaders({
urls: ['http://ads.nicovideo.jp/*']
}, (details, callback) => {
callback({ cancel: true });
});

const ret = globalShortcut.register('MediaPlayPause', () => {
globalShortcut.register('MediaPlayPause', () => {
mainWindow.content().send('updateAudioStatus');
});
}
Expand Down
6 changes: 0 additions & 6 deletions src/main/menu.js
@@ -1,5 +1,3 @@
// @flow

'use strict';

const { app, Menu, shell } = require('electron');
Expand Down Expand Up @@ -67,7 +65,6 @@ const window = ({ setAlwaysOnTop }) => {
label : 'window',
submenu: [
{
// type: 'checkbox',
label: 'Use Video Player with AlwaysOnTop',
click: (flag) => setAlwaysOnTop(flag.checked)
}
Expand Down Expand Up @@ -103,9 +100,6 @@ const dev = {
]
};

/**
* create the menu
*/
function createMenu(funcs) {
const common = [about, edit, window(funcs), help(funcs)];
const template = process.env.NODE_ENV === 'production' ? common : [...common, dev];
Expand Down
2 changes: 1 addition & 1 deletion src/renderer/SubWindow/SubWindow.js
Expand Up @@ -9,7 +9,7 @@ type State = {
videoId: string;
};

class SubWindow extends React.PureComponent<void, State> {
class SubWindow extends React.PureComponent<{}, State> {
state: State;

constructor() {
Expand Down
8 changes: 5 additions & 3 deletions src/renderer/actions/auth.js
Expand Up @@ -2,7 +2,9 @@

import type {
Login,
Logout
Logout,
CreateNicoInstance,
ValidateUserSession
} from '../types/actions/auth';

export const login = (mail: string, password: string): Login => ({
Expand All @@ -15,11 +17,11 @@ export const logout = (): Logout => ({
type: 'LOGOUT'
});

export const createNicoInstance = (session: string) => ({
export const createNicoInstance = (session: string): CreateNicoInstance => ({
type: 'CREATE_NICO_INSTANCE',
session
});

export const validateUserSession = () => ({
export const validateUserSession = (): ValidateUserSession => ({
type: 'VALIDATE_USER_SESSION'
});
9 changes: 7 additions & 2 deletions src/renderer/actions/common.js
@@ -1,11 +1,16 @@
// @flow

import type {
OpenModal,
CloseModal
} from '../types/actions/common';

// eslint-disable-next-line flowtype/no-weak-types
export const openModal = (data: Object) => ({
export const openModal = (data: Object): OpenModal => ({
type: 'OPEN_MODAL',
data
});

export const closeModal = () => ({
export const closeModal = (): CloseModal => ({
type: 'CLOSE_MODAL'
});
4 changes: 3 additions & 1 deletion src/renderer/actions/db.js
@@ -1,5 +1,7 @@
// @flow

export const deleteDB = () => ({
import type { DeleteDB } from '../types/actions/db';

export const deleteDB = (): DeleteDB => ({
type: 'DELETE_DB'
});
11 changes: 11 additions & 0 deletions src/renderer/actions/mylist.js
Expand Up @@ -46,3 +46,14 @@ export const removeVideo = (groupId: string, itemId: string) => ({
groupId,
itemId
});

import {ExtractReturn} from '../types/ExtractReturn';

export type Actions =
ExtractReturn<typeof setup> |
ExtractReturn<typeof fetchMylistgroup> |
ExtractReturn<typeof createMylist> |
ExtractReturn<typeof loadMylist> |
ExtractReturn<typeof fetchMylist> |
ExtractReturn<typeof addVideo> |
ExtractReturn<typeof removeVideo>;
19 changes: 13 additions & 6 deletions src/renderer/actions/page.js
@@ -1,30 +1,37 @@
// @flow

import type { PushPage } from '../types/actions/page';
import type {
PushPage,
RoutePage,
GoBackPage,
GoForwardPage,
ControlSubWindow,
UpdateSubWindowStatus
} from '../types/actions/page';

export const pushPage = (path: string): PushPage => ({
type: 'PUSH_PAGE',
path
});

// go to login or mylist
export const routePage = () => ({
export const routePage = (): RoutePage => ({
type: 'ROUTE_PAGE'
});

export const goBackPage = () => ({
export const goBackPage = (): GoBackPage => ({
type: 'GO_BACK_PAGE'
});

export const goForwardPage = () => ({
export const goForwardPage = (): GoForwardPage => ({
type: 'GO_FORWARD_PAGE'
});

export const controlSubWindow = () => ({
export const controlSubWindow = (): ControlSubWindow => ({
type: 'CONTROL_SUB_WINDOW'
});

export const updateSubWindowStatus = (opened: boolean) => ({
export const updateSubWindowStatus = (opened: boolean): UpdateSubWindowStatus => ({
type: 'UPDATE_SUB_WINDOW_STATUS',
opened
});
33 changes: 24 additions & 9 deletions src/renderer/actions/player.js
Expand Up @@ -5,13 +5,15 @@ import type {
ToggleLoop,
ChangeVolume,
ToggleStatus,
InsertDuration,
InsertToPlaylist,
UpdateElapsedTime,
PlaySpecificAudio
PlaySpecificAudio,
ChangeLoadingStatus
} from '../types/actions/player';
import type { Mylistitem } from '../types/apis/mylist';
import type { Mylistitem } from '../types/states/Mylist';

export const play = (playType, index: number): Play => ({
export const play = (playType: 'audio' | 'video', index: number): Play => ({
type: 'PLAY',
playType,
index
Expand All @@ -22,10 +24,10 @@ export const toggleLoop = (mode: 'none' | 'one' | 'all'): ToggleLoop => ({
mode
});

export const insertToPlaylist = (playlist: Array<Mylistitem>): InsertToPlaylist => ({
type: 'INSERT_TO_PLAYLIST',
playlist
});
export const insertToPlaylist = (playlist: any): InsertToPlaylist => ({ // TODO: fix
type: 'INSERT_TO_PLAYLIST',
playlist
});

export const toggleStatus = (status?: boolean): ToggleStatus => ({
type: 'TOGGLE_STATUS',
Expand All @@ -47,12 +49,12 @@ export const changeVolume = (volume: number): ChangeVolume => ({
volume
});

export const changeLoadingStatus = (loaded: boolean) => ({
export const changeLoadingStatus = (loaded: boolean): ChangeLoadingStatus => ({
type: 'CHANGE_LOADING_STATUS',
loaded
});

export const insertDuration = (duration: number) => ({ // [TODO] rename
export const insertDuration = (duration: number): InsertDuration => ({ // [TODO] rename
type: 'INSERT_TOTAL_TIME',
duration
});
Expand All @@ -61,3 +63,16 @@ export const closeVideoPlayer = () => ({
type : 'SET_PLAY_TYPE',
playType: 'music'
});

import {ExtractReturn} from '../types/ExtractReturn';
export type Actions =
ExtractReturn<typeof play> |
ExtractReturn<typeof toggleLoop> |
ExtractReturn<typeof insertToPlaylist> |
ExtractReturn<typeof toggleStatus> |
ExtractReturn<typeof updateElapsedTime> |
ExtractReturn<typeof playSpecificAudio> |
ExtractReturn<typeof changeVolume> |
ExtractReturn<typeof changeLoadingStatus> |
ExtractReturn<typeof insertDuration> |
ExtractReturn<typeof closeVideoPlayer>;
2 changes: 1 addition & 1 deletion src/renderer/actions/ranking.js
@@ -1,6 +1,6 @@
// @flow

export const fetchRanking = (category: string, target, period) => ({
export const fetchRanking = (category: string, target: string, period: string) => ({
type: 'FETCH_RANKING',
category,
target,
Expand Down

0 comments on commit f909838

Please sign in to comment.