diff --git a/app/js/login/login.js b/app/js/login/login.js index 605b4103..a91acfc6 100644 --- a/app/js/login/login.js +++ b/app/js/login/login.js @@ -537,9 +537,10 @@ function multiSelector(parseC) { } last = last + '' var sel + const webview = localStorage.getItem('webview_setting') === 'true' if (obj.length < 1) { $('#src-acct-sel').html('') - $('#add-acct-sel').html('') + $('#add-acct-sel').html('${webview ? `` : ''}`) } else { Object.keys(obj).forEach(function (key) { var acct = obj[key] @@ -610,7 +611,7 @@ function multiSelector(parseC) { $('#add-acct-sel').append( '' + `${webview ? `` : ''}` ) $('#dir-acct-sel').append('') } diff --git a/app/js/platform/end.js b/app/js/platform/end.js index 01b7c3f6..7175ea26 100644 --- a/app/js/platform/end.js +++ b/app/js/platform/end.js @@ -198,6 +198,8 @@ onmessage = function (e) { type: 'info', title: e.data[1] }) + } else if (e.data[0] == 'twitterLoginComplete') { + location.reload() } } /* PWA */ diff --git a/app/js/platform/first.js b/app/js/platform/first.js index c2cfd481..2b14d839 100644 --- a/app/js/platform/first.js +++ b/app/js/platform/first.js @@ -3,7 +3,7 @@ window.onload = function () { initPostbox() connection() initPlugin(plugins) - if(localStorage.getItem('control-center-np')) $('#ccnp').removeClass('hide') + if (localStorage.getItem('control-center-np')) $('#ccnp').removeClass('hide') } $.strip_tags = function (str, allowed) { if (!str) { @@ -290,3 +290,23 @@ function statusModel(now) { poll: null } } +function webviewFinder() { + const webview = document.querySelector('webview') + webview.addEventListener('did-navigate', (e) => { + const url = webview.getURL() + if (url.match('https://mobile.twitter.com/login')) { + postMessage(['twitterLogin', null], '*') + } else if (url.match('https://mobile.twitter.com/logout')) { + postMessage(['twitterLogin', true], '*') + } + }) +} +function initWebviewEvent() { + if (document.querySelector('webview')) { webviewFinder() } else { + const timerWV = setInterval(function () { + document.querySelector('webview') + ? (webviewFinder(), clearInterval(timerWV)) + : console.log('まだロード中') + }, 500) + } +} \ No newline at end of file diff --git a/app/js/platform/preload.js b/app/js/platform/preload.js index ea64945c..248582d2 100644 --- a/app/js/platform/preload.js +++ b/app/js/platform/preload.js @@ -54,6 +54,8 @@ onmessage = function(e) { ipc.send('theme-json-request', e.data[1]) } else if (e.data[0] == 'ha') { ipc.send('ha', e.data[1]) + } else if (e.data[0] == 'webviewSetting') { + ipc.send('webview', e.data[1]) } else if (e.data[0] == 'frameSet') { ipc.send('frameSet', e.data[1]) } else if (e.data[0] == 'ua') { @@ -77,6 +79,8 @@ onmessage = function(e) { ipc.send('copy', e.data[1]) } else if (e.data[0] == 'log') { ipc.send('log', e.data[1]) + } else if (e.data[0] == 'twitterLogin') { + ipc.send('twitterLogin', e.data[1]) } } //version.js @@ -227,9 +231,6 @@ ipc.on('asReadEnd', function(event, arg) { ipc.on('accessibility', function(event, arg) { postMessage(['accessibility', 'true'], '*') }) -var webviewDom = document.getElementById('webview') -if (webviewDom) { - webviewDom.addEventListener('new-window', function(e) { - shell.openExternal(e.url) - }) -} +ipc.on('twitterLoginComplete', function(event, arg) { + postMessage(['twitterLoginComplete', ''], '*') +}) diff --git a/app/js/ui/layout.js b/app/js/ui/layout.js index edff655f..c4dd2388 100644 --- a/app/js/ui/layout.js +++ b/app/js/ui/layout.js @@ -185,6 +185,7 @@ function parseColumn(target, dontclose) { } var html = webviewParse('https://tweetdeck.twitter.com', key, insert, icnsert, css) $('#timeline-container').append(html) + initWebviewEvent() } else if (acct.type == 'tootsearch') { if (!acct.left_fold) { basekey = key diff --git a/app/js/ui/settings.js b/app/js/ui/settings.js index fe81242a..464529e2 100644 --- a/app/js/ui/settings.js +++ b/app/js/ui/settings.js @@ -13,16 +13,18 @@ var envView = new Vue({ for (var j = 0; j < ls.length; j++) { M.toast({ html: 'Complete', displayLength: 3000 }) var id = ls[j].id - var val = $('#' + id).val() localStorage.setItem(ls[j].storage, val) } - if (ls == 'ha') { + if (ls[0].id == 'ha') { hardwareAcceleration(val) } - if (ls == 'ua_setting') { + if (ls[0].id == 'webview') { + postMessage(['webviewSetting', val], '*') + } + if (ls[0].id == 'ua_setting') { useragent(val) } - if (ls == 'frame') { + if (ls[0].id == 'frame') { frameSet(val) } return true @@ -302,7 +304,7 @@ function oksload() { function changeLang() { const lang = $('#langsel-sel').val() console.log(lang) - if(lang) postMessage(['lang', lang], '*') + if (lang) postMessage(['lang', lang], '*') } function exportSettings() { var exp = exportSettingsCore() @@ -787,7 +789,7 @@ function completePlugin(comp) { var pgns = localStorage.getItem('plugins') var args = JSON.parse(pgns ? pgns : '[]') var id = $('#plugin').attr('data-id') - + var inputPlugin = editor.getValue() var meta = getMeta(inputPlugin) if (!meta.data) { @@ -821,7 +823,7 @@ function completePlugin(comp) { } var ss = args localStorage.setItem('plugins', JSON.stringify(ss)) - if(comp) return false + if (comp) return false $('#plugin').attr('data-id', 'add_new') editor.setValue('', -1) pluginLoad() diff --git a/app/main.js b/app/main.js index a0fffbe4..5cd0ab13 100644 --- a/app/main.js +++ b/app/main.js @@ -123,6 +123,7 @@ function createWindow() { var info_path = join(app.getPath('userData'), 'window-size.json') var max_info_path = join(app.getPath('userData'), 'max-window-size.json') var ha_path = join(app.getPath('userData'), 'hardwareAcceleration') + var wv_path = join(app.getPath('userData'), 'webview') var ua_path = join(app.getPath('userData'), 'useragent') try { fs.readFileSync(ha_path, 'utf8') @@ -131,6 +132,8 @@ function createWindow() { } catch { if (!packaged) console.log('enabled: Hardware Acceleration') } + let webviewEnabled = false + if(fs.existsSync(wv_path, 'utf8')) webviewEnabled = true var window_size try { window_size = JSON.parse(fs.readFileSync(info_path, 'utf8')) @@ -156,7 +159,7 @@ function createWindow() { var bit = process.arch var arg = { webPreferences: { - webviewTag: true, + webviewTag: webviewEnabled, nodeIntegration: false, contextIsolation: true, spellcheck: false, diff --git a/app/main/system.js b/app/main/system.js index aaa7fd04..c9787673 100644 --- a/app/main/system.js +++ b/app/main/system.js @@ -9,6 +9,7 @@ function system(mainWindow, dir, lang, dirname) { const clipboard = electron.clipboard var tmp_img = join(app.getPath('userData'), 'tmp.png') var ha_path = join(app.getPath('userData'), 'hardwareAcceleration') + var wv_path = join(app.getPath('userData'), 'webview') var ua_path = join(app.getPath('userData'), 'useragent') var lang_path = join(app.getPath('userData'), 'language') var log_dir_path = join(app.getPath('userData'), 'logs') @@ -100,7 +101,16 @@ function system(mainWindow, dir, lang, dirname) { if (arg == 'true') { fs.writeFileSync(ha_path, arg) } else { - fs.unlink(ha_path, function (err) {}) + fs.unlink(ha_path, function (err) { }) + } + app.relaunch() + app.exit() + }) + ipc.on('webview', function (e, arg) { + if (arg == 'true') { + fs.writeFileSync(wv_path, arg) + } else { + fs.unlink(wv_path, function (err) { }) } app.relaunch() app.exit() @@ -108,7 +118,7 @@ function system(mainWindow, dir, lang, dirname) { //ユーザーエージェント ipc.on('ua', function (e, arg) { if (arg == '') { - fs.unlink(ua_path, function (err) {}) + fs.unlink(ua_path, function (err) { }) } else { fs.writeFileSync(ua_path, arg) } @@ -299,5 +309,28 @@ function system(mainWindow, dir, lang, dirname) { }) } }) + + ipc.on('twitterLogin', (e, args) => { + const window = new BrowserWindow({ + webPreferences: { + webviewTag: false, + nodeIntegration: false, + contextIsolation: true, + preload: join(dirname, 'js', 'platform', 'preload.js'), + }, + width: 414, + height: 736, + }) + const login = `https://mobile.twitter.com/login?hide_message=true&redirect_after_login=https%3A%2F%2Ftweetdeck.twitter.com%2F%3Fvia_twitter_login%3Dtrue` + const logout = `https://mobile.twitter.com/logout?redirect_after_logout=https%3A%2F%2Ftweetdeck.twitter.com%2F` + window.loadURL(args ? logout : login) + window.webContents.on('did-navigate', () => { + const url = window.webContents.getURL() + if (url.match("https://tweetdeck.twitter.com")) { + window.close() + e.sender.webContents.send('twitterLoginComplete', '') + } + }) + }) } exports.system = system diff --git a/app/view/make/language/en/setting.json b/app/view/make/language/en/setting.json index aed93776..075d7173 100644 --- a/app/view/make/language/en/setting.json +++ b/app/view/make/language/en/setting.json @@ -18,6 +18,8 @@ "export": "Export", "hardwareAcceleration": "Disable hardware acceleration", "hardwareAccelerationWarn": "Auto restarted", + "webview": "Webview Integration", + "webviewWarn": "To use TweetDeck Integration, please turn on. You should understand it may lessen security level.", "theme": "Themes", "popup": "Popup notification", "popupwarn": "Hide to set \"0\"", diff --git a/app/view/make/language/ja-KS/setting.json b/app/view/make/language/ja-KS/setting.json index 8c7ac749..e2bd32b6 100644 --- a/app/view/make/language/ja-KS/setting.json +++ b/app/view/make/language/ja-KS/setting.json @@ -17,6 +17,8 @@ "export": "エクスポート", "hardwareAcceleration": "ハードウェアアクセラレーションの無効化", "hardwareAccelerationWarn": "表示(特に設定画面)があかんときは「はい」を選んでな。再起動入るで。", + "webview": "Webviewの使用", + "webviewWarn": "TweetDeck使いたかったら「はい」にしてほしいんやけど、セキュリティ的には結構あかんやつやから、使わんのやったらちゃんと「いいえ」にしといてな。再起動入るで。", "theme": "テーマの設定", "popup": "新規通知のポップアップお知らせの表示秒数", "popupwarn": "0にしたら出さへん", diff --git a/app/view/make/language/ja/setting.json b/app/view/make/language/ja/setting.json index d558b3a9..7b0e082c 100644 --- a/app/view/make/language/ja/setting.json +++ b/app/view/make/language/ja/setting.json @@ -18,6 +18,8 @@ "export": "エクスポート", "hardwareAcceleration": "ハードウェアアクセラレーションの無効化", "hardwareAccelerationWarn": "表示(特に設定画面)が乱れる場合に「はい」を選択してください。自動で再起動します。", + "webview": "Webviewの使用", + "webviewWarn": "TweetDeckを埋め込むために必要です。セキュリティに影響するため、使用しないときは「いいえ」を選択してください。自動で再起動します。", "theme": "テーマの設定", "popup": "新規通知のポップアップお知らせの表示秒数", "popupwarn": "0に設定すると表示されません", diff --git a/app/view/make/make.js b/app/view/make/make.js index 3fd26a8c..44e8f75f 100644 --- a/app/view/make/make.js +++ b/app/view/make/make.js @@ -29,7 +29,7 @@ function main(ver, basefile, pwa, store) { fs.writeFileSync(basefile + 'git', gitHash) console.log('Constructing view files ' + ver) const langs = ['ja', 'ja-KS', 'en', 'bg', 'cs', 'de', - 'es-AR', 'it-IT', 'zh-CN', 'zh-TW', 'fr-FR', 'no-NO', 'pt-BR', 'ru-RU', 'es-ES','pl-PL', 'ps'] + 'es-AR', 'it-IT', 'zh-CN', 'fr-FR', 'zh-TW', 'no-NO', 'pt-BR', 'ru-RU', 'es-ES','pl-PL', 'ps'] const langsh = [ '日本語', '日本語(関西)', diff --git a/app/view/make/setting.sample.js b/app/view/make/setting.sample.js index aa40841b..811c24b1 100644 --- a/app/view/make/setting.sample.js +++ b/app/view/make/setting.sample.js @@ -154,6 +154,26 @@ var envConstruction = [ desc: '@@useragentWarn@@' } }, + { + id: 'webview', + storage: 'webview_setting', + checkbox: true, + setValue: false, + text: { + head: '@@webview@@', + desc: '@@webviewWarn@@', + checkbox: [ + { + text: '@@yes@@', + value: 'true' + }, + { + text: '@@no@@', + value: 'false' + } + ] + } + }, { id: 'srcUrl', storage: 'srcUrl', diff --git a/app/view/pl-PL/index.html b/app/view/pl-PL/index.html index 900e38b7..276e87d2 100644 --- a/app/view/pl-PL/index.html +++ b/app/view/pl-PL/index.html @@ -26,7 +26,7 @@