vulcan9 / jikji.editor

jik-ji 프로젝트 관리
Other
0 stars 0 forks source link

JIK, JJS, JJC 파일등을 더블클릭으로 열기할때 실행이 잘 안되는 현상 #247

Closed vulcan9 closed 1 year ago

vulcan9 commented 2 years ago

이슈 내용

더블클릭으로 저작도구 관련 파일들을 실행하고자 할때 저작도구가 포커싱을 받기는 하나 실행하지는 않는 현상이 있음

재연 방법

  1. 저작도구를 실행한다
  2. jjc, jjs, jjt, jik 파일등을 더블클릭으로 실행한다.
  3. 간헐적으로 더블클릭한 파일에 대한 명령이 실행되지 않는 현상이 발생한다.

디버깅

디버깅 창에서 nw.App open 이벤트를 통해 로그를 확인해 보면 다음과 같이 문자열이 깨짐으로 인해 파일 경로를 확인할 수 없는 현상이 확인되었다.

    nw.App.on('open', function(argString){
        console.error('App Open Event args: ', argString);
        // argString 내용 중 마지막 전달된 인자가 더블클릭된 파일 경로임
    });

위 코드에서 argString 내용 중 exe 파일 경로 뒤에 따라오는 옵션들은 package.json 파일에서 설정된 chromium-args 항목 내용들이며 원본은 다음과 같다.

"chromium-args": "--disable-features=nw2 --disable-backgrounding-occluded-windows --disable-raf-throttling --disable-background-timer-throttling --disable-renderer-accessibility  --disable-file-system --enable-local-file-accesses --disable-web-security --allow-file-access-from-files --allow-file-access --allow-insecure-localhost --allow-running-insecure-content --enable-webfonts-intervention-trigger --allow-running-insecure-content --ignore-certificate-errors --ignore-urlfetcher-cert-requests --allow-http-background-page --allow-http-screen-capture",

더블클릭으로 실행하면 nwJS는 open 이벤트의 매개변수로 "chromium-args"의 내용이 추가된 문자열과 더블클릭된 파일 경로를 전달해 준다.

정상적인 매개변수 문자열은 다음과 같아야한다.

"... /Jik-ji Editor.exe" --disable-features=nw2 ...(chromium-args 옵션 문자열)... "더블클릭된 파일 경로"

하지만 문제가 발생할때 로그는 다음과 같이 뒷부분의 문자열이 깨진 상태로 전달된다. image

문제 원인

매개변수 문자열이 깨진 상태로 전달되므로 더블클릭된 파일 경로를 파싱할 수 없기 때문에 실행 명령이 중단된다.

이 문제는 nwJS에서 chromium-args 내용을 처리할때 발생하는 버그일 가능성이 높다. chromium-args 내용이 약 256글자 이내이면 옵션 내용과 관계없이 정상동작하는 것을 확인하였다. 글자가 깨지는 것은 한글 문제와 관련이 없고 데이터의 길이 문제인것으로 추측된다. 이 문제는 글자가 깨지는 위치에 따라 간헐적으로 발생한다.

해결

chromium-args 항목의 내용이 너무 길경우 File Association (더블 클릭) 기능 실행시 글자 깨짐이 발생하므로 chromium-args 설정을 사용하지 않고 NW_PRE_ARGS 환경변수를 사용하여 버그를 우회한다. (https://docs.nwjs.io/en/latest/References/Command%20Line%20Options/#environment-variables)

launcher에서 exe를 실행할때 환경 변수로 지정해 주면 NW_PRE_ARGS 값은 chromium-args 값 앞에 자동으로 붙어 전달된다.

        var option = {
            detached: true,
            env: {
                NW_PRE_ARGS: "--disable-features=nw2 ..."
            }
        };

        var child_process = require('child_process');
        var child = child_process.spawn(command, args, option);
        child.unref();

image

매개변수가 정상적으로 전달됨을 확인함.