second instance to customurl

This commit is contained in:
cutls 2021-04-18 04:23:45 +09:00
parent e9aa22f5cf
commit 28f6ccbfee
5 changed files with 142 additions and 61 deletions

1
.gitignore vendored
View File

@ -21,6 +21,7 @@ app/view/cs
app/view/ps app/view/ps
app/view/es-AR app/view/es-AR
app/view/it-IT app/view/it-IT
app/view/pl-PL
app/git app/git
*.code-workspace *.code-workspace
releasenote.md releasenote.md

View File

@ -91,13 +91,13 @@ option {
height: 100%; height: 100%;
} }
#imagewrap img.rotate-90 { #imagewrap img.rotate-90 {
transform: rotate(-90deg) transform: rotate(-90deg);
} }
#imagewrap img.rotate-180 { #imagewrap img.rotate-180 {
transform: rotate(-180deg) transform: rotate(-180deg);
} }
#imagewrap img.rotate-270 { #imagewrap img.rotate-270 {
transform: rotate(-270deg) transform: rotate(-270deg);
} }
.pointer { .pointer {
cursor: pointer; cursor: pointer;
@ -417,13 +417,23 @@ input[type='color']::-webkit-color-swatch {
display: flex; display: flex;
flex-wrap: wrap; flex-wrap: wrap;
align-items: center; align-items: center;
width: 13rem; min-width: 150px;
height: 3.1rem; width: 50%;
height: 2.5rem;
cursor: pointer; cursor: pointer;
color: var(--text); color: var(--text);
} }
#tltype .type div {
margin-left: 5px;
margin-right: 5px;
margin-top: 3px;
}
#tltype .type span { #tltype .type span {
width: calc(100% - 2.3rem); width: calc(100% - 4rem);
white-space: nowrap;
text-overflow: ellipsis;
word-break: break-word;
overflow: hidden;
} }
#tltype .type:hover { #tltype .type:hover {
background-color: var(--beforehover); background-color: var(--beforehover);
@ -498,7 +508,8 @@ textarea {
font-size: 1rem !important; font-size: 1rem !important;
font-family: inherit; font-family: inherit;
} }
.swal2-popup, .swal2-header { .swal2-popup,
.swal2-header {
background-color: var(--subcolor) !important; background-color: var(--subcolor) !important;
} }
.swal2-title, .swal2-title,
@ -558,6 +569,7 @@ h2.swal2-title {
background-color: var(--emphasized); background-color: var(--emphasized);
} }
#pageSrc { #pageSrc {
border-radius: 10px;
position: absolute; position: absolute;
top: 0; top: 0;
left: calc(50vw - 11.53rem); left: calc(50vw - 11.53rem);
@ -565,10 +577,22 @@ h2.swal2-title {
max-width: 100%; max-width: 100%;
background-color: var(--subcolor); background-color: var(--subcolor);
z-index: 501; z-index: 501;
padding: 0.4rem;
} }
#pageSrcInput { .pageSrcBtn:hover {
width: 12.3rem; background-color: var(--active);
}
.srcQ {
margin-top: 0.4rem;
padding-left: 0.5rem;
padding-right: 0.5rem;
border-bottom: 1px solid;
}
.lastPSB {
margin-bottom: 0.4rem;
}
.pageSrcBtn {
padding-left: 0.5rem;
padding-right: 0.5rem;
} }
.voice { .voice {
clip: rect(1px, 1px, 1px, 1px); clip: rect(1px, 1px, 1px, 1px);

View File

@ -423,10 +423,6 @@ function login(url) {
versionChecker(url) versionChecker(url)
$('#add').hide() $('#add').hide()
postMessage(['openUrl', auth], '*') postMessage(['openUrl', auth], '*')
if ($('#linux:checked').val() == 'on') {
} else {
postMessage(['sendSinmpleIpc', 'quit'], '*')
}
} }
} }
} }
@ -625,7 +621,7 @@ function misskeyAuth(url, mkc) {
//テキストボックスにURL入れた //テキストボックスにURL入れた
function instance() { function instance() {
var url = $('#url').val() var url = $('#autocomplete-input').val()
if (url.indexOf('@') != -1 || url.indexOf('https') != -1) { if (url.indexOf('@') != -1 || url.indexOf('https') != -1) {
alert('入力形式が違います。(Cutls@mstdn.jpにログインする場合、入力するのは"mstdn.jp"です。)') alert('入力形式が違います。(Cutls@mstdn.jpにログインする場合、入力するのは"mstdn.jp"です。)')
return false return false
@ -634,6 +630,7 @@ function instance() {
} }
//コード入れてAccessTokenゲット //コード入れてAccessTokenゲット
function code(code) { function code(code) {
var red = localStorage.getItem('redirect')
localStorage.removeItem('redirect') localStorage.removeItem('redirect')
if (!code) { if (!code) {
var code = $('#code').val() var code = $('#code').val()
@ -696,7 +693,7 @@ function code(code) {
} }
return return
} else { } else {
var red = 'urn:ietf:wg:oauth:2.0:oob' if (!red) red = 'urn:ietf:wg:oauth:2.0:oob'
if (~url.indexOf('pixelfed')) { if (~url.indexOf('pixelfed')) {
red = 'https://thedesk.top/hello.html' red = 'https://thedesk.top/hello.html'
} }
@ -720,6 +717,7 @@ function code(code) {
if (httpreq.readyState === 4) { if (httpreq.readyState === 4) {
var json = httpreq.response var json = httpreq.response
if (this.status !== 200) { if (this.status !== 200) {
M.toast({ html: lang.lang_fatalerroroccured + 'Error: cannot complete', displayLength: 5000 })
setLog(start, this.status, json) setLog(start, this.status, json)
} }
if (json['access_token']) { if (json['access_token']) {
@ -1089,15 +1087,14 @@ function coloradd(key, bg, txt) {
//入力時にハッシュタグと@をサジェスト //入力時にハッシュタグと@をサジェスト
var timer = null var timer = null
var input = document.getElementById('url') var input = document.getElementById('autocomplete-input')
var prev_val = input.value var prev_val = input.value
var oldSuggest var oldSuggest
var suggest var suggest
input.addEventListener( input.addEventListener(
'focus', 'focus',
function () { function () {
$('#ins-suggest').html('') const instance = M.Autocomplete.getInstance(input)
window.clearInterval(timer) window.clearInterval(timer)
timer = window.setInterval(function () { timer = window.setInterval(function () {
var new_val = input.value var new_val = input.value
@ -1125,21 +1122,20 @@ input.addEventListener(
}) })
.then(function (json) { .then(function (json) {
if (!json.error) { if (!json.error) {
var urls = 'Suggest:' let data = {}
Object.keys(json.data).forEach(function (key) { Object.keys(json.data).forEach(function (key) {
var url = json.data[key] var url = json.data[key]
urls = data[url.uri] = escapeHTML(url.title ? url.title : url.uri)
urls +
`<a onclick="login('${url.uri}')" class="pointer" title="${url.uri}">${escapeHTML(url.title ? url.title : url.uri)}</a>, `
}) })
$('#ins-suggest').html(urls) instance.updateData(data)
instance.open()
} else { } else {
console.error(json.error) console.error(json.error)
} }
}) })
} }
oldSuggest = suggest oldSuggest = suggest
prev_value = new_val prev_val = new_val
} }
}, 1000) }, 1000)
}, },
@ -1157,3 +1153,12 @@ input.addEventListener(
function asReadEnd() { function asReadEnd() {
postMessage(['asReadComp', ''], '*') postMessage(['asReadComp', ''], '*')
} }
// Or with jQuery
$(document).ready(function(){
$('input.autocomplete').autocomplete({
data: {},
});
});

View File

@ -186,7 +186,7 @@ onmessage = function (e) {
} else if (e.data[0] == 'asReadEnd') { } else if (e.data[0] == 'asReadEnd') {
asReadEnd() asReadEnd()
} else if (e.data[0] == 'accessibility') { } else if (e.data[0] == 'accessibility') {
console.log('atrue') console.log('accessibility mode')
$('body').addClass('accessibility') $('body').addClass('accessibility')
$('.window-title').before('<div class="accessMark">Screen Reader Optimized</div>') $('.window-title').before('<div class="accessMark">Screen Reader Optimized</div>')
} else if (e.data[0] == 'logData') { } else if (e.data[0] == 'logData') {
@ -200,6 +200,22 @@ onmessage = function (e) {
}) })
} else if (e.data[0] == 'twitterLoginComplete') { } else if (e.data[0] == 'twitterLoginComplete') {
location.reload() location.reload()
} else if (e.data[0] == 'customUrl') {
const mode = e.data[1][0]
const codex = e.data[1][1]
if (mode === 'share') {
$('textarea').focus()
$('#textarea').val(decodeURI(codex))
show()
$('body').removeClass('mini-post')
$('.mini-btn').text('expand_less')
} else if (mode === 'manager' || mode === 'login') {
code(codex)
} else if (mode === 'spotify') {
var coder = codex.split(':')
localStorage.setItem('spotify', coder[0])
localStorage.setItem('spotify-refresh', coder[1])
}
} }
} }
/* PWA */ /* PWA */
@ -236,3 +252,34 @@ const connection = function (event) {
} }
window.onoffline = connection window.onoffline = connection
window.ononline = connection window.ononline = connection
let lastSelection = null
let isSame = true
$(document).on('keyup mouseup', function (e) {
lastSelection = (window.getSelection().toString() !== '') ? window.getSelection().getRangeAt(0) : null
if (!isSame) $('#pageSrc').addClass('hide')
})
// カスタム右クリックメニュー
$(document).on('contextmenu', function (e) {
// テキスト選択中であれば何もしない
if (lastSelection !== null) {
const currentSelection = window.getSelection().getRangeAt(0)
for (let key in currentSelection) {
if (currentSelection[key] != lastSelection[key]) {
isSame = false
break
}
}
if (isSame && currentSelection != '') {
$('#pageSrc').removeClass('hide')
$('#pageSrc').css('left', e.pageX)
$('#pageSrc').css('top', e.pageY)
$('.srcQ').text(currentSelection)
}
}
})
$('textarea, input').on('contextmenu', function (e) {
postMessage(['textareaContextMenu', { x: e.pageX, y: e.pageY }], '*')
})

View File

@ -14,12 +14,12 @@ const dl = require('./main/dl.js')
const img = require('./main/img.js') const img = require('./main/img.js')
const np = require('./main/np.js') const np = require('./main/np.js')
const systemFunc = require('./main/system.js') const systemFunc = require('./main/system.js')
const Menu = electron.Menu const { Menu, MenuItem, BrowserWindow, ipcMain } = electron
const join = require('path').join const join = require('path').join
// ウィンドウを作成するモジュール // ウィンドウを作成するモジュール
const BrowserWindow = electron.BrowserWindow
// メインウィンドウはGCされないようにグローバル宣言 // メインウィンドウはGCされないようにグローバル宣言
let mainWindow let mainWindow
let opening = true
// アプリが多重起動しないようにする // アプリが多重起動しないようにする
const gotTheLock = app.requestSingleInstanceLock() const gotTheLock = app.requestSingleInstanceLock()
@ -27,9 +27,12 @@ const gotTheLock = app.requestSingleInstanceLock()
if (!gotTheLock) { if (!gotTheLock) {
app.quit() app.quit()
} else { } else {
app.on('second-instance', () => { app.on('second-instance', (event, commandLine, workingDirector) => {
// 多重起動を試みた場合、既に存在するウィンドウにフォーカスを移す opening = false
// Someone tried to run a second instance, we should focus our window. const m = commandLine[2].match(/([a-zA-Z0-9]+)\/\?[a-zA-Z-0-9]+=(.+)/)
if (m) {
mainWindow.send('customUrl', [m[1], m[2]])
}
if (mainWindow) { if (mainWindow) {
if (mainWindow.isMinimized()) mainWindow.restore() if (mainWindow.isMinimized()) mainWindow.restore()
mainWindow.focus() mainWindow.focus()
@ -39,7 +42,7 @@ if (!gotTheLock) {
// 全てのウィンドウが閉じたら終了 // 全てのウィンドウが閉じたら終了
app.on('window-all-closed', function () { app.on('window-all-closed', function () {
electron.session.defaultSession.clearCache(() => {}) electron.session.defaultSession.clearCache(() => { })
app.quit() app.quit()
}) })
function isFile(file) { function isFile(file) {
@ -76,25 +79,26 @@ function createWindow() {
if (!packaged) console.log('launch:' + lang) if (!packaged) console.log('launch:' + lang)
//Opening //Opening
const package = fs.readFileSync(__dirname + '/package.json') const package = fs.readFileSync(__dirname + '/package.json')
if(lang == 'ja') { if (lang == 'ja') {
const maxims = JSON.parse(fs.readFileSync(__dirname + '/maxim.ja.json')) const maxims = JSON.parse(fs.readFileSync(__dirname + '/maxim.ja.json'))
var show = maxims[Math.floor(Math.random() * maxims.length)] var show = maxims[Math.floor(Math.random() * maxims.length)]
} else if(lang == 'ja-KS') { } else if (lang == 'ja-KS') {
//ja-KSも作れたらいいね //ja-KSも作れたらいいね
const maxims = JSON.parse(fs.readFileSync(__dirname + '/maxim.ja.json')) const maxims = JSON.parse(fs.readFileSync(__dirname + '/maxim.ja.json'))
var show = maxims[Math.floor(Math.random() * maxims.length)] var show = maxims[Math.floor(Math.random() * maxims.length)]
} else{ } else {
var show = 'TheDesk 2018' var show = 'TheDesk 2018'
} }
const data = JSON.parse(package) const data = JSON.parse(package)
const version = data.version const version = data.version
const codename = data.codename const codename = data.codename
var openingWindow = new BrowserWindow({ const openingWindow = new BrowserWindow({
width: 300, width: 300,
height: 400, height: 400,
transparent: false, transparent: false,
frame: false, frame: false,
resizable: false, resizable: false,
show: opening
}) })
openingWindow.loadURL(`${__dirname}/opening.html?ver=${version}&codename=${codename}&maxim=${encodeURI(show)}`) openingWindow.loadURL(`${__dirname}/opening.html?ver=${version}&codename=${codename}&maxim=${encodeURI(show)}`)
@ -133,7 +137,7 @@ function createWindow() {
if (!packaged) console.log('enabled: Hardware Acceleration') if (!packaged) console.log('enabled: Hardware Acceleration')
} }
let webviewEnabled = false let webviewEnabled = false
if(fs.existsSync(wv_path, 'utf8')) webviewEnabled = true if (fs.existsSync(wv_path, 'utf8')) webviewEnabled = true
var window_size var window_size
try { try {
window_size = JSON.parse(fs.readFileSync(info_path, 'utf8')) window_size = JSON.parse(fs.readFileSync(info_path, 'utf8'))
@ -190,13 +194,13 @@ function createWindow() {
}) })
mainWindow.webContents.on('page-title-updated', () => { mainWindow.webContents.on('page-title-updated', () => {
const url = mainWindow.webContents.getURL() const url = mainWindow.webContents.getURL()
if(url.match(/https:\/\/crowdin.com\/profile/)) { if (url.match(/https:\/\/crowdin.com\/profile/)) {
app.relaunch() app.relaunch()
app.exit() app.exit()
} }
}) })
if (!packaged) mainWindow.toggleDevTools() if (!packaged) mainWindow.toggleDevTools()
electron.session.defaultSession.clearCache(() => {}) electron.session.defaultSession.clearCache(() => { })
if (process.argv) { if (process.argv) {
if (process.argv[1]) { if (process.argv[1]) {
var m = process.argv[1].match(/([a-zA-Z0-9]+)\/\?[a-zA-Z-0-9]+=(.+)/) var m = process.argv[1].match(/([a-zA-Z0-9]+)\/\?[a-zA-Z-0-9]+=(.+)/)
@ -229,7 +233,7 @@ function createWindow() {
} }
// ウィンドウが閉じられたらアプリも終了 // ウィンドウが閉じられたらアプリも終了
mainWindow.on('closed', function () { mainWindow.on('closed', function () {
electron.ipcMain.removeAllListeners() ipcMain.removeAllListeners()
mainWindow = null mainWindow = null
}) })
closeArg = false closeArg = false
@ -242,7 +246,7 @@ function createWindow() {
mainWindow.send('asReadEnd', '') mainWindow.send('asReadEnd', '')
let wait = 3000 let wait = 3000
const url = mainWindow.webContents.getURL() const url = mainWindow.webContents.getURL()
if(!url.match(/index.html/)) wait = 0 if (!url.match(/index.html/)) wait = 0
setTimeout(function () { setTimeout(function () {
resolve() resolve()
}, wait) }, wait)
@ -252,7 +256,7 @@ function createWindow() {
mainWindow.close() mainWindow.close()
}) })
}) })
electron.ipcMain.on('sendMarkersComplete', function (e, arg) { ipcMain.on('sendMarkersComplete', function (e, arg) {
closeArg = true closeArg = true
mainWindow.close() mainWindow.close()
}) })