liuyuqi-dellpc 6 years ago
parent
commit
f4352cc9fa
6 changed files with 120 additions and 1 deletions
  1. 1 1
      LICENSE
  2. 23 0
      package.json
  3. 20 0
      src/index.html
  4. 12 0
      src/js/preload.js
  5. 7 0
      src/js/renderer.js
  6. 57 0
      src/main.js

+ 1 - 1
LICENSE

@@ -1,5 +1,5 @@
 MIT License
-Copyright (c) <year> <copyright holders>
+Copyright (c) <2020> <liuyuqi.gov@msn.cn>
 
 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
 

+ 23 - 0
package.json

@@ -0,0 +1,23 @@
+{
+  "name": "folder-server",
+  "version": "1.0.0",
+  "description": "ss",
+  "main": "src/main.js",
+  "scripts": {
+    "start": "node .",
+    "test": "node test"
+  },
+  "repository": {
+    "type": "git",
+    "url": "https://git.yoqi.me/lyq/folder-server.git"
+  },
+  "keywords": [
+    "server",
+    "node"
+  ],
+  "devDependencies": {
+    "electron": "^5.0.7"
+  },
+  "author": "liuyuqi.gov@msn.cn",
+  "license": "MIT"
+}

+ 20 - 0
src/index.html

@@ -0,0 +1,20 @@
+<!DOCTYPE html>
+<html>
+
+<head>
+  <meta charset="UTF-8">
+  <title>Hello World!</title>
+</head>
+
+<body>
+  <h1>Hello World!</h1>
+  We are using Node.js <span id="node-version"></span>,
+  Chromium <span id="chrome-version"></span>,
+  and Electron <span id="electron-version"></span>.
+  <a href="#" id="drag">item</a>
+
+  <!-- You can also require other files to run in this process -->
+  <script src="./js/renderer.js"></script>
+</body>
+
+</html>

+ 12 - 0
src/js/preload.js

@@ -0,0 +1,12 @@
+// All of the Node.js APIs are available in the preload process.
+// It has the same sandbox as a Chrome extension.
+window.addEventListener('DOMContentLoaded', () => {
+  const replaceText = (selector, text) => {
+    const element = document.getElementById(selector)
+    if (element) element.innerText = text
+  } 
+  
+  for (const type of ['chrome', 'node', 'electron']) {
+    replaceText(`${type}-version`, process.versions[type])
+  }
+})

+ 7 - 0
src/js/renderer.js

@@ -0,0 +1,7 @@
+document.getElementById('drag').ondragstart = (event) => {
+    event.preventDefault()
+    ipcRenderer.send('ondragstart', '/path/to/item')
+}
+
+const { ipcMain } = require('electron')
+

+ 57 - 0
src/main.js

@@ -0,0 +1,57 @@
+const { app, BrowserWindow } = require('electron')
+const path = require('path')
+
+// 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 mainWindow
+
+function createWindow() {
+    mainWindow = new BrowserWindow({
+        width: 800,
+        height: 600,
+        webPreferences: {
+            preload: path.join(__dirname, 'js/preload.js')
+        }
+    })
+
+    // and load the index.html of the app.
+    mainWindow.loadFile('index.html')
+
+    // Open the DevTools.
+    // mainWindow.webContents.openDevTools()
+
+    // Emitted when the window is closed.
+    mainWindow.on('closed', function () {
+        // 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.
+        mainWindow = 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', function () {
+    // 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', function () {
+    // 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 (mainWindow === 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.
+ipcMain.on('ondragstart', (event, filePath) => {
+    event.sender.startDrag({
+        file: filePath,
+        icon: '/path/to/icon.png'
+    })
+})