0
所以這可能是一個簡單的修復,但我一直在研究,並沒有找到解決辦法。我認爲電子默認是這樣做的。在我的Electron
應用程序中,我使用remote
api從renderer
進程調用對話框。一切正常,除此之外,我的對話框不會阻止用戶與BrowserWindow
的其餘部分進行交互。我的兩個功能如下電子對話框不阻止與頁面的交互
// function for saving a gantt project projects are serialized into a JSON file
// the JSON is then stringified for human readiblity then thru the dialog api is saved to
// users computer
const saveGantt =() => {
let content = gantt.serialize();
content = JSON.stringify(content, null, '\t');
dialog.showSaveDialog(
{
defaultPath: `C:\\Users\\${process.env.USERNAME}\\Documents\\`,
filters: [
{
name: 'json',
extensions: ['json'],
},
],
},
(filename) => {
if (filename === undefined) {
return;
}
fs.writeFile(filename, content, (err) => {
if (err) {
dialog.showErrorBox(
'Save Failed',
`An error occured saving the file ${err.message}`,
);
return;
}
dialog.showMessageBox({
type: 'none',
title: 'Ganttron',
message: 'The chart was successfully saved',
buttons: ['OK'],
});
});
},
);
};
// function that loads a gantt project uses the dialog api to open a JSON file from
// the users computer then it is parsed to return a JSON object that is then parsed by
// the gantt api
const loadGantt =() => {
dialog.showMessageBox(
{
type: 'none',
title: 'Ganttron',
message: 'This will clear the gantt chart and load new data',
buttons: ['Cancel', 'OK'],
},
(response) => {
if (response === 1) {
gantt.clearAll();
dialog.showOpenDialog(
{
defaultPath: `C:\\Users\\${process.env.USERNAME}\\Documents`,
filters: [
{
name: 'json',
extensions: ['json'],
},
],
},
(fileName) => {
if (fileName === undefined) {
return;
}
fs.readFile(fileName[0], 'utf-8', (err, data) => {
quickSaveFileName = fileName[0].toString();
if (err) {
dialog.showErrorBox(
'Load Failed',
`Cannot read file ${err.message}`,
);
}
const loadedData = JSON.parse(data);
gantt.parse(loadedData);
});
},
);
}
},
);
};
我正在通過回調函數和兩個函數。我知道如果你不傳遞迴調,它會阻止進程,但不會阻止用戶在對話框外進行交互。我是否錯過了一些簡單的東西,或者這是否會被黑入電子?