Repository: jamasBian/youdao-note-electron Branch: master Commit: b96eca3e0114 Files: 13 Total size: 9.6 KB Directory structure: gitextract_rjqey3vm/ ├── .gitignore ├── LICENSE.md ├── README.md ├── assets/ │ └── icon.icns ├── index.html ├── main.js ├── package.json ├── scripts/ │ ├── build-all.sh │ ├── build-win32.bat │ ├── build.sh │ └── tar-all.sh ├── style.css └── ynote.js ================================================ FILE CONTENTS ================================================ ================================================ FILE: .gitignore ================================================ dist/* node_modules/* ================================================ FILE: LICENSE.md ================================================ The MIT License (MIT) Copyright (c) 2016 Zhongyi Tong 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: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ================================================ FILE: README.md ================================================ # youdao-note-electron(有道云笔记Linux版) Mac OS X 和 Linux 下更好用的有道云笔记客户端。使用Electron构建。logo ## 下载已经打包好的应用 [有道云笔记-Electron Linux 64位版本](https://github.com/jamasBian/youdao-note-electron/releases/download/1.1.1/Youdao-Note-Electron-linux-x64.zip) [有道云笔记-Electron MacOSX 版本](https://github.com/jamasBian/youdao-note-electron/releases/download/1.1.1/Youdao-Note-Electron-darwin-x64.zip) ## 如何使用: ```bash # Clone this repository git clone https://github.com/jamasBian/youdao-note-electron.git # Go into the repository cd youdao-note-electron # Install dependencies and run the app npm install -g cnpm --registry=https://registry.npm.taobao.org cnpm install cp ./assets/icon.png ./node_modules/_electron@4.1.1@electron/dist/resources/ npm start ``` ## 根据你的平台打包应用 ``` shell npm run build:osx npm run build:linux npm run build:win ``` ## 解决图标的问题。 cp ./assets/icon.png ./node_modules/_electron@4.1.1@electron/dist/resources/ #### License [CC0 (Public Domain)](LICENSE.md) ================================================ FILE: index.html ================================================ 有道云笔记 ================================================ FILE: main.js ================================================ 'use strict'; const electron = require('electron'); // Module to control application life. const app = electron.app; // Module to create native browser window. const BrowserWindow = electron.BrowserWindow; // 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 () { // Create the browser window. const path = require('path'); const imgPath = path.join(process.resourcesPath, '/icon.png') mainWindow = new BrowserWindow({icon: imgPath}); // and load the index.html of the app. mainWindow.loadURL('file://' + __dirname + '/index.html'); mainWindow.setIcon(imgPath); mainWindow.maximize(); //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. app.on('ready', createWindow); // Quit when all windows are closed. app.on('window-all-closed', function () { // On OS X 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 OS X 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(); } }); ================================================ FILE: package.json ================================================ { "name": "Youdao-Note-Electron", "version": "1.0.0", "description": "An Electron application for Youdao-Note", "main": "main.js", "scripts": { "start": "electron main.js", "build": "./scripts/build-all.sh", "build:osx": "./scripts/build.sh darwin x64", "build:osx64": "./scripts/build.sh darwin x64", "build:linux32": "./scripts/build.sh linux ia32", "build:linux": "./scripts/build.sh linux x64", "build:linux64": "./scripts/build.sh linux x64", "build:win": ".\\scripts\\build-win32.bat win32 ia32", "build:win32": ".\\scripts\\build-win32.bat win32 ia32", "build:win64": ".\\scripts\\build-win32.bat win32 x64" }, "repository": { "type": "git", "url": "git+https://github.com/jamasBian/youdao-note-electron.git" }, "keywords": [ "Youdao", "Note", "有道云笔记", "Web" ], "author": "Zhiqiang Bian", "license": "MIT", "bugs": { "url": "https://github.com/jamasBian/youdao-note-electron/issues" }, "homepage": "https://github.com/jamasBian/youdao-note-electron", "dependencies": { "electron": "4.1.1", "electron-packager": "13.0.1" } } ================================================ FILE: scripts/build-all.sh ================================================ #!/bin/bash if ! hash electron-packager 2>/dev/null; then RED='\033[0;31m' NC='\033[0m' echo "${RED}Error${NC}: you need to npm install electron-packager. Aborting." exit 1 fi function build() { ./scripts/build.sh $@ } build darwin x64 build linux ia32 build linux x64 build win32 ia32 build win32 x64 ================================================ FILE: scripts/build-win32.bat ================================================ set PLATFORM=%1% set ARCH=%2% set APP_NAME="Youdao-Note-Electron" set ignore_list="dist|scripts|\.idea|.*\.md|.*\.yml|node_modules/nodejieba" electron-packager . "%APP_NAME%" --platform=%PLATFORM% --arch=%ARCH% --electronVersion=1.4.15 --app-version=1.4.0 --asar --icon=assets\icon.png --overwrite --out=.\dist --ignore=%ignore_list% ================================================ FILE: scripts/build.sh ================================================ #!/bin/bash if ! hash electron-packager 2>/dev/null; then RED='\033[0;31m' NC='\033[0m' echo "${RED}Error${NC}: you need to npm install electron-packager. Aborting." exit 1 fi if [ "$#" -ne 2 ]; then echo -e "Usage: ./script/build.sh " echo -e " platform: darwin, linux, win32" echo -e " arch: ia32, x64" exit 1 fi PLATFORM=$1 ARCH=$2 echo "Start packaging for $PLATFORM $ARCH." if [ $PLATFORM = "linux" ]; then APP_NAME="Youdao-Note-Electron" else APP_NAME="Youdao-Note-Electron" fi if [ $PLATFORM = "darwin" ]; then ICON=icon.icns else ICON=icon.png fi ignore_list="dist|scripts|\.idea|.*\.md|.*\.yml|node_modules/nodejieba" cp assets/$ICON node_modules/electron/dist/resources/$ICON electron-packager . "${APP_NAME}" --platform=$PLATFORM --arch=$ARCH --electronVersion=4.1.1 --app-version=1.1.0 --asar --icon=assets/$ICON --overwrite --out=./dist --ignore=${ignore_list} if [ $PLATFORM = "darwin" ]; then cp assets/$ICON dist/${APP_NAME}-$PLATFORM-$ARCH/$APP_NAME.app/Contents/Resources/ else cp assets/$ICON dist/${APP_NAME}-$PLATFORM-$ARCH/resources/ fi if [ $? -eq 0 ]; then echo -e "$(tput setaf 2)Packaging for $PLATFORM $ARCH succeeded.$(tput sgr0)\n" fi ================================================ FILE: scripts/tar-all.sh ================================================ #!/bin/bash APP_NAME="Youdao-Note-Electron" cd dist echo 'Start compressing for Linux x64.' tar zcf "$APP_NAME-linux-x64.tar.gz" "$APP_NAME-linux-x64" echo 'Compressing for Linux x64 succeed.' echo 'Start compressing for Linux ia32.' tar zcf $APP_NAME-linux-ia32.tar.gz $APP_NAME-linux-ia32 echo 'Compressing for Linux ia32 succeed.' echo 'Start compressing for MAC OSX.' zip -r -q $APP_NAME-darwin-x64.zip $APP_NAME-darwin-x64 echo 'Compressing for MAC OSX succeed.' echo 'Start compressing for Windows 64-bit.' zip -r -q $APP_NAME-win32-x64.zip $APP_NAME-win32-x64 echo 'Compressing for Windows 64-bit succeed.' echo 'Start compressing for Windows 32-bit.' zip -r -q $APP_NAME-win32-ia32.zip $APP_NAME-win32-ia32 echo 'Compressing for Windows 32-bit succeed.' cd .. ================================================ FILE: style.css ================================================ html, body, #webview { width: 100%; height: 100%; margin: 0; padding: 0; overflow-y: hidden; } html::-webkit-scrollbar { width: 0 !important; } ================================================ FILE: ynote.js ================================================ const shell = require('electron').shell; const injectCSS = `div#layout-main{width:100%;flex:0 1 auto;height:100%} div#layout-container{width:100%;height:100%} div#body{height:100%}`; function getParameterByName(url, name) { name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]"); var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"), results = regex.exec(url); return results === null ? "" : decodeURIComponent(results[1].replace(/\+/g, " ")); } newWindow =function (e) { e.defaultPrevented = true; var url = getParameterByName(e.url, 'requrl'); if (url.length > 1) { //shell.openExternal(url); if(url.indexOf("succ.html")>=0) webview.loadURL("https://note.youdao.com/web/") else webview.loadURL(url); } else { //shell.openExternal(e.url); if(e.url.indexOf("succ.html")>=0) webview.loadURL("https://note.youdao.com/web/") else webview.loadURL(e.url); } }; checkUrl =function (e) { console.log(e.url) if(e.url.indexOf("succ.html")>=0) webview.loadURL("https://note.youdao.com/web/") }; onload = function () { var webview = document.getElementById("webview"); webview.addEventListener('dom-ready', function () { // overwrite css style. make it fullscreen. console.log(webview); const path = require('path'); const imgPath = path.join(process.resourcesPath, '/icon.png') console.log(imgPath); webview.insertCSS(injectCSS); // inject js to trigger if there is new message in. // webview.executeJavaScript('injectJS.getBadge()'); webview.addEventListener('new-window', newWindow); webview.addEventListener('did-navigate', checkUrl); }); };