OSDN Git Service

66132d89d6e7f4273bf63100afc95bef2cc7d803
[commentgenerator-electron/CommentGenerator-Electron.git] / src / main.js
1 /* #Node.js */
2 //アプリケーションを制御し、ネイティブなブラウザウィンドウを作成するモジュール
3 const { app, BrowserWindow, Notification, globalShortcut } = require('electron')
4 const path = require('path')
5 let window
6
7 function createWindow() {
8   //ブラウザウィンドウを作成します。
9   window = new BrowserWindow({
10     width: 800,
11     height: 600,
12     webPreferences: {
13       preload: path.join(__dirname, 'preload.js')
14     }
15   })
16   //アプリのindex.htmlを読み込みます。
17   window.loadFile('index.html')
18 }
19
20 function showNotification() {
21   //通知を表示します。
22   const notification = {
23     title: 'Basic Notification',
24     body: 'Notification from the Main process'
25   }
26   new Notification(notification).show()
27 }
28
29 // このメソッドは、Electronが初期化を終え、ブラウザウィンドウを作成する準備ができたときに呼び出されます。
30 // 初期化が完了し、ブラウザウィンドウを作成する準備ができたときに呼び出されます。
31 // いくつかのAPIは、このイベントが発生した後にのみ使用できます。
32 app.whenReady().then(() => {/*
33   globalShortcut.register('CommandOrControl+Shift+I', () => {
34     console.log('Devtool Block')
35   })//*/
36 }).then(() => {
37   createWindow()// <-- function createWindow のやつを動かす。
38
39   window.setProgressBar(0.555555555555,{mode:"paused"})
40   setTimeout(() => {
41     window.setProgressBar(0)
42     setTimeout(() => {
43       window.setProgressBar(0.2)
44       setTimeout(() => {
45         window.setProgressBar(0.25)
46         setTimeout(() => {
47           window.setProgressBar(0.3,{mode:"error"})
48           setTimeout(() => {
49             window.setProgressBar(0.9)
50             setTimeout(() => {
51               window.setProgressBar(0.99)
52               setTimeout(() => {
53                 window.setProgressBar(1)
54                 setTimeout(() => {
55                   window.setProgressBar(-1)
56                   setTimeout(() => {
57                     window.setProgressBar(2)
58                   }, 2000)
59                 }, 2000)
60               }, 2000)
61             }, 2000)
62           }, 2000)
63         }, 2000)
64       }, 2000)
65     }, 2000)
66   }, 2000)
67
68   // このリスナーは、アプリケーションが起動した後に動きます。
69   app.on('activate', () => {
70
71     // 表示されているウィンドウがないときにのみ動きます。(バックグラウンド処理など)
72     /*
73     if (BrowserWindow.getAllWindows().length === 0) {
74       // 新しいブラウザウィンドウを作成します。
75       createWindow()
76     }
77     //*/
78   })
79
80 }).then(() => {
81   showNotification()
82 })
83
84 // 開いているウィンドウがなくなったときにのみ動きます。
85 // !このリスナーは、macOSではOSのウィンドウ管理の動作のため、使用できません。
86 // !macOSでは、ユーザーがCmd + Qで明示的に終了させるまで、アプリケーションとそのメニューバーがアクティブなままであることが一般的です。
87 // !(余談:Neko7soraは、macを持っていないため詳しく分かりません。以上....)
88 app.on('window-all-closed', () => {
89   if (process.platform !== 'darwin') {
90     // アプリケーションを終了!!
91     app.quit()
92   }
93 })
94
95 function plugin() {
96   require("./plugin/NavigatorOnLine/index.js")(app, BrowserWindow);
97 }
98 plugin()