Skip to content

Commit

Permalink
Minor polishing
Browse files Browse the repository at this point in the history
  • Loading branch information
wtetsu committed Sep 17, 2018
1 parent 320a3e6 commit 41e8cbe
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 13 deletions.
12 changes: 10 additions & 2 deletions src/content.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,13 @@ const KEY_USER_CONFIG = "**** config ****";
const loadUserSettings = async () => {
return new Promise(resolve => {
chrome.storage.sync.get([KEY_USER_CONFIG], d => {
const userSettings = JSON.parse(d[KEY_USER_CONFIG]);
const userSettingsJson = d[KEY_USER_CONFIG];
let userSettings = null;
if (userSettingsJson) {
userSettings = JSON.parse(userSettingsJson);
} else {
userSettings = {};
}
resolve(userSettings);
});
});
Expand All @@ -23,7 +29,9 @@ const processSettings = settings => {
const jsonItems = ["normalDialogStyles", "movingDialogStyles", "hiddenDialogStyles"];
for (let i = 0; i < jsonItems.length; i++) {
const item = jsonItems[i];
settings[item] = JSON.parse(settings[item]);
if (settings[item]) {
settings[item] = JSON.parse(settings[item]);
}
}

if (env.disableKeepingWindowStatus && settings.initialPosition === "keep") {
Expand Down
6 changes: 4 additions & 2 deletions src/options/Main.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,10 @@ class Main extends React.Component {
}

let userSettings = this.tryToParseJson(r[KEY_USER_CONFIG]);
for (let key of Object.keys(userSettings)) {
settings[key] = userSettings[key];
if (userSettings) {
for (let key of Object.keys(userSettings)) {
settings[key] = userSettings[key];
}
}

this.setState({ settings });
Expand Down
9 changes: 2 additions & 7 deletions src/options/MouseDictionaryOptions.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -91,16 +91,12 @@ const UserSettings = props => {
<br />
<br />
<h2>各種設定</h2>

<input type="button" value="保存する" onClick={props.onClickSaveSettings.bind(this)} />
<span> </span>
<input type="button" value="初期状態に戻す" onClick={props.onClickBackToDefaultSettings.bind(this)} />

<hr />

<label>お試し用テキスト</label>
<input type="text" value={props.trialText} onChange={props.onChangeState.bind(this, "trialText")} />

<label>短い単語の切り詰め</label>
<input type="number" value={settings.shortWordLength} onChange={props.onChange.bind(this, "shortWordLength")} style={{ width: 60 }} />
<span> 文字以内の短い単語は、説明を </span>
Expand Down Expand Up @@ -146,7 +142,6 @@ const UserSettings = props => {
<TwitterPicker color={settings.headFontColor} colors={headColors} onChangeComplete={props.onChangeColorSettings.bind(this, "headFontColor")} />
<label>文字色(説明)</label>
<TwitterPicker color={settings.descFontColor} colors={descColors} onChangeComplete={props.onChangeColorSettings.bind(this, "descFontColor")} />

<hr />
{props.settings2Opened ? (
settings2
Expand Down Expand Up @@ -222,9 +217,9 @@ const MouseDictionaryOptions = props => {
return (
<div>
<label>{res("dictDataEncoding")}</label>
<SimpleSelect name="encoding" value={props.encoding} options={ENCODINGS} onChange={props.onChange} />
<SimpleSelect name="encoding" value={props.encoding} options={ENCODINGS} onChange={props.onChangeState} />
<label>{res("dictDataFormat")}</label>
<SimpleSelect name="format" value={props.format} options={FORMATS} onChange={props.onChange} />
<SimpleSelect name="format" value={props.format} options={FORMATS} onChange={props.onChangeState} />
<label>{res("readDictData")}</label>
<input type="file" id="dictdata" />
<br />
Expand Down
4 changes: 2 additions & 2 deletions static/manifest.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "Mouse Dictionary",
"description": "Mouse Dictionary",
"name": "Mouse Dictionary(Beta)",
"description": "Mouse Dictionary(Beta)",
"author": "wtetsu",
"version": "1.0.6",
"options_ui": {
Expand Down

0 comments on commit 41e8cbe

Please sign in to comment.