-
-
Notifications
You must be signed in to change notification settings - Fork 51
/
RS_WinTray.js
286 lines (263 loc) · 7.25 KB
/
RS_WinTray.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
//================================================================
// RS_WinTray.js
// ---------------------------------------------------------------
// The MIT License
// Copyright (c) 2016 biud436
// ---------------------------------------------------------------
// Free for commercial and non commercial use.
//================================================================
/*:
* @plugindesc This plugin provides a function that minimizes to system tray.
* @author biud436
*
* @param url
* @desc
* @default http://www.google.com/
*
* @param --- Tray Menu
*
* @param Open
* @parent --- Tray Menu
* @desc
* @default Open
* @type text
*
* @param tooltip
* @parent --- Tray Menu
* @desc
* @default tooltip
* @type text
*
* @param Minimize To Tray
* @parent --- Tray Menu
* @desc
* @default To Tray
* @type text
*
* @param Window Always On Top
* @parent --- Tray Menu
* @desc
* @default Window Always On Top
* @type text
*
* @param Show Internet
* @parent --- Tray Menu
* @desc
* @default Open URL
* @type text
*
* @param Exit
* @parent --- Tray Menu
* @desc
* @default Game Exit
* @type text
*
* @help
* =============================================================================
* Change Log
* =============================================================================
* 2016.01.21 (v1.0.0) - First Release.
* 2016.12.28 (v1.0.1) - Fixed a bug that a previous tray will remain after reloading the window.
* 2018.02.27 (v1.0.2) - Changed the source code for RMMV 1.6.0.
*/
/*:ko
* @plugindesc nw.js의 Tray 메뉴 기능을 플러그인으로 구현하였습니다.
* @author 러닝은빛(biud436)
*
* @param url
* @text 주소
* @desc 링크 버튼이 눌리면 여기 입력된 주소를 시스템 기본 브라우저로 띄웁니다.
* @default http://www.google.com/
*
* @param --- Tray Menu
* @text 트레이 메뉴
*
* @param Open
* @type text
* @text 열기
* @parent --- Tray Menu
* @desc '열기' 버튼의 이름을 수정합니다. (열기 버튼을 누르면 게임 창이 뜹니다)
* @default 열기
*
* @param tooltip
* @type text
* @text 툴팁
* @parent --- Tray Menu
* @desc 트레이 아이콘에 마우스를 올렸을 때 표시될 툴팁 메시지를 적으세요.
* @default 더블 클릭하면 창을 띄울 수 있습니다.
*
* @param Minimize To Tray
* @type text
* @text 트레이로 최소화
* @parent --- Tray Menu
* @desc 트레이로 최소화 버튼의 이름을 수정합니다.
* @default 트레이로 최소화
*
* @param Window Always On Top
* @type text
* @text 항상 위에
* @parent --- Tray Menu
* @desc 항상 위에 버튼의 이름을 수정합니다.
* @default 항상 위에
*
* @param Show Internet
* @type text
* @text 링크
* @parent --- Tray Menu
* @desc 링크 버튼의 이름을 수정합니다.
* @default 버그 문의 및 공식 카페
*
* @param Exit
* @type text
* @text 종료
* @parent --- Tray Menu
* @desc 게임 종료 버튼의 이름을 수정합니다.
* @default 게임 종료
*
* @help
* =============================================================================
* 변동 사항
* =============================================================================
* 2016.01.21 (v1.0.0) - First Release.
* 2016.12.28 (v1.0.1) - Fixed a bug that a previous tray will remain after reloading the window.
* 2018.02.27 (v1.0.2) - Changed the source code for RMMV 1.6.0.
*/
var Imported = Imported || {};
var RS = RS || {};
RS.Tray = RS.Tray || {};
RS.Tray.Params = RS.Tray.Params || {};
Imported.RS_WinTray = true;
function Tray() {
this.initialize.apply(this, arguments);
}
(function($) {
if(typeof require === 'undefined') return false;
// Tray Menu
var parameters = PluginManager.parameters('RS_WinTray');
$.menuString = {
'open': parameters['Open'],
'tooltip': parameters['tooltip'],
'url': parameters['url'],
'minimize_to_tray': parameters['Minimize To Tray'],
'window_always_on_top': parameters['Window Always On Top'],
'show_internet': parameters['Show Internet'],
'exit': parameters['Exit']
}
Tray.prototype.initialize = function() {
this.initMembers();
this.initTray();
this.setupMenu();
};
Tray.prototype.initMembers = function() {
var self = this;
// In RMMV 1.6.0,
// All NW specific APIs, including require() is moved into a nw object from the nw.gui library.
var gui;
if(Utils.RPGMAKER_VERSION >= "1.6.0") {
gui = nw;
} else {
gui = require('nw.gui');
}
this._path = this.setupPath();
this._win = gui.Window.get();
this._tray = new gui.Tray({icon: self._path + 'icon.png' });
this._menu = new gui.Menu();
this._status = false;
};
$.localFilePath = function () {
if(!Utils.isNwjs()) return '';
var path, base;
path = require('path');
base = path.dirname(process.mainModule.filename);
return path.join(base, 'icon/');
};
Tray.prototype.setupPath = function () {
if(Utils.RPGMAKER_VERSION >= "1.6.0") return $.localFilePath();
var path = window.location.pathname.replace(/(\/www|)\/[^\/]*$/, '/icon/');
if (path.match(/^\/([A-Z]\:)/)) {
path = path.slice(1);
}
return decodeURIComponent(path);
};
Tray.prototype.initTray = function () {
var self = this;
this._tray.menu = this._menu;
this._tray.tooltip = $.menuString['tooltip'];
this._tray.on('click', function() {
self._menu.items[0].click();
});
this._tray.on('close', function () {
if(self._tray) {
self._tray.remove();
self._tray = null;
}
});
};
Tray.prototype.setupMenu = function () {
var self = this;
var gui;
if(Utils.RPGMAKER_VERSION >= "1.6.0") {
gui = nw;
} else {
gui = require('nw.gui');
}
self._menu.append(new gui.MenuItem({
type: 'normal',
label: $.menuString['open'],
click: function() {
self._win.show();
self._win.focus();
}
}));
self._menu.append(new gui.MenuItem({
type: 'checkbox',
label: $.menuString['minimize_to_tray'],
click: function () {
if(this.checked) {
self._win.hide();
} else {
self._win.show();
self._win.focus();
}
}
}));
self._menu.append(new gui.MenuItem({
type: 'checkbox',
label: $.menuString['window_always_on_top'],
click: function() {
self._win.setAlwaysOnTop(this.checked);
}
}));
self._menu.append(new gui.MenuItem({
type: 'normal',
label: $.menuString['show_internet'],
click: function() {
var gui;
if(Utils.RPGMAKER_VERSION >= "1.6.0") {
gui = nw;
} else {
gui = require('nw.gui');
}
var shell = gui.Shell;
shell.openExternal($.menuString['url']);
}
}));
self._menu.append(new gui.MenuItem({
type: 'normal',
label: $.menuString['exit'],
click: function() {
if(self._tray) {
self._tray.remove();
self._tray = null;
}
if(self._win !== null) {
self._win.close(true);
self._win = null;
}
}
}));
};
if(!RS.Tray.system) {
RS.Tray.system = new Tray();
}
})(RS.Tray.Params);