在windows8.1,8上,需要安装 Application User Model ID.aspx) 到开始屏幕上,这不是将你的应用固定到开始屏幕。 Windows7及以下,不支持通知,可以通过 Tray API 发送一个气泡通知。 此外,通知的最大长度为250个字符,Windows团队建议通知的长度保持在200个字符。
Linux ToDo
macOS
通知在macOS上是直接转发的,你应该需要了解Apple's Human Interface guidelines regarding notifications. 注意,通知被限制在256bytes,如果超出将会被截断。
最近文档(Windows和macOS)
Windows 和 macOS 提供获取最近文档列表的便捷方式,那就是打开跳转列表或者鱼眼菜单。 增加一个文件到最近的访问文档,使用app.addRecentDocumentAPI.
在 Windows,你可以特别定义跳转列表的 Tasks 目录的行为,引用 MSDN 的文档: Applications define tasks based on both the program’s features and the key things a user is expected to do with them. Tasks should be context-free, in that the application does not need to be running for them to work. They should also be the statistically most common actions that a normal user would perform in an application, such as compose an email message or open the calendar in a mail program, create a new document in a word processor, launch an application in a certain mode, or launch one of its subcommands. An application should not clutter the menu with advanced features that standard users won’t need or one-time actions such as registration. Do not use tasks for promotional items such as upgrades or special offers. It is strongly recommended that the task list be static. It should remain the same regardless of the state or status of the application. While it is possible to vary the list dynamically, you should consider that this could confuse the user who does not expect that portion of the destination list to change.
const electron = require('electron'); // Module to control application life. const {app} = electron; // Module to create native browser window. const {BrowserWindow} = electron;
// Keep a global reference of the window object, if you don't, the window will // be closed automatically when the JavaScript object is garbage collected. let win;
function createWindow() { // Create the browser window. win = new BrowserWindow({width: 800, height: 600});
// and load the index.html of the app. win.loadURL(`file://${__dirname}/index.html`);
// Open the DevTools. win.webContents.openDevTools();
// Emitted when the window is closed. win.on('closed', () => { // Dereference the window object, usually you would store windows // in an array if your app supports multi windows, this is the time // when you should delete the corresponding element. win = null; }); }
// This method will be called when Electron has finished // initialization and is ready to create browser windows. // Some APIs can only be used after this event occurs. app.on('ready', createWindow);
// Quit when all windows are closed. app.on('window-all-closed', () => { // On macOS it is common for applications and their menu bar // to stay active until the user quits explicitly with Cmd + Q if (process.platform !== 'darwin') { app.quit(); } });
app.on('activate', () => { // On macOS it's common to re-create a window in the app when the // dock icon is clicked and there are no other windows open. if (win === null) { createWindow(); } });
// In this file you can include the rest of your app's specific main process // code. You can also put them in separate files and require them here.
最后,你想展示的index.html:
1 2 3 4 5 6 7 8 9 10 11 12 13
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Hello World!</title> </head> <body> <h1>Hello World!</h1> We are using node <script>document.write(process.versions.node)</script>, Chrome <script>document.write(process.versions.chrome)</script>, and Electron <script>document.write(process.versions.electron)</script>. </body> </html>
// webpack.config.js var ExtractTextPlugin = require("extract-text-webpack-plugin"); module.exports = { // The standard entry point and output config entry: { posts: "./posts", post: "./post", about: "./about" }, output: { filename: "[name].js", chunkFilename: "[id].js" }, module: { loaders: [ // Extract css files { test: /\.css$/, loader: ExtractTextPlugin.extract("style-loader", "css-loader") }, // Optionally extract less files // or any other compile-to-css language { test: /\.less$/, loader: ExtractTextPlugin.extract("style-loader", "css-loader!less-loader") } // You could also use other loaders the same way. I. e. the autoprefixer-loader ] }, // Use the plugin to specify the resulting filename (and add needed behavior to the compiler) plugins: [ new ExtractTextPlugin("[name].css") ] }
Webpack不支持ES6模块,直接使用require.ensure或者require取决于设计哪个模块组成你的 编译. Webpack1.x.x(2.0即将来临)原生的不支持ES6模块,但是你可以通过转换器解决他,比如使用Babel 转换ES6的import语法为CommonJs或者AMD模块,这种途径是有效的,但是当动态加载时会有警告。 这种模块添加方式import x from 'foo'是故意设计为静态分析的,意味着你不能用于动态导入
1 2
// INVALID!!!!!!!!! ['lodash', 'backbone'].forEach(name => import name )
id 定义模块的名称,可选择的 dependencies 指定定义该模块需要依赖其余的哪些模块,是一个模块标识的数组,缺省时默认值是 [“require”, “exports”, “module”]. factory 最后的这个参数就是谁定义了这个模块,它可以是一个对象也可以是一个函数(只调用一次),如果是函数 的话,函数的返回值就是模块暴露出去的值。
例子
定义一个叫myModule并且依赖jQuery的模块
1 2 3 4 5 6
define('myModule', ['jquery'], function($) { // $ is the export of the jquery module. $('body').text('hello world'); }); // and use it require(['myModule'], function(myModule) {});