Error when using electron `app.getPath('home');`

一世执手 提交于 2020-08-10 05:48:07

问题


I have the following code within a script I am using within my electron app:

window.$ = window.jQuery = require('jquery');
const {
   app
} = require('electron');
$(document).ready(function() {
   let home = app.getPath('home');
   let homePathTemplate = document.getElementById('home');
    homePathTemplate.innerHTML(home);
});

Which looks as though it should work however receive the following error:

Uncaught TypeError: Cannot read property 'getPath' of undefined

Any ideas for a quick fix?

Edit 1

With the following

const app = require('electron');

And the same function as above I receive the following error:

Uncaught TypeError: app.getPath is not a function at HTMLDocument.

回答1:


window.$ = window.jQuery = require('jquery');
const { remote } = require('electron');
const app = remote.app;

$(document).ready(function() {
   let home = app.getPath('home');
   console.log(home)
   let homePathTemplate = document.getElementById('home');
   homePathTemplate.innerHTML(home);
});

And make sure you are enabling nodeIntegration when you are creating BrowserWindow in main process



来源:https://stackoverflow.com/questions/60444303/error-when-using-electron-app-getpathhome

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!