2017-03-07 4 views
1

実行時に実行ファイルを起動する電子アプリケーションを作成しています。 exeを単独で実行すると、正しく動作し、すべてのフォントが読み込まれます。しかし、電子アプリケーションで実行すると、それは開きますが、フォントファイルのうちのどれもロードすることはできません。 exeは、Visual Studioで作成されたコンパイルされたリリースプロジェクトです。電子プロジェクトからの実行ファイルがリソースをロードしていません

resフォルダをindex.htmlと同じディレクトリに入れてみましたが、無駄です。 index.htmlのため

コード:

<!DOCTYPE html> 
<html> 
    <head> 
    <meta charset="UTF-8"> 
    <title>Hello World!</title> 
    </head> 
    <body> 
    <h1>Hello World!</h1> 
    <script> 
     var child = require('child_process').execFile; 
     var exePath = "C:\\Users\\name\\Documents\\Visual Studio 2015\\Projects\\Ten\\Release\\Ten.exe"; 
     var parameters = ["test"]; 

     child(exePath, parameters, function(err, data){ 
     console.log(err); 
     console.log(data.toString()); 
     }) 
    </script> 
    </body> 
</html> 

コードmain.js

const {app, BrowserWindow} = require('electron') 
const path = require('path') 
const url = require('url') 

function createWindow() { 
// Create the browser window. 
win = new BrowserWindow({width: 800, height: 600}) 

// and load the index.html of the app. 
win.loadURL(url.format({ 
pathname: path.join(__dirname, 'index.html'), 
protocol: 'file:', 
slashes: true 
})) 

    win.webContents.openDevTools() 

    // Emitted when the window is closed. 
    win.on('closed',() => { 

    win = null 
    }) 
} 

app.on('ready', createWindow) 

// Quit when all windows are closed. 
app.on('window-all-closed',() => { 

if (process.platform !== 'darwin') { 
    app.quit() 
} 
    }) 

app.on('activate',() => { 
    if (win === null) { 
    createWindow() 
    } 
}) 

ありがとう!

答えて

1

あなたのexeはフォントを読み込むために相対パスを使用しますか?その場合は、exeをより柔軟に変更するか、execFile()への呼び出しで、オプションの3rd argを指定して、目的の作業ディレクトリを指定します。

var child = require('child_process').execFile; 
var exePath = "C:\\Users\\name\\Documents\\Visual Studio 2015\\Projects\\Ten\\Release"; 
var exe = exePath + "\\Ten.exe"; 
var parameters = ["test"]; 
var options = {cwd:exePath}; 

child(exePath, parameters, options, function(err, data){ 
    console.log(err); 
    console.log(data.toString()); 
    }); 

これでうまくいかない場合、私の推測では何らかのパーミッションの問題が発生します。 exeをテストするときとは別のユーザーとしてあなたの電子アプリを実行していますか?

+0

ありがとうございました! – guavadrag0n

関連する問題