From 336ceba567f9c3c962d710c68e2b7e3f6ce8eb42 Mon Sep 17 00:00:00 2001 From: Kenshin Date: Fri, 22 Jun 2018 13:13:22 +0800 Subject: [PATCH] Format source. --- src/module/plugins.jsx | 62 ++++++++++++++++++++---------------------- 1 file changed, 30 insertions(+), 32 deletions(-) diff --git a/src/module/plugins.jsx b/src/module/plugins.jsx index 81557428..ea808800 100644 --- a/src/module/plugins.jsx +++ b/src/module/plugins.jsx @@ -120,37 +120,35 @@ export default class PluginsOpt extends React.Component { plugins: [] }; - initialize() { - if ( decodeURIComponent( location.href ).includes( "#plugins?install=http://simpread.ksria.cn/plugins" ) ) { - const url = decodeURIComponent( location.hash ).replace( "#plugins?install=", "" ); - run.Install( undefined, url, result => { - if ( result ) { - const install = () => { - storage.plugins[result.id] = result; - storage.Plugins( result => { - new Notify().Render( "当前插件已安装成功,2 秒后自动刷新当前页面。" ); - setTimeout( ()=> { - location.href = location.origin + location.pathname + "#plugins"; - location.reload(); - }, 2000 ); - }, storage.plugins ); - }; - if ( !storage.option.plugins.includes( result.id ) ) { - install(); - storage.option.plugins.push( result.id ); - storage.Write(); - } else if ( storage.plugins[result.id].version != result.version ) { - new Notify().Render({ content: "本地版本与安装版本不一致,是否重新安装?", action: "安装", cancel: "取消", callback: type => { - type == "action" && install(); - }}); - } else { - new Notify().Render({ content: "本地版本与安装版本一致,是否重新安装?", action: "安装", cancel: "取消", callback: type => { - type == "action" && install(); - }}); - } - } else new Notify().Render( 2, url + "获取失败,请稍后再试。" ); - }); - } + install() { + const url = decodeURIComponent( location.hash ).replace( "#plugins?install=", "" ); + run.Install( undefined, url, result => { + if ( result ) { + const add = () => { + storage.plugins[result.id] = result; + storage.Plugins( result => { + new Notify().Render( "当前插件已安装成功,2 秒后自动刷新当前页面。" ); + setTimeout( ()=> { + location.href = location.origin + location.pathname + "#plugins"; + location.reload(); + }, 2000 ); + }, storage.plugins ); + }; + if ( !storage.option.plugins.includes( result.id ) ) { + add(); + storage.option.plugins.push( result.id ); + storage.Write(); + } else if ( storage.plugins[result.id].version != result.version ) { + new Notify().Render({ content: "本地版本与安装版本不一致,是否重新安装?", action: "安装", cancel: "取消", callback: type => { + type == "action" && add(); + }}); + } else { + new Notify().Render({ content: "本地版本与安装版本一致,是否重新安装?", action: "安装", cancel: "取消", callback: type => { + type == "action" && add(); + }}); + } + } else new Notify().Render( 2, url + "获取失败,请稍后再试。" ); + }); } clear() { @@ -233,7 +231,7 @@ export default class PluginsOpt extends React.Component { componentWillMount() { storage.Plugins( () => { - this.initialize(); + decodeURIComponent( location.href ).includes( "#plugins?install=http://simpread.ksria.cn/plugins" ) && this.install(); this.setState({ plugins: Object.values( storage.plugins ) }); }); }