{"id":162869,"date":"2019-11-29T08:35:30","date_gmt":"2019-11-29T00:35:30","guid":{"rendered":"https:\/\/lrxjmw.cn\/?p=162869"},"modified":"2019-10-30T09:36:16","modified_gmt":"2019-10-30T01:36:16","slug":"linux-electron-visual","status":"publish","type":"post","link":"https:\/\/lrxjmw.cn\/linux-electron-visual.html","title":{"rendered":"\u6559\u4f60\u5982\u4f55\u5728\u4f18\u9e92\u9e9f\u4e0a\u4f7f\u7528 Electron \u5f00\u53d1\u684c\u9762\u5e94\u7528"},"content":{"rendered":"\n\n\n
\u5bfc\u8bfb<\/td>\nElectron \u662f\u7531 Github \u5f00\u53d1\uff0c\u7528 HTML\u3001CSS \u548c JavaScript \u6765\u6784\u5efa\u8de8\u5e73\u53f0\u684c\u9762\u5e94\u7528\u7a0b\u5e8f\u7684\u4e00\u4e2a\u5f00\u6e90\u5e93\u3002Electron \u901a\u8fc7\u5c06 Chromium \u548c Node.js \u5408\u5e76\u5230\u540c\u4e00\u4e2a\u8fd0\u884c\u65f6\u73af\u5883\u4e2d\uff0c\u5e76\u5c06\u5176\u6253\u5305\u4e3a Mac\u3001Windows \u548c Linux \u4e0b\u7684\u5e94\u7528\u6765\u5b9e\u73b0\u8fd9\u4e00\u76ee\u7684\u3002\u50cf\u6211\u4eec\u5927\u5bb6\u719f\u6089\u7684 Visual Studio Code \u5c31\u662f\u4f7f\u7528 Electron \u5f00\u53d1\u7684\u3002<\/strong><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n

\u4f7f\u7528 Web \u6807\u51c6\u6765\u521b\u5efa\u684c\u9762 GUI\uff0c\u4e0a\u624b\u5feb\u3001\u6210\u672c\u4f4e\u3001\u8de8\u5e73\u53f0\u3001\u81ea\u9002\u5e94\u5206\u8fa8\u7387\uff0c\u8fd9\u4e9b\u90fd\u662f Electron \u7684\u4f18\u52bf\u3002\u63a5\u4e0b\u6765\u6211\u4eec\u901a\u8fc7\u5b9e\u73b0\u4e00\u4e2a\u7b80\u5355\u7684\u6f14\u793a\u6765\u4e86\u89e3\u5728\u4f18\u9e92\u9e9f\u4e0a\u5f00\u53d1 Electron \u5e94\u7528\u7684\u6574\u4e2a\u6d41\u7a0b\u5427\uff0c\u8fd9\u4e2a\u6f14\u793a\u6211\u4eec\u5c06\u5b9e\u73b0\u4e00\u4e2a\u65e0\u7a97\u53e3\u8fb9\u6846\u7684\u684c\u9762\u5c0f\u5de5\u5177\uff0c\u4e00\u4e2a\u663e\u793a\u5f53\u524d\u65f6\u95f4\u7684\u65f6\u949f\u8868\u76d8\u3002<\/p>\n

\u5f00\u53d1\u73af\u5883\u914d\u7f6e<\/strong><\/div>\n

\u8981\u652f\u6301 Electron\uff0c\u6211\u4eec\u9700\u8981 Node.js \u8fd0\u884c\u73af\u5883\u548c\u8d77\u5305\u7ba1\u7406\u5de5\u5177 npm\uff0c\u6253\u5f00\u547d\u4ee4\u884c\u5de5\u5177\uff0c\u4f7f\u7528 apt install nodejs npm \u547d\u4ee4\u8fdb\u884c\u5b89\u88c5\uff0c\u5b89\u88c5\u5b8c\u6210\u540e\uff0c\u786e\u8ba4\u5176\u662f\u5426\u5df2\u7ecf\u5168\u5c40\u53ef\u7528\uff1a<\/p>\n

# \u4e0b\u9762\u8fd9\u884c\u7684\u547d\u4ee4\u4f1a\u6253\u5370\u51fa Node.js \u7684\u7248\u672c\u4fe1\u606f\r\nnode -v\r\n# \u4e0b\u9762\u8fd9\u884c\u7684\u547d\u4ee4\u4f1a\u6253\u5370\u51fa npm \u7684\u7248\u672c\u4fe1\u606f\r\nnpm -v<\/pre>\n

\u63a5\u4e0b\u6765\u5b89\u88c5 Electron \u4ee5\u53ca\u4e00\u4e2a\u597d\u7528\u7684\u811a\u624b\u67b6\u7a0b\u5e8f electron-forge\uff0c\u540e\u8005\u53ef\u4ee5\u8ba9\u6211\u4eec\u5feb\u901f\u6784\u5efa\u4e00\u4e2a electron \u5e94\u7528\uff1a<\/p>\n

npm install -g electron\r\nnpm install -g electron-forge<\/pre>\n

\u8fd9\u6837\u6211\u4eec\u7684\u5f00\u53d1\u73af\u5883\u5c31\u642d\u5efa\u597d\u4e86\uff0c\u4f60\u53ef\u80fd\u8fd8\u9700\u8981\u4e00\u4e2a\u597d\u7528\u7684 IDE\uff0c\u5728\u8fd9\u91cc\u6211\u63a8\u8350 vscode \u6216\u8005\u662f atom\uff0c\u4e0d\u4ec5\u597d\u7528\uff0c\u800c\u4e14\u8fd9\u4e24\u4e2a IDE \u90fd\u662f electron \u5f00\u53d1\u7684\uff0c\u5982\u679c\u4e0d\u60f3\u7528\u4e5f\u6ca1\u5173\u7cfb\uff0cvim \u5c31\u53ef\u4ee5\u3002<\/p>\n

\u521b\u5efa\u5e94\u7528\u4ee5\u53ca\u7f16\u7801<\/strong><\/div>\n

1\u3001\u9996\u5148\uff0c\u521b\u5efa\u4e00\u4e2a Electron \u9879\u76ee\uff1a<\/p>\n

electron-forge init [\u7a0b\u5e8f\u540d]<\/pre>\n

electron-forge \u4f1a\u4e3a\u6211\u4eec\u751f\u6210 packege.json \u6587\u4ef6\u4ee5\u53ca src \u76ee\u5f55\uff0c\u5e76\u5b89\u88c5\u597d\u76f8\u5173\u7684 Node.js \u4f9d\u8d56\u5e93\u3002src \u76ee\u5f55\u4e0b\u6709\u4e24\u4e2a\u6587\u4ef6 index.html \u548c index.js\uff0cindex.html \u662f\u4e00\u4e2a\u666e\u901a\u7684 HTML \u9875\u9762\uff0c\u800c index.js \u662f\u5728 package.json \u6587\u4ef6\u4e2d\u6307\u5b9a\u7684\u7a0b\u5e8f\u5165\u53e3\uff0c\u5e76\u4e14 electron-forge \u4f1a\u4e3a\u6211\u4eec\u751f\u6210\u6a21\u677f\u4ee3\u7801\u4ee5\u53ca\u76f8\u5173\u7684\u6ce8\u91ca\uff0c\u53ef\u4ee5\u6839\u636e\u6ce8\u91ca\u4e86\u89e3\u76f8\u5173\u7684\u4ee3\u7801\u4f5c\u7528\u3002<\/p>\n

\u63a5\u4e0b\u6765\uff0c\u6211\u4eec\u4f7f\u7528 HTML+CSS \u77e5\u8bc6\u753b\u4e00\u4e2a\u65f6\u949f\u8868\u76d8\uff0c\u56e0\u4e3a\u76f8\u5bf9\u672c\u6587\u7684\u5185\u5bb9\uff0c\u8fd9\u90e8\u5206\u4e0d\u662f\u5173\u952e\uff0c\u6240\u4ee5\u5728\u6b64\u5148\u7701\u7565\uff0c\u672c\u6587\u7684\u4ee3\u7801\u90fd\u4f1a\u5728\u6587\u672b\u516c\u5e03\uff0c\u4f9b\u5927\u5bb6\u53c2\u8003\u3002<\/p>\n

\u7136\u540e\uff0c\u6211\u4eec\u9700\u8981\u8ba9\u8868\u76d8\u4e0a\u7684\u6307\u9488\u52a8\u8d77\u6765\uff0c\u5728 index.html \u4e2d\u5f15\u5165 clock.js \u6587\u4ef6\uff0c\u6dfb\u52a0 JavaScript \u4ee3\u7801\u8ba9\u5176\u63a7\u5236\u6307\u9488\u7684\u8fd0\u52a8\uff0c\u4ee5\u79d2\u9488\u4e3a\u4f8b\uff1a<\/p>\n

const second = today.getSeconds();  \/\/ \u83b7\u53d6\u5f53\u524d\u65f6\u95f4\r\nconst secondDeg = ((second \/ 60) * 360) + 360; \/\/ \u8ba1\u7b97\u79d2\u9488\u8fd0\u52a8\u89d2\u5ea6\r\nsecondHand.style.transform = `rotate(${secondDeg}deg)`; \/\/ \u6dfb\u52a0 CSS \u52a8\u753b<\/pre>\n

\u6700\u540e\uff0c\u6211\u4eec\u8c03\u6574 index.js\uff0c\u8c03\u7528 new BrowserWindow() \u751f\u6210 window \u5bf9\u8c61\u7684\u65f6\u5019\uff0c\u5b83\u7684\u5bbd\u5ea6\u548c\u9ad8\u5ea6\u8981\u6839\u636e\u8868\u76d8\u7684\u5927\u5c0f\u4f5c\u76f8\u5e94\u7684\u8c03\u6574\uff0c\u5c06 transprent \u5b57\u6bb5\u8d4b\u503c\u4e3a true\u3001frame \u4e3a false\uff0c\u4f7f\u4f60\u7684\u7a0b\u5e8f\u65e0\u8fb9\u6846\u5e76\u4e14\u80cc\u666f\u4fdd\u6301\u900f\u660e\uff1b\u5e76\u4e14\u9700\u8981\u5bf9new BrowserWindow() \u7684\u64cd\u4f5c\u4f5c\u5ef6\u8fdf\u5904\u7406\uff0c\u8fd9\u6837\u4f60\u7684\u900f\u660e\u5316\u64cd\u4f5c\u624d\u4f1a\u751f\u6548\uff1a<\/p>\n

app.on('ready', () => setTimeout(createWindow, 500));<\/pre>\n
\u5e94\u7528\u8fd0\u884c\u4ee5\u53ca\u6253\u5305\u53d1\u5e03<\/strong><\/div>\n

\u7f16\u7801\u5b8c\u6210\u4e4b\u540e\uff0c\u8fd0\u884c\u5e94\u7528\u4e5f\u662f\u975e\u5e38\u7b80\u5355\uff0c\u5728\u5de5\u7a0b\u76ee\u5f55\u4e0b\u8fd0\u884c\u547d\u4ee4 electron-forge start \u5373\u53ef\u3002<\/p>\n

\u90a3\u4e48\u5982\u4f55\u5728\u4f18\u9e92\u9e9f\u4e0a\u5bf9\u5e94\u7528\u8fdb\u884c\u6253\u5305\u53d1\u5e03\u5462\uff1f\u9996\u5148\u6211\u4eec\u4fee\u6539 package.json \u6587\u4ef6\uff0c\u627e\u5230 make_targets \u5b57\u6bb5\uff0c\u5728 linux \u4e0b\uff0c\u6211\u4eec\u5220\u9664\u6389 rpm\uff0c\u56e0\u4e3a\u6211\u4eec\u7684\u4f18\u9e92\u9e9f\u91c7\u7528\u7684\u662f debian \u7684\u6253\u5305\u4f53\u7cfb\uff0c\u4e4b\u540e\u5728\u5de5\u7a0b\u76ee\u5f55\u8fd0\u884c\u547d\u4ee4 electron-forge make\uff0c\u5373\u53ef\u5b8c\u6210\u53d1\u5e03\u3002\u6ce8\u610f\u53d1\u5e03\u540e\u751f\u6210\u4e8c\u8fdb\u5236\u6587\u4ef6\u548c deb \u5305\u90fd\u5728 out \u76ee\u5f55\u4e0b\u3002\u7a0b\u5e8f\u6700\u540e\u7684\u6548\u679c\u5982\u4e0b\uff1a <\/p>\n

\"\"<\/p>\n

\u603b\u7ed3<\/strong><\/div>\n

\u4f7f\u7528 Electron \u6765\u5f00\u53d1\u684c\u9762\u7a0b\u5e8f\u662f\u4e0d\u662f\u53c8\u5feb\u53c8\u597d\u5462\uff0c\u5927\u5bb6\u53ef\u4ee5\u8bd5\u8bd5\u540c\u6837\u4e00\u4e2a\u65f6\u949f\u8868\u76d8\u684c\u9762\u5e94\u7528\uff0c\u4f7f\u7528 Gtk \u6216\u8005 Qt \u5f00\u53d1\u8981\u82b1\u591a\u5c11\u65f6\u95f4\uff0c\u624d\u80fd\u771f\u6b63\u4f53\u4f1a Electron \u5e26\u6765\u7684\u662f\u4ec0\u4e48\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"

\u4f7f\u7528 Web \u6807\u51c6\u6765\u521b\u5efa\u684c\u9762 GUI\uff0c\u4e0a\u624b\u5feb\u3001\u6210\u672c\u4f4e\u3001\u8de8\u5e73\u53f0\u3001\u81ea\u9002\u5e94\u5206\u8fa8\u7387\uff0c\u8fd9\u4e9b\u90fd\u662f Electron \u7684\u4f18\u52bf […]<\/p>\n","protected":false},"author":1482,"featured_media":144243,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[55],"tags":[],"class_list":["post-162869","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-thread"],"acf":[],"_links":{"self":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/162869","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/users\/1482"}],"replies":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/comments?post=162869"}],"version-history":[{"count":4,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/162869\/revisions"}],"predecessor-version":[{"id":162905,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/162869\/revisions\/162905"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media\/144243"}],"wp:attachment":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media?parent=162869"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/categories?post=162869"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/tags?post=162869"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}