feat: add electron app.
2
electron/app/.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
dist
|
||||
website
|
||||
8
electron/app/assets/entitlements.mac.plist
Normal file
@@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>com.apple.security.cs.allow-unsigned-executable-memory</key>
|
||||
<true/>
|
||||
</dict>
|
||||
</plist>
|
||||
35
electron/app/config.json
Normal file
@@ -0,0 +1,35 @@
|
||||
{
|
||||
"productName": "wxmp",
|
||||
"appId": "com.wangchujiang.wxmp",
|
||||
"asar": true,
|
||||
"directories": {
|
||||
"output": "dist"
|
||||
},
|
||||
"mac": {
|
||||
"icon": "tools.icns",
|
||||
"target": {
|
||||
"target": "default",
|
||||
"arch": ["arm64", "x64"]
|
||||
},
|
||||
"category": "public.app-category.developer-tools",
|
||||
"type": "distribution",
|
||||
"entitlements": "assets/entitlements.mac.plist",
|
||||
"entitlementsInherit": "assets/entitlements.mac.plist"
|
||||
},
|
||||
"linux": {
|
||||
"icon": "tools.icns",
|
||||
"description": "微信公众号 Markdown 编辑器",
|
||||
"category": "Development",
|
||||
"target": ["deb", "rpm"],
|
||||
"desktop": {
|
||||
"Name": "Web Tools"
|
||||
}
|
||||
},
|
||||
"win": {
|
||||
"icon": "tools.ico",
|
||||
"target": {
|
||||
"target": "nsis",
|
||||
"arch": ["x64", "ia32"]
|
||||
}
|
||||
}
|
||||
}
|
||||
BIN
electron/app/icon.icns
Normal file
BIN
electron/app/icons.iconset/icon_128x128.png
Normal file
|
After Width: | Height: | Size: 12 KiB |
BIN
electron/app/icons.iconset/icon_128x128@2x.png
Normal file
|
After Width: | Height: | Size: 30 KiB |
BIN
electron/app/icons.iconset/icon_16x16.png
Normal file
|
After Width: | Height: | Size: 1.3 KiB |
BIN
electron/app/icons.iconset/icon_16x16@2x.png
Normal file
|
After Width: | Height: | Size: 2.4 KiB |
BIN
electron/app/icons.iconset/icon_256x256.png
Normal file
|
After Width: | Height: | Size: 30 KiB |
BIN
electron/app/icons.iconset/icon_256x256@2x.png
Normal file
|
After Width: | Height: | Size: 82 KiB |
BIN
electron/app/icons.iconset/icon_32x32.png
Normal file
|
After Width: | Height: | Size: 2.4 KiB |
BIN
electron/app/icons.iconset/icon_32x32@2x.png
Normal file
|
After Width: | Height: | Size: 5.2 KiB |
BIN
electron/app/icons.iconset/icon_512x512.png
Normal file
|
After Width: | Height: | Size: 82 KiB |
BIN
electron/app/icons.iconset/icon_512x512@2x.png
Normal file
|
After Width: | Height: | Size: 275 KiB |
BIN
electron/app/logo.png
Normal file
|
After Width: | Height: | Size: 82 KiB |
15
electron/app/main.js
Normal file
@@ -0,0 +1,15 @@
|
||||
const path = require('path');
|
||||
const { App } = require('@wcj/wxmp-main');
|
||||
|
||||
(async () => {
|
||||
const options = {};
|
||||
if (process.env.NODE_ENV === 'development') {
|
||||
options.preload = require.resolve('@wcj/wxmp-preload');
|
||||
options.webpath = require.resolve('website/build/index.html');
|
||||
} else {
|
||||
options.preload = path.resolve(__dirname, 'website/index.js');
|
||||
options.webpath = 'website/index.html';
|
||||
}
|
||||
const app = new App();
|
||||
await app.createWindow(options);
|
||||
})();
|
||||
30
electron/app/package.json
Normal file
@@ -0,0 +1,30 @@
|
||||
{
|
||||
"name": "wxmp",
|
||||
"description": "微信公众号 Markdown 编辑器",
|
||||
"homepage": "https://github.com/jaywcjlove/wxmp.git",
|
||||
"version": "2.1.0",
|
||||
"main": "main.js",
|
||||
"author": "Kenny Wong <398188662@qq.com>",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"deps": "electron-builder install-app-deps",
|
||||
"start": "cross-env NODE_ENV=development ELECTRON_DISABLE_SECURITY_WARNINGS=true electron .",
|
||||
"start:production": "cross-env NODE_ENV=production ELECTRON_DISABLE_SECURITY_WARNINGS=true electron .",
|
||||
"dist-win32": "electron-builder --win --ia32 --config config.json",
|
||||
"dist-win64": "electron-builder --win --x64 --config config.json",
|
||||
"dist-mac": "electron-builder --mac --universal --config config.json",
|
||||
"dist-linux": "electron-builder --linux --config config.json",
|
||||
"copy": "cpy './node_modules/@wcj/wxmp-preload/lib/*.js' './node_modules/website/build/**' website",
|
||||
"build": "npm run copy && cross-env NODE_ENV=production electron-builder build --publish=never --config config.json"
|
||||
},
|
||||
"dependencies": {
|
||||
"@wcj/wxmp-main": "2.1.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@wcj/wxmp-preload": "2.1.0",
|
||||
"cpy-cli": "4.1.0",
|
||||
"electron": "19.0.5",
|
||||
"electron-builder": "23.1.0",
|
||||
"website": "2.1.0"
|
||||
}
|
||||
}
|
||||
1
electron/main/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
lib
|
||||
16
electron/main/package.json
Normal file
@@ -0,0 +1,16 @@
|
||||
{
|
||||
"name": "@wcj/wxmp-main",
|
||||
"version": "2.1.0",
|
||||
"main": "./lib/index.js",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"build": "tsbb build --disable-babel --file-names src/index.ts",
|
||||
"watch": "tsbb watch --disable-babel --file-names src/index.ts"
|
||||
},
|
||||
"files": [
|
||||
"lib"
|
||||
],
|
||||
"devDependencies": {
|
||||
"electron": "19.0.5"
|
||||
}
|
||||
}
|
||||
56
electron/main/src/Menu.ts
Normal file
@@ -0,0 +1,56 @@
|
||||
import { app, Menu, MenuItem, MenuItemConstructorOptions } from 'electron';
|
||||
const isMac = process.platform === 'darwin';
|
||||
const template = [
|
||||
// { role: 'appMenu' }
|
||||
...(isMac
|
||||
? [
|
||||
{
|
||||
label: app.name,
|
||||
submenu: [
|
||||
{ role: 'about' },
|
||||
{ type: 'separator' },
|
||||
{ role: 'services' },
|
||||
{ type: 'separator' },
|
||||
{ role: 'hide' },
|
||||
{ role: 'hideOthers' },
|
||||
{ role: 'unhide' },
|
||||
{ type: 'separator' },
|
||||
{ role: 'quit' },
|
||||
],
|
||||
},
|
||||
]
|
||||
: []),
|
||||
{ role: 'editMenu' },
|
||||
{
|
||||
label: 'Window',
|
||||
submenu: [
|
||||
{ role: 'minimize' },
|
||||
{ role: 'zoom' },
|
||||
...(isMac
|
||||
? [{ type: 'separator' }, { role: 'front' }, { type: 'separator' }, { role: 'window' }]
|
||||
: [{ role: 'close' }]),
|
||||
],
|
||||
},
|
||||
{
|
||||
role: 'help',
|
||||
submenu: [
|
||||
{
|
||||
label: 'Open Source for Github',
|
||||
click: async () => {
|
||||
const { shell } = require('electron');
|
||||
await shell.openExternal('https://github.com/jaywcjlove/wxmp');
|
||||
},
|
||||
},
|
||||
{
|
||||
label: 'Online Website',
|
||||
click: async () => {
|
||||
const { shell } = require('electron');
|
||||
await shell.openExternal('https://jaywcjlove.github.io/wxmp');
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
];
|
||||
|
||||
const menu = Menu.buildFromTemplate(template as Array<MenuItem | MenuItemConstructorOptions>);
|
||||
Menu.setApplicationMenu(menu);
|
||||
60
electron/main/src/app.ts
Normal file
@@ -0,0 +1,60 @@
|
||||
import { app, shell, BrowserWindow } from 'electron';
|
||||
import './Menu';
|
||||
|
||||
export interface Options extends Electron.BrowserWindowConstructorOptions {
|
||||
preload?: string;
|
||||
webpath?: string;
|
||||
}
|
||||
|
||||
export class App {
|
||||
app = app;
|
||||
win?: BrowserWindow;
|
||||
isLogin: boolean = false;
|
||||
/** 创建主进程窗口 */
|
||||
async createWindow(options: Options = {}, loadURL?: string) {
|
||||
await app.whenReady();
|
||||
const opts: Options = {
|
||||
titleBarStyle: 'hidden', // 无标题栏
|
||||
frame: false, // 创建无边窗口
|
||||
width: 800,
|
||||
height: 600,
|
||||
minWidth: 850,
|
||||
center: true,
|
||||
maximizable: true,
|
||||
minimizable: true,
|
||||
resizable: true,
|
||||
webPreferences: {
|
||||
// 多线程
|
||||
nodeIntegrationInWorker: true,
|
||||
nodeIntegration: true,
|
||||
contextIsolation: false,
|
||||
},
|
||||
...options,
|
||||
};
|
||||
if (options.preload) {
|
||||
opts.webPreferences.preload = options.preload;
|
||||
}
|
||||
|
||||
this.win = new BrowserWindow(opts);
|
||||
if (process.env.NODE_ENV === 'development') {
|
||||
this.win.loadURL(loadURL || 'http://localhost:3000/');
|
||||
// 打开开发者工具,默认不打开
|
||||
this.win.webContents.openDevTools();
|
||||
} else {
|
||||
this.win.loadFile(options.webpath);
|
||||
}
|
||||
this.win.webContents.setWindowOpenHandler(({ url }) => {
|
||||
if (/^https?:\/\//.test(url)) {
|
||||
shell.openExternal(url);
|
||||
return { action: 'deny' };
|
||||
}
|
||||
return {
|
||||
action: 'allow',
|
||||
overrideBrowserWindowOptions: {
|
||||
modal: true,
|
||||
},
|
||||
};
|
||||
});
|
||||
return this.win;
|
||||
}
|
||||
}
|
||||
1
electron/main/src/index.ts
Normal file
@@ -0,0 +1 @@
|
||||
export * from './app';
|
||||
19
electron/main/tsconfig.json
Normal file
@@ -0,0 +1,19 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"esModuleInterop": true,
|
||||
"declaration": true,
|
||||
"target": "es2017",
|
||||
"noImplicitAny": true,
|
||||
"resolveJsonModule": true,
|
||||
"moduleResolution": "node",
|
||||
"emitDecoratorMetadata": true,
|
||||
"experimentalDecorators": true,
|
||||
"sourceMap": false,
|
||||
"strict": false,
|
||||
"skipLibCheck": true,
|
||||
"outDir": "lib",
|
||||
"baseUrl": "."
|
||||
},
|
||||
"include": ["src"]
|
||||
}
|
||||
1
electron/preload/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
lib
|
||||
16
electron/preload/package.json
Normal file
@@ -0,0 +1,16 @@
|
||||
{
|
||||
"name": "@wcj/wxmp-preload",
|
||||
"version": "2.1.0",
|
||||
"main": "./lib/index.js",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"build": "tsbb build --disable-babel --file-names src/index.ts",
|
||||
"watch": "tsbb watch --disable-babel --file-names src/index.ts"
|
||||
},
|
||||
"files": [
|
||||
"lib"
|
||||
],
|
||||
"devDependencies": {
|
||||
"electron": "19.0.5"
|
||||
}
|
||||
}
|
||||
24
electron/preload/src/index.ts
Normal file
@@ -0,0 +1,24 @@
|
||||
const styleStr = `.siderbar {
|
||||
-webkit-app-region: drag;
|
||||
}
|
||||
.siderbar header h1 a, github-corners {
|
||||
display: none;
|
||||
}
|
||||
article.content:before {
|
||||
-webkit-app-region: drag;
|
||||
position: absolute;
|
||||
content: ' ';
|
||||
display: block;
|
||||
height: 41px;
|
||||
width: 100%;
|
||||
z-index: -1;
|
||||
}`;
|
||||
|
||||
document.addEventListener('DOMContentLoaded', () => {
|
||||
const head = document.querySelector('head');
|
||||
const style = document.createElement('style');
|
||||
style.textContent = styleStr;
|
||||
if (head) {
|
||||
head.append(style);
|
||||
}
|
||||
});
|
||||
27
electron/preload/tsconfig.json
Normal file
@@ -0,0 +1,27 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"esModuleInterop": true,
|
||||
"declaration": true,
|
||||
"target": "es5",
|
||||
"lib": ["dom", "dom.iterable", "esnext"],
|
||||
"allowJs": true,
|
||||
"skipLibCheck": true,
|
||||
"sourceMap": false,
|
||||
"noImplicitAny": true,
|
||||
"resolveJsonModule": true,
|
||||
"moduleResolution": "node",
|
||||
"emitDecoratorMetadata": true,
|
||||
"experimentalDecorators": true,
|
||||
"allowSyntheticDefaultImports": true,
|
||||
"strict": true,
|
||||
"outDir": "lib",
|
||||
"baseUrl": "."
|
||||
// "esModuleInterop": true,
|
||||
// "allowSyntheticDefaultImports": true,
|
||||
// "forceConsistentCasingInFileNames": true,
|
||||
// "noFallthroughCasesInSwitch": true,
|
||||
// "isolatedModules": false,
|
||||
},
|
||||
"include": ["src"]
|
||||
}
|
||||