2
respostas

Electron

Estou criando uma aplicação que inicialmente crie e salve arquivos, quando rodo a aplicação o devtools retorna essa mensagem:

Electron Security Warning (Insecure Content-Security-Policy) This renderer process has either no Content Security
  Policy set or a policy with "unsafe-eval" enabled. This exposes users of
  this app to unnecessary security risks.

For more information and help, consult
https://electronjs.org/docs/tutorial/security.
This warning will not show up
once the app is packaged

E o console retorna essa mensgem:

[1202/142527.217:ERROR:registration_protocol_win.cc(106)] CreateFile: O sistema nÒo pode encontrar o arquivo especificado. (0x2)
[1202/142527.289:ERROR:registration_protocol_win.cc(106)] CreateFile: O sistema nÒo pode encontrar o arquivo especificado. (0x2)

Não consigo criar um arquivo na minha aplicação, agradecço desde ja.

2 respostas

main.js

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

//janela principal
var mainWindow = null
async function createWindow(){
    mainWindow = new BrowserWindow({
      width: 800,
      height: 600,
      webPreferences: {
        nodeIntegration:true,
        contextIsolation:false,
      }
    })
    await mainWindow.loadFile('src/editor/index.html')  

    mainWindow.webContents.openDevTools()
}

//arquivo
var file = {}

//criar arquivo
function createNewFile(){
  file = {
    name: 'novo-arquivo.txt',
    content: '',
    saved: false,
    path: app.getPath('documents') + '/novo-arquvivo.txt'
  }
  mainWindow.webContents.send('set-file', file)
}

//template menu
const templateMenu = [
  {
    label: 'Arquivo',
    submenu: [
      {
        label: 'Novo',
        click(){
          createNewFile()
        }
      },
      {
        label: 'Abrir'
      },
      {
        label: 'Salvar'
      },
      {
        label: 'Salvar como'
      },
      {
        label: 'Fechar',
        role:process.platform === 'darwin' ? 'close' : 'quit'
      }

    ]
  }
]

//criando menu
const menu = Menu.buildFromTemplate(templateMenu)
Menu.setApplicationMenu(menu)

//on ready
app.whenReady().then(createWindow)

//activate
app.on('activate', () => {
  if(BrowserWindow.getAllWindows().lenght === 0){
    createWindow()
  }
})
O post foi fechado pois este curso foi descontinuado e não faz mais parte da grade oficial. Bons Estudos!

Quer mergulhar em tecnologia e aprendizagem?

Receba a newsletter que o nosso CEO escreve pessoalmente, com insights do mercado de trabalho, ciência e desenvolvimento de software