Closed qcgm1978 closed 7 months ago
The gray screen suggests that something isn't working properly.
This works for me:
I copied the files wrongly. I directly copied the image files from Finder, which may not be supported. Now I'm able to solve the tsumego problems, thank you very much!
I found the app only support copying the contents of the SGF or IMG file instead of the file directly. It seems should prompt user about the error as the following code:
function paste_sgf_or_url_from_clipboard() {
const s = clipboard.readText(1);
if (/\.\w{0,5}$/.test(s)) { // match .sgf, .png etc
return toast('Please copy the contents of the SGF or IMG file instead of copying the file directly.',3000)
}
...
}
Could you explain this in detail? I'd like to know:
clipboard.readText()
and clipboard.readText(1)
in this situationBy the way, is clipboard.readText(1)
correct? Do you mean clipboard.readText('selection')
?
clipboard.readText()
, clipboard.readText(0)
, clipboard.readText('selection')
and clipboard.readText(1)
all return the same file name of the copied file such as 122706.sgf
, 李维清-伊凌涛.png
So I think it is not supported that copy the file in finder(Mac folder) directly.
Would you try this in paste_sgf_or_url_from_clipboard()
?
console.log(clipboard.availableFormats().map(fmt => [fmt, clipboard.read(fmt)]))
If we can obtain the full path of the file, it is better to open the file directly rather than to show an error message. We may need to use a library to detect the file type for this approach.
Very correct, your words inspired me to find a solution. You need to first obtain the file path. The code is as follows:
function get_clipboard_path() {
const buffer = clipboard.readBuffer('public.file-url')
const filePath = buffer.toString('utf-8')
return filePath
}
function paste_sgf_or_url_from_clipboard() {
let s = get_clipboard_path()
// the copied would be data instead of file if s is empty string by my observation
if (s == '') {
s = clipboard.readText(1);
if (!clipboard.readImage().isEmpty()) {
open_clipboard_image();
return
}
}
if (s.match('^(file|https?)://')) {
open_url(s)
} else {
read_sgf(s)
}
}
So could you test this code for the next release?
--- a/src/main.js
+++ b/src/main.js
@@ -2127,7 +2127,11 @@ function copy_sgf_to_clipboard(cache_suggestions_p) {
}
function paste_sgf_or_url_from_clipboard() {
if (!clipboard.readImage().isEmpty()) {open_clipboard_image(); return}
- const s = clipboard.readText(); s.match('^(file|https?)://') ? open_url(s) : read_sgf(s)
+ // clipboard.has and clipboard.read are experimental in Electron v28 [2024-02-02]
+ const read = format => clipboard.has(format) && clipboard.read(format)
+ const mac_url = 'public.file-url' // for Cmd-C on Finder (Mac)
+ const s = read(mac_url) || clipboard.readText()
+ s.match('^(file|https?)://') ? open_url(s) : read_sgf(s)
}
function open_sgf_etc() {open_sgf_etc_in(option_path('sgf_dir'))}
clipboard.readImage().isEmpty()
can't check whether the copied is img on mac. If the copied is a sgf file, this method !clipboard.readImage().isEmpty()
would still return true. It may still need to check the result of read(mac_url). For example change to the following code:
function paste_sgf_or_url_from_clipboard() {
// clipboard.has and clipboard.read are experimental in Electron v28 [2024-02-02]
const read = format => clipboard.has(format) && clipboard.read(format)
const mac_url = 'public.file-url' // for Cmd-C on Finder (Mac)
const mac_s = read(mac_url);
const s = mac_s || clipboard.readText()
if (mac_s=='' && !clipboard.readImage().isEmpty()) {open_clipboard_image(); return}
s.match('^(file|https?)://') ? open_url(s) : read_sgf(s)
}
Thanks for pointing that out. Does this work for various cases?
--- a/src/main.js
+++ b/src/main.js
@@ -2126,6 +2126,9 @@ function copy_sgf_to_clipboard(cache_suggestions_p) {
clipboard.writeText(game.to_sgf(cache_suggestions_p)); wink()
}
function paste_sgf_or_url_from_clipboard() {
+ // clipboard.read is experimental in Electron v28 [2024-02-02]
+ const mac_url = clipboard.read('public.file-url') // for Cmd-C on Finder (Mac)
+ if (mac_url) {open_url(mac_url); return}
if (!clipboard.readImage().isEmpty()) {open_clipboard_image(); return}
const s = clipboard.readText(); s.match('^(file|https?)://') ? open_url(s) : read_sgf(s)
}
(;SZ[19];B[qd];W[cd])
to select it. Push Cmd-C.Yes. All the five cases work.
fixed
I'm trying to solve tsumego problems using this app, but when pasting the tsumego image, it shows up as gray and the tsumego position is not displayed. The effect and image are shown below:
update: Do I need to drag the img into gray area? It displays if I drag it but the stones aren't recognized correctly.