@@ -7,9 +7,11 @@ import * as settings from 'src/utils/settings';
77import each from 'src/utils/each' ;
88import wrap from 'src/utils/2.pokemon' ;
99import Translation from 'src/structures/constants/translation' ;
10- import { buttonCSS } from 'src/utils/1.variables' ;
10+ import { buttonCSS , scriptVersion } from 'src/utils/1.variables' ;
1111import sleep from 'src/utils/sleep' ;
1212import createParser from 'src/utils/parser' ;
13+ import DialogHelper from 'src/utils/DialogHelper' ;
14+ import { getVersion } from 'src/utils/plugin' ;
1315
1416const HOUR = 60 * 60 * 1000 ;
1517const DAY = 24 * HOUR ;
@@ -28,6 +30,8 @@ export const disabled = settings.register({
2830 category : 'Updates' ,
2931} ) ;
3032
33+ const silent = settings . register ( ) ;
34+
3135const frequency = settings . register ( {
3236 // TODO: translation
3337 name : 'Update Frequency' ,
@@ -47,6 +51,7 @@ const frequency = settings.register({
4751 } ,
4852} ) ;
4953
54+ const dialog = new DialogHelper ( ) ;
5055const pendingUpdates = new Map ( ) ;
5156
5257export function register ( {
@@ -152,7 +157,7 @@ async function check(auto = true) {
152157 if ( updateFound ) {
153158 finish ( ) ;
154159 // TODO: translation
155- notify ( 'Updates found .' , true ) ;
160+ notify ( 'Updates available .' , true ) ;
156161 } else if ( ! auto && ! pendingUpdates . size ) {
157162 // TODO: translation
158163 notify ( 'No updates available.' ) ;
@@ -182,7 +187,10 @@ function setup() {
182187}
183188
184189function open ( ) {
185- // TODO: window for showing pending updates
190+ dialog . open ( {
191+ title : 'Pending Updates' , // TODO: translation
192+ message : build ,
193+ } ) ;
186194}
187195
188196menu . addButton ( {
@@ -228,3 +236,62 @@ each(localStorage, (data, key) => wrap(() => {
228236
229237sessionStorage . removeItem ( CHECKING ) ;
230238eventManager . on ( 'underscript:ready' , setup ) ;
239+
240+ function build ( ) {
241+ let addedRefresh = false ;
242+ const container = $ ( '<div>' ) ;
243+ function refreshButton ( ) {
244+ if ( addedRefresh ) return ;
245+ dialog . prependButton ( {
246+ label : 'Refresh Page' ,
247+ cssClass : 'btn-success' ,
248+ action ( ) {
249+ location . reload ( ) ;
250+ } ,
251+ } ) ;
252+ addedRefresh = true ;
253+ }
254+ function add ( {
255+ currentVersion,
256+ name,
257+ url,
258+ version,
259+ } ) {
260+ const button = $ ( `<a>` )
261+ . text ( `Update to ${ version } ` ) // TODO: translation
262+ . attr ( {
263+ href : url ,
264+ rel : 'noreferrer' ,
265+ target : 'updateUserScript' ,
266+ } )
267+ . addClass ( 'btn btn-primary' )
268+ . on ( 'click' , ( ) => {
269+ refreshButton ( ) ;
270+ button . addClass ( 'btn-success' ) ;
271+ } ) ;
272+ container . append ( $ ( '<fieldset>' ) . append (
273+ $ ( '<legend>' ) . text ( name ) ,
274+ $ ( '<div>' ) . text ( `Current: ${ currentVersion } ` ) ,
275+ button ,
276+ ) ) ;
277+ }
278+ const underscript = pendingUpdates . get ( 'UnderScript' ) ;
279+ if ( underscript ) {
280+ add ( {
281+ ...underscript ,
282+ name : 'UnderScript' ,
283+ currentVersion : scriptVersion ,
284+ } ) ;
285+ }
286+ [ ...pendingUpdates . entries ( ) ] . forEach (
287+ ( [ name , data ] ) => {
288+ if ( name === 'UnderScript' ) return ;
289+ add ( {
290+ ...data ,
291+ name,
292+ currentVersion : getVersion ( name ) ,
293+ } ) ;
294+ } ,
295+ ) ;
296+ return container . children ( ) ;
297+ }
0 commit comments