簡體   English   中英

在創建electronjs自動啟動應用程序時遇到問題

[英]Getting issues while creating electronjs auto-launch app

npm init
npm install electron-prebuilt --save-dev
Create index.js
npm install electron-packager --save-dev
npm run build OR electron-packager . --all

我過去使用這些步驟創建了一個electronjs應用程序,並將其可執行文件放在start文件夾中,以便在系統啟動時運行它。 但是,發布Windows更新時,我在tabmode中運行應用程序時會出現一些問題。 所以,我計划創建一個新的應用程序,但是,這些命令並不完美。 我遇到了問題。

所以,我想要做的就是:創建一個auto-launch electron app 任何人都可以向我提供正確的步驟,因為我在提供的步驟中出錯了嗎?

先感謝您。

創建電子應用程序的步驟

命令:

npm install electron-prebuilt -g

電子項目需要三個文件:

  • index.html:默認呈現的網頁。
  • main.js:啟動應用程序並創建一個瀏覽器窗口來呈現HTML。
  • package.json:列出所需的應用程序依賴項,元數據和文件。

package.json並添加以下內容:

{
  "name": "hero-browser",
  "version": "0.1.0",
  "main": "main.js",
  "dependencies": {
    "dotenv": "^2.0.0",
    "md5": "^2.1.0"
  }
}

'use strict';

const electron = require('electron');
const app = electron.app;  // Module to control application life.
const BrowserWindow = electron.BrowserWindow;  // Module to create native browser window.
var mainWindow = null;

app.on('window-all-closed', function() {
    if (process.platform != 'darwin') {
        app.quit();
    }
});


app.on('ready', function() {
  mainWindow = new BrowserWindow({width: 800, height: 600});
  mainWindow.loadURL('file://' + __dirname + '/app/index.html');

  mainWindow.on('closed', function() {
    mainWindow = null;
  });
});

應用程序/ index.html的

<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>Marvel Super Hero Browser</title>
    <link href="css/index.css" rel="stylesheet" type="text/css"/>
</head>
<body>
    <h1>Marvel Super Hero Browser</h1>
    <em>Thanks to Marvel for their API.</em>

    <div id="character_list"></div>

    <script src="js/index.js"></script>
</body>
</html>

pp / css / index.css並添加一些基本的CSS以幫助布局。

#character_list .character img {
    width: 100px;
}

.character {
    float: left;
    padding: 25px;
    max-width: 100px;
}

應用程序/ JS / index.js。

這將是大多數應用程序功能發生的地方。 首先設置所需的依賴項和變量:

'use strict';

require('dotenv').config();
var md5 = require('md5');
var publicKey = process.env.MARVEL_PUBLIC_KEY;
var privateKey = process.env.MARVEL_PRIVATE_KEY;
var ts = String(new Date().getTime());
var hash = md5(ts+privateKey+publicKey);

var url = `https://gateway.marvel.com/v1/public/characters?ts=${ts}&apikey=${publicKey}&hash=${hash}&limit=25`;

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM