diff --git a/app/js/platform/preload.js b/app/js/platform/preload.js index cc30121e..c56f8a64 100644 --- a/app/js/platform/preload.js +++ b/app/js/platform/preload.js @@ -25,6 +25,22 @@ onmessage = function (e) { ipc.send('open-finder', e.data[1]); } else if (e.data[0] == "columnDel") { ipc.send('column-del', e.data[1]); + } else if (e.data[0] == "lang") { + ipc.send('lang', e.data[1]); + } else if (e.data[0] == "exportSettings") { + ipc.send('exportSettings', e.data[1]); + } else if (e.data[0] == "importSettings") { + ipc.send('importSettings', e.data[1]); + } else if (e.data[0] == "customSound") { + ipc.send('customSound', e.data[1]); + } else if (e.data[0] == "themeJsonDelete") { + ipc.send('theme-json-delete', e.data[1]); + } else if (e.data[0] == "themeJsonCreate") { + ipc.send('theme-json-create', e.data[1]); + } else if (e.data[0] == "themeJsonRequest") { + ipc.send('theme-json-request', id); + } else if (e.data[0] == "ha") { + ipc.send('ha', had); } } //version.js @@ -163,6 +179,42 @@ ipc.on('column-del-reply', function (event, args) { sortload() } }) +//setting.js +ipc.on('langres', function (event, arg) { + location.href = "../" + lang + "/setting.html" +}); +ipc.on('exportSettingsFile', function (event, savedFiles) { + var exp = exportSettingsCore() + ipc.send('export', [savedFiles, JSON.stringify(exp)]); + alert("Done.") + //cards + //lang +}); +ipc.on('config', function (event, arg) { + importSettingsCore(arg) +}); +ipc.on('savefolder', function (event, arg) { + localStorage.setItem("savefolder", arg); +}); +ipc.on('font-list', function (event, arg) { + fontList(arg) +}); +ipc.on('customSoundRender', function (event, args) { + customSoundSave(args[0], args[1]) +}); +ipc.on('theme-json-list-response', function (event, args) { + ctLoadCore(args) +}); +ipc.on('theme-json-delete-complete', function (event, args) { + ctLoad() +}); +ipc.on('theme-json-response', function (event, args) { + customConnect(args) +}); +ipc.on('theme-json-create-complete', function (event, args) { + clearCustomImport() + ctLoad() +}); /* var webviewDom = document.getElementById('webview'); const { diff --git a/app/js/ui/menu.js b/app/js/ui/menu.js index 17dbb91a..0ddea47f 100644 --- a/app/js/ui/menu.js +++ b/app/js/ui/menu.js @@ -51,6 +51,5 @@ $(function () { }); }); function help() { - const { shell } = require('electron'); - shell.openExternal("https://docs.thedesk.top"); + postMessage(["openUrl", "https://docs.thedesk.top"], "*") } \ No newline at end of file diff --git a/app/js/ui/settings.js b/app/js/ui/settings.js index c916865f..e3c745aa 100644 --- a/app/js/ui/settings.js +++ b/app/js/ui/settings.js @@ -190,9 +190,7 @@ function wordempSave() { localStorage.setItem("word_emp", json); } function notftest() { - var electron = require("electron"); - var ipc = electron.ipcRenderer; - var os = electron.remote.process.platform; + var os = localStorage.getItem("platform"); var options = { body: lang.lang_setting_notftest + '(' + lang.lang_setting_notftestprof + ')', icon: localStorage.getItem("prof_0") @@ -200,7 +198,8 @@ function notftest() { if (os == "darwin") { var n = new Notification('TheDesk' + lang.lang_setting_notftest, options); } else { - ipc.send('native-notf', ['TheDesk' + lang.lang_setting_notftest, lang.lang_setting_notftest + '(' + lang.lang_setting_notftestprof + ')', localStorage.getItem('prof_0'), "", ""]); + var nativeNotfOpt = ['TheDesk' + lang.lang_setting_notftest, lang.lang_setting_notftest + '(' + lang.lang_setting_notftestprof + ')', localStorage.getItem('prof_0'), "", ""] + postMessage(["nativeNotf", nativeNotfOpt], "*") } } @@ -215,228 +214,183 @@ function oksload() { if (localStorage.getItem("oks-3")) { $("#oks-3").val(localStorage.getItem("oks-3")) } } function changelang(lang) { - var electron = require("electron"); - var ipc = electron.ipcRenderer; - ipc.send('lang', lang); - ipc.on('langres', function (event, arg) { - location.href = "../" + lang + "/setting.html" - }); + postMessage(["lang", lang], "*") } function exportSettings() { if (!confirm(lang.lang_setting_exportwarn)) { return false; } - var electron = require("electron"); - var remote = electron.remote; - var dialog = remote.dialog; - var ipc = electron.ipcRenderer; - dialog.showSaveDialog(null, { - title: 'Export', - properties: ['openFile', 'createDirectory'], - defaultPath: "export.thedeskconfigv2" - }, (savedFiles) => { - if (!savedFiles) { - return false; - } - var exp = {}; - //Accounts - var multi = localStorage.getItem("multi"); - var acct = JSON.parse(multi); - exp.accts = acct; - //Columns - var multi = localStorage.getItem("column"); - var column = JSON.parse(multi); - exp.columns = column; - //Themes - var config = {}; - config.theme = localStorage.getItem("theme"); - //Other configs - var max = envView.config.length; - for (var i = 0; i < max; i++) { - var ls = envView.config[i].storage; - config[ls] = localStorage.getItem(ls) - } - var max = tlView.config.length; - for (var i = 0; i < max; i++) { - var ls = tlView.config[i].storage; - config[ls] = localStorage.getItem(ls) - } - var max = postView.config.length; - for (var i = 0; i < max; i++) { - var ls = postView.config[i].storage; - config[ls] = localStorage.getItem(ls) - } - //Font - config.font = localStorage.getItem("font"); - exp.config = config; - //keysc - exp.ksc = [ - localStorage.getItem("oks-1"), - localStorage.getItem("oks-2"), - localStorage.getItem("oks-3") - ]; - //climu - var cli = localStorage.getItem("client_mute"); - var climu = JSON.parse(cli); - exp.clientMute = climu; - //wordmu - var wdm = localStorage.getItem("word_mute"); - var wordmu = JSON.parse(wdm); - exp.wordMute = wordmu; - //spotify - exp.spotifyArtwork = localStorage.getItem("artwork") - var content = localStorage.getItem("np-temp"); - if (content || content == "" || content == "null") { - exp.spotifyTemplete = content; - } else { - exp.spotifyTemplete = null; - } - //tags - var tagarr = localStorage.getItem("tag"); - var favtag = JSON.parse(tagarr); - exp.favoriteTags = favtag; - ipc.send('export', [savedFiles, JSON.stringify(exp)]); - alert("Done.") - //cards - //lang - }); + postMessage(["exportSettings", ""], "*") +} +function exportSettingsCore() { + var exp = {}; + //Accounts + var multi = localStorage.getItem("multi"); + var acct = JSON.parse(multi); + exp.accts = acct; + //Columns + var multi = localStorage.getItem("column"); + var column = JSON.parse(multi); + exp.columns = column; + //Themes + var config = {}; + config.theme = localStorage.getItem("theme"); + //Other configs + var max = envView.config.length; + for (var i = 0; i < max; i++) { + var ls = envView.config[i].storage; + config[ls] = localStorage.getItem(ls) + } + var max = tlView.config.length; + for (var i = 0; i < max; i++) { + var ls = tlView.config[i].storage; + config[ls] = localStorage.getItem(ls) + } + var max = postView.config.length; + for (var i = 0; i < max; i++) { + var ls = postView.config[i].storage; + config[ls] = localStorage.getItem(ls) + } + //Font + config.font = localStorage.getItem("font"); + exp.config = config; + //keysc + exp.ksc = [ + localStorage.getItem("oks-1"), + localStorage.getItem("oks-2"), + localStorage.getItem("oks-3") + ]; + //climu + var cli = localStorage.getItem("client_mute"); + var climu = JSON.parse(cli); + exp.clientMute = climu; + //wordmu + var wdm = localStorage.getItem("word_mute"); + var wordmu = JSON.parse(wdm); + exp.wordMute = wordmu; + //spotify + exp.spotifyArtwork = localStorage.getItem("artwork") + var content = localStorage.getItem("np-temp"); + if (content || content == "" || content == "null") { + exp.spotifyTemplete = content; + } else { + exp.spotifyTemplete = null; + } + //tags + var tagarr = localStorage.getItem("tag"); + var favtag = JSON.parse(tagarr); + exp.favoriteTags = favtag; + return exp; } function importSettings() { if (!confirm(lang.lang_setting_importwarn)) { return false; } - var electron = require("electron"); - var remote = electron.remote; - var dialog = remote.dialog; - var ipc = electron.ipcRenderer; - dialog.showOpenDialog(null, { - title: 'Import', - properties: ['openFile'], - filters: [ - { name: 'TheDesk Config', extensions: ['thedeskconfig', 'thedeskconfigv2'] }, - ] - }, (fileNames) => { - if (!fileNames) { - return false; + postMessage(["importSettings", ""], "*") +} +function importSettingsCore(arg) { + var obj = JSON.parse(arg); + if (obj) { + localStorage.clear(); + localStorage.setItem("multi", JSON.stringify(obj.accts)); + for (var key = 0; key < obj.accts.length; key++) { + var acct = obj.accts[key]; + localStorage.setItem("name_" + key, acct.name); + localStorage.setItem("user_" + key, acct.user); + localStorage.setItem("user-id_" + key, acct.id); + localStorage.setItem("prof_" + key, acct.prof); + localStorage.setItem("domain_" + key, acct.domain); + localStorage.setItem("acct_" + key + "_at", acct.at); } - ipc.send('import', fileNames[0]); - ipc.on('config', function (event, arg) { - var obj = JSON.parse(arg); - if (obj) { - localStorage.clear(); - localStorage.setItem("multi", JSON.stringify(obj.accts)); - for (var key = 0; key < obj.accts.length; key++) { - var acct = obj.accts[key]; - localStorage.setItem("name_" + key, acct.name); - localStorage.setItem("user_" + key, acct.user); - localStorage.setItem("user-id_" + key, acct.id); - localStorage.setItem("prof_" + key, acct.prof); - localStorage.setItem("domain_" + key, acct.domain); - localStorage.setItem("acct_" + key + "_at", acct.at); + localStorage.setItem("column", JSON.stringify(obj.columns)); + if (obj.config) { + //Version 2 + var max = envView.config.length; + for (var i = 0; i < max; i++) { + var ls = envView.config[i].storage; + if (obj.config[ls]) { + localStorage.setItem(ls, obj.config[ls]) } - localStorage.setItem("column", JSON.stringify(obj.columns)); - if (obj.config) { - //Version 2 - var max = envView.config.length; - for (var i = 0; i < max; i++) { - var ls = envView.config[i].storage; - if (obj.config[ls]) { - localStorage.setItem(ls, obj.config[ls]) - } - } - var max = tlView.config.length; - for (var i = 0; i < max; i++) { - var ls = tlView.config[i].storage; - if (obj.config[ls]) { - localStorage.setItem(ls, obj.config[ls]) - } - } - var max = postView.config.length; - for (var i = 0; i < max; i++) { - var ls = postView.config[i].storage; - if (obj.config[ls]) { - localStorage.setItem(ls, obj.config[ls]) - } - } - } else { - //Version 1 - localStorage.setItem("theme", obj.theme); - if (obj.width) { - localStorage.setItem("width", obj.width); - } - if (obj.font) { - localStorage.setItem("font", obj.font); - } - if (obj.size) { - localStorage.setItem("size", obj.size); - } - themes(obj.theme); - if (obj.imgheight) { - localStorage.setItem("img-height", obj.imgheight); - } - localStorage.setItem("mainuse", obj.mainuse); - if (obj.cw) { - localStorage.setItem("cwtext", obj.cw); - } - localStorage.setItem("vis", obj.vis); - //End - } - if (obj.ksc[0]) { - localStorage.setItem("oks-1", obj.ksc[0]); - } - if (obj.ksc[1]) { - localStorage.setItem("oks-2", obj.ksc[1]); - } - if (obj.ksc[2]) { - localStorage.setItem("oks-3", obj.ksc[2]); - } - if (obj.clientMute) { - localStorage.setItem("client_mute", JSON.stringify(obj.clientMute)); - } - if (obj.wordMute) { - localStorage.setItem("word_mute", JSON.stringify(obj.wordMute)); - } - if (obj.favoriteTags) { - localStorage.setItem("tag", JSON.stringify(obj.favoriteTags)); - } - - localStorage.setItem("np-temp", obj.spotifyTemplete); - for (var i = 0; i < obj.columns.length; i++) { - localStorage.setItem("card_" + i, "true"); - localStorage.removeItem("catch_" + i); - } - location.href = "index.html"; - } else { - alert("Error.") } - }) - //cards - //lang - }); + var max = tlView.config.length; + for (var i = 0; i < max; i++) { + var ls = tlView.config[i].storage; + if (obj.config[ls]) { + localStorage.setItem(ls, obj.config[ls]) + } + } + var max = postView.config.length; + for (var i = 0; i < max; i++) { + var ls = postView.config[i].storage; + if (obj.config[ls]) { + localStorage.setItem(ls, obj.config[ls]) + } + } + } else { + //Version 1 + localStorage.setItem("theme", obj.theme); + if (obj.width) { + localStorage.setItem("width", obj.width); + } + if (obj.font) { + localStorage.setItem("font", obj.font); + } + if (obj.size) { + localStorage.setItem("size", obj.size); + } + themes(obj.theme); + if (obj.imgheight) { + localStorage.setItem("img-height", obj.imgheight); + } + localStorage.setItem("mainuse", obj.mainuse); + if (obj.cw) { + localStorage.setItem("cwtext", obj.cw); + } + localStorage.setItem("vis", obj.vis); + //End + } + if (obj.ksc[0]) { + localStorage.setItem("oks-1", obj.ksc[0]); + } + if (obj.ksc[1]) { + localStorage.setItem("oks-2", obj.ksc[1]); + } + if (obj.ksc[2]) { + localStorage.setItem("oks-3", obj.ksc[2]); + } + if (obj.clientMute) { + localStorage.setItem("client_mute", JSON.stringify(obj.clientMute)); + } + if (obj.wordMute) { + localStorage.setItem("word_mute", JSON.stringify(obj.wordMute)); + } + if (obj.favoriteTags) { + localStorage.setItem("tag", JSON.stringify(obj.favoriteTags)); + } + + localStorage.setItem("np-temp", obj.spotifyTemplete); + for (var i = 0; i < obj.columns.length; i++) { + localStorage.setItem("card_" + i, "true"); + localStorage.removeItem("catch_" + i); + } + location.href = "index.html"; + } else { + alert("Error.") + } } function savefolder() { - var electron = require("electron"); - var remote = electron.remote; - var dialog = remote.dialog; - dialog.showOpenDialog(null, { - title: 'Save folder', - properties: ['openDirectory'], - }, (fileNames) => { - localStorage.setItem("savefolder", fileNames[0]); - }); + postMessage(["sendSinmpleIpc", "savefolder"], "*") } function font() { - var electron = require("electron"); - var ipc = electron.ipcRenderer; - ipc.send('fonts', []); - ipc.on('font-list', function (event, arg) { - $("#fonts").removeClass("hide"); - for (var i = 0; i < arg.length; i++) { - var font = arg[i]; - $("#fonts").append('