From 834fa719b27bce170ceaf2687839a4819b844c1d Mon Sep 17 00:00:00 2001 From: Cutls Date: Thu, 29 Aug 2019 01:20:47 +0900 Subject: [PATCH] Introduce: JSON5 and export v2.1 --- app/js/lang/json5Tojson.js | 3 +++ app/js/platform/end.js | 7 +++++-- app/js/platform/preload.js | 11 ++++------- app/js/ui/settings.js | 6 +++--- app/main/system.js | 9 +++++---- app/view/make/index.sample.html | 13 ++++++++----- 6 files changed, 28 insertions(+), 21 deletions(-) create mode 100644 app/js/lang/json5Tojson.js diff --git a/app/js/lang/json5Tojson.js b/app/js/lang/json5Tojson.js new file mode 100644 index 00000000..59a20745 --- /dev/null +++ b/app/js/lang/json5Tojson.js @@ -0,0 +1,3 @@ +const JSON5 = require('json5') +const fs = require("fs") +fs.writeFileSync("main.json", JSON.stringify(JSON5.parse(fs.readFileSync("lang." + process.argv[2] + ".js", 'utf8').replace("var lang = ", "")))) \ No newline at end of file diff --git a/app/js/platform/end.js b/app/js/platform/end.js index 7b474647..c7a03a4c 100644 --- a/app/js/platform/end.js +++ b/app/js/platform/end.js @@ -141,8 +141,11 @@ onmessage = function (e) { } else if (e.data[0] == "parseColumn") { parseColumn(e.data[1]) } else if (e.data[0] == "exportSettingsCore") { - exportSettingsCore() - } else if (e.data[0] == "fontList") { + var exp = exportSettingsCore() + postMessage(["exportSettingsCoreComplete", [e.data[1], exp]], "*") + } else if (e.data[0] == "importSettingsCore") { + importSettingsCore(e.data[1]) + }else if (e.data[0] == "fontList") { fontList(e.data[1]) } else if (e.data[0] == "customSoundSave") { customSoundSave(e.data[1][0], e.data[1][1]) diff --git a/app/js/platform/preload.js b/app/js/platform/preload.js index aea35298..8d96cdaa 100644 --- a/app/js/platform/preload.js +++ b/app/js/platform/preload.js @@ -2,7 +2,6 @@ var electron = require("electron"); const shell = electron.shell; var ipc = electron.ipcRenderer; onmessage = function (e) { - console.log(e) if (e.data[0] == "openUrl") { urls = e.data[1].match(/https?:\/\/(.+)/); if (urls) { @@ -31,6 +30,8 @@ onmessage = function (e) { ipc.send('lang', e.data[1]); } else if (e.data[0] == "exportSettings") { ipc.send('exportSettings', e.data[1]); + } else if (e.data[0] == "exportSettingsCoreComplete") { + ipc.send('export', e.data[1]); } else if (e.data[0] == "importSettings") { ipc.send('importSettings', e.data[1]); } else if (e.data[0] == "customSound") { @@ -112,12 +113,8 @@ ipc.on('general-dl-message', function (event, arg) { ipc.on('langres', function (event, arg) { location.href = "../" + arg + "/setting.html" }); -ipc.on('exportSettingsFile', function (event, savedFiles) { - var exp = exportSettingsCore() - ipc.send('export', [savedFiles, JSON.stringify(exp)]); - postMessage(["alert", "Done"], "*") - //cards - //lang +ipc.on('exportSettingsFile', function (event, arg) { + postMessage(["exportSettingsCore", arg], "*") }); ipc.on('config', function (event, arg) { postMessage(["importSettingsCore", arg], "*") diff --git a/app/js/ui/settings.js b/app/js/ui/settings.js index d0043daa..99bbc28e 100644 --- a/app/js/ui/settings.js +++ b/app/js/ui/settings.js @@ -323,6 +323,7 @@ function exportSettingsCore() { var tagarr = localStorage.getItem("tag"); var favtag = JSON.parse(tagarr); exp.favoriteTags = favtag; + exp.version = "2.1" return exp; } function importSettings() { @@ -340,8 +341,7 @@ function importSettings() { } }) } -function importSettingsCore(arg) { - var obj = JSON.parse(arg); +function importSettingsCore(obj) { if (obj) { localStorage.clear(); localStorage.setItem("multi", JSON.stringify(obj.accts)); @@ -356,7 +356,7 @@ function importSettingsCore(arg) { } localStorage.setItem("column", JSON.stringify(obj.columns)); if (obj.config) { - //Version 2 + //Version 2~ var max = envView.config.length; for (var i = 0; i < max; i++) { var ls = envView.config[i].storage; diff --git a/app/main/system.js b/app/main/system.js index c1c8ffb7..560cabe1 100644 --- a/app/main/system.js +++ b/app/main/system.js @@ -4,6 +4,7 @@ function system(mainWindow, dir, lang, dirname) { const join = require('path').join; var Jimp = require("jimp"); const fs = require("fs"); + var JSON5 = require('json5'); var ipc = electron.ipcMain; var tmp_img = join(app.getPath("userData"), "tmp.png"); var ha_path = join(app.getPath("userData"), "hardwareAcceleration"); @@ -61,7 +62,7 @@ function system(mainWindow, dir, lang, dirname) { dialog.showSaveDialog(null, { title: 'Export', properties: ['openFile', 'createDirectory'], - defaultPath: "export.thedeskconfigv2" + defaultPath: "export.thedeskconfig.json5" }, (savedFiles) => { if (!savedFiles) { return false; @@ -75,13 +76,13 @@ function system(mainWindow, dir, lang, dirname) { title: 'Import', properties: ['openFile'], filters: [ - { name: 'TheDesk Config', extensions: ['thedeskconfig', 'thedeskconfigv2'] }, + { name: 'TheDesk Config', extensions: ['thedeskconfig', 'thedeskconfigv2', 'json5'] }, ] }, (fileNames) => { if (!fileNames) { return false; } - e.sender.webContents.send('config', fs.readFileSync(arg, 'utf8')); + e.sender.webContents.send('config', JSON5.parse(fs.readFileSync(fileNames[0], 'utf8'))); }) }) //保存フォルダのダイアログ @@ -194,7 +195,7 @@ function system(mainWindow, dir, lang, dirname) { ipc.on('export', (e, args) => { - fs.writeFileSync(args[0], args[1]); + fs.writeFileSync(args[0], JSON5.stringify(args[1])); }); //フォント function object_array_sort(data, key, order, fn) { diff --git a/app/view/make/index.sample.html b/app/view/make/index.sample.html index 32dcf917..a91e82a1 100644 --- a/app/view/make/index.sample.html +++ b/app/view/make/index.sample.html @@ -681,11 +681,14 @@ Pixiv Fanboxでは支援者様限定で様々なTheDeskに関する記事をご覧いただけます。最低月一更新。
困ったときは、TheDesk Docsをご覧ください。
Release Note Usamin (18.8.3)
- ・Pawooでフォローできなかった不具合を修正。
- ・(macOS)iTunes NowPlayingでにの不具合を修正。
- ・トゥートのアクションが正しく切り替えれれない不具合を修正。
- ・アカウント画面のトゥートのカウントが上手くいってなかった不具合を修正。
- ・アカウント画面のデザインを大幅に改善。
+ ・設定エクスポートファイルが変更された
+ .thedeskconfigv2: 17.2.0~18.8.3
+ .thedeskconfig: 16.0.1~17.2.0
+ .json5: 本バージョン以降
+ エクスポート可能な形式
+ .json5
+ インポート可能な形式
+ .thedeskconfigv2, .thedeskconfig, .json5