From 80de7a57280212d34631aac07120e60cb5def0e6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oskar=20K=C3=B6=C3=B6k?= Date: Mon, 13 Aug 2018 00:43:30 +0300 Subject: [PATCH 1/5] Add Reddit support --- randomwallpaper@iflow.space/prefs.js | 23 +++- .../schemas/gschemas.compiled | Bin 2980 -> 3333 bytes ...ns.space.iflow.randomwallpaper.gschema.xml | 17 ++- randomwallpaper@iflow.space/settings.ui | 115 ++++++++++++++---- randomwallpaper@iflow.space/sourceAdapter.js | 54 ++++++++ .../wallpaperController.js | 4 + 6 files changed, 184 insertions(+), 29 deletions(-) diff --git a/randomwallpaper@iflow.space/prefs.js b/randomwallpaper@iflow.space/prefs.js index baea0b1..5d194a0 100644 --- a/randomwallpaper@iflow.space/prefs.js +++ b/randomwallpaper@iflow.space/prefs.js @@ -17,6 +17,7 @@ const RWG_SETTINGS_SCHEMA = 'org.gnome.shell.extensions.space.iflow.randomwallpa const RWG_SETTINGS_SCHEMA_DESKTOPPER = 'org.gnome.shell.extensions.space.iflow.randomwallpaper.desktopper'; const RWG_SETTINGS_SCHEMA_UNSPLASH = 'org.gnome.shell.extensions.space.iflow.randomwallpaper.unsplash'; const RWG_SETTINGS_SCHEMA_WALLHAVEN = 'org.gnome.shell.extensions.space.iflow.randomwallpaper.wallhaven'; +const RWG_SETTINGS_SCHEMA_REDDIT = 'org.gnome.shell.extensions.space.iflow.randomwallpaper.reddit'; const RWG_SETTINGS_SCHEMA_GENERIC_JSON = 'org.gnome.shell.extensions.space.iflow.randomwallpaper.genericJSON'; const LoggerModule = Self.imports.logger; @@ -44,6 +45,7 @@ var RandomWallpaperSettings = new Lang.Class({ desktopperSettings: null, unsplashSettings: null, wallhavenSettings: null, + redditSettings: null, genericJsonSettings: null, _wallpaperController: null, @@ -73,6 +75,11 @@ var RandomWallpaperSettings = new Lang.Class({ this.wallhavenSettings = this._builder.get_object('wallhaven-settings'); this.bindWallhaven(); + // Reddit Settings + this._reddit_settings = Convenience.getSettings(RWG_SETTINGS_SCHEMA_REDDIT); + this.redditSettings = this._builder.get_object('reddit-settings'); + this.bindReddit(); + // Generic JSON Settings this._generic_json_settings = Convenience.getSettings(RWG_SETTINGS_SCHEMA_GENERIC_JSON); this.genericJsonSettings = this._builder.get_object('generic-json-settings'); @@ -102,7 +109,10 @@ var RandomWallpaperSettings = new Lang.Class({ case 2: // wallhaven this.currentSourceSettingsWidget = this.wallhavenSettings; break; - case 3: // generic JSON + case 3: // reddit + this.currentSourceSettingsWidget = this.redditSettings; + break; + case 4: // generic JSON this.currentSourceSettingsWidget = this.genericJsonSettings; break; default: @@ -227,6 +237,17 @@ var RandomWallpaperSettings = new Lang.Class({ Gio.SettingsBindFlags.DEFAULT); }, + bindReddit: function () { + this._reddit_settings.bind('subreddits', + this._builder.get_object('reddit-subreddits'), + 'text', + Gio.SettingsBindFlags.DEFAULT); + this._reddit_settings.bind('allow-sfw', + this._builder.get_object('reddit-allow-sfw'), + 'active', + Gio.SettingsBindFlags.DEFAULT); + }, + bindGenericJSON: function () { this._builder.get_object('generic-json-docs-link').set_label("More information here"); this._generic_json_settings.bind('generic-json-request-url', diff --git a/randomwallpaper@iflow.space/schemas/gschemas.compiled b/randomwallpaper@iflow.space/schemas/gschemas.compiled index bee5c6b230062634e2370d0dea3bbe7e736ba906..3f9c5ec0fd264e5409104c9d9208aa98ca8692cb 100644 GIT binary patch delta 1396 zcmYLJT}TvB82z?&{9DbR6gSJFl30<|mwqhL(nLfoO@lNLTH7(L^@kl-1IzItAuz#Q zr3iz4$Phs>4B8jVhaw3>Ga@4hg@`3hd=QGL?3~rXfivgKx!=9_yZ3%~9wl`q_ax|F zCHUCFHdwZS3G*fta46thI^m~ge6AFV%_MRQ=zo^|h5j=15%{U-d;^_T+spIx>+w1T ze+>K-16_2RKhj^rgn3eUPO`#9rUCs|WeFR)BSf;%VH%ttDWW8btmB!07AclV@I3Iu zcOaed)F%;dwcsO4#QWEL^zM3EF_Vju7U^M+A^;Lm`O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s>=Di< zmq@Tfb^_|5TU&mwa)4Zn7u@i}&_uefpE;S$I|bLET$9LbQZIbWGW*za&!qFdRAKHg zJOt(Dk~#Mhd;;<+sW&`qas}q!g+G9D#gkcl6rO=z?20aMKG})fiNbgv&uTu+f3C-M zesI9&@@vM|f*(drUW<;M>uq0n9^^vgN%%Kt+d};^b29h-3$7OauY=4w zZ16+mwVO)je%j#|pvv;54z5FXNKltBAOf`|T3&O2oR5X3;7_6Vp3*pTGEPGh@J~=M z)3}j2*@8R;Z^Abf{BWa$Ihh5y;XTmu(r7j(bHl^%km^KNN20BKA%uW`JPw~!XD^yZ VOopQLR$z$3d~i2~&BaG0{{Yr7>*4?a diff --git a/randomwallpaper@iflow.space/schemas/org.gnome.shell.extensions.space.iflow.randomwallpaper.gschema.xml b/randomwallpaper@iflow.space/schemas/org.gnome.shell.extensions.space.iflow.randomwallpaper.gschema.xml index 0911d56..3a6d22b 100644 --- a/randomwallpaper@iflow.space/schemas/org.gnome.shell.extensions.space.iflow.randomwallpaper.gschema.xml +++ b/randomwallpaper@iflow.space/schemas/org.gnome.shell.extensions.space.iflow.randomwallpaper.gschema.xml @@ -5,7 +5,8 @@ - + + + + + "" + Subreddits + These subreddits will be searched. + + + false + SFW + Whether safe images are allowed. + + + diff --git a/randomwallpaper@iflow.space/settings.ui b/randomwallpaper@iflow.space/settings.ui index 535014a..5c65552 100644 --- a/randomwallpaper@iflow.space/settings.ui +++ b/randomwallpaper@iflow.space/settings.ui @@ -199,6 +199,93 @@ You can also define a prefix that will be added to the image URL. 1 10 + + True + False + 10 + 10 + 10 + 10 + No Settings Available + + + + True + False + gtk-open + + + True + False + 10 + 10 + 10 + 10 + vertical + + + True + False + start + Subreddits (separate with a comma) + + + False + True + 0 + + + + + True + True + wallpaper, wallpapers, earthporn + + + False + True + 1 + + + + + True + False + start + + + SFW (Safe for work) + True + True + False + True + + + True + True + 0 + + + + + False + True + 2 + + + + + True + False + gtk-refresh + + + True + False + gtk-delete + 400 600 @@ -727,6 +814,7 @@ You can also define a prefix that will be added to the image URL. unsplash.com desktoppr.co alpha.wallhaven.cc + reddit Generic JSON @@ -1213,33 +1301,6 @@ You can also define a prefix that will be added to the image URL. - - True - False - 10 - 10 - 10 - 10 - No Settings Available - - - - True - False - gtk-open - - - True - False - gtk-refresh - - - True - False - gtk-delete - 1 1000000 diff --git a/randomwallpaper@iflow.space/sourceAdapter.js b/randomwallpaper@iflow.space/sourceAdapter.js index a9f2f7e..eec828a 100644 --- a/randomwallpaper@iflow.space/sourceAdapter.js +++ b/randomwallpaper@iflow.space/sourceAdapter.js @@ -8,6 +8,7 @@ const Json = imports.gi.Json; const RWG_SETTINGS_SCHEMA_DESKTOPPER = 'org.gnome.shell.extensions.space.iflow.randomwallpaper.desktopper'; const RWG_SETTINGS_SCHEMA_UNSPLASH = 'org.gnome.shell.extensions.space.iflow.randomwallpaper.unsplash'; const RWG_SETTINGS_SCHEMA_WALLHAVEN = 'org.gnome.shell.extensions.space.iflow.randomwallpaper.wallhaven'; +const RWG_SETTINGS_SCHEMA_REDDIT = 'org.gnome.shell.extensions.space.iflow.randomwallpaper.reddit'; const RWG_SETTINGS_SCHEMA_GENERIC_JSON = 'org.gnome.shell.extensions.space.iflow.randomwallpaper.genericJSON'; const SettingsModule = Self.imports.settings; @@ -352,6 +353,59 @@ var WallhavenAdapter = new Lang.Class({ } }); +var RedditAdapter = new Lang.Class({ + Name: "RedditAdapter", + Extends: BaseAdapter, + + _settings: null, + + _init: function () { + this.parent(); + this._settings = new SettingsModule.Settings(RWG_SETTINGS_SCHEMA_REDDIT); + }, + + requestRandomImage: function (callback) { + let session = new Soup.SessionAsync(); + + const subreddits = this._settings.get('subreddits', 'string').split(',').map(s => s.trim()).join('+'); + const require_sfw = this._settings.get('allow-sfw', 'boolean'); + const url = encodeURI(`https://www.reddit.com/r/${subreddits}.json`); + + let message = Soup.Message.new('GET', url); + + if (message === null) { + this._error("Could not create request.", callback); + return; + } + + session.queue_message(message, (session, message) => { + try { + const submissions = JSON.parse(message.response_body.data).data.children.filter(child => { + if(child.data.post_hint !== 'image') return false; + if(require_sfw) return child.data.over_18 === false; + return true; + }); + if(submissions.length === 0) { + this._error("No suitable submissions found!", callback); + return; + } + const random = Math.floor(Math.random() * submissions.length); + const submission = submissions[random].data; + const imageDownloadUrl = submission.preview.images[0].source.url; + + if (callback) { + let historyEntry = new HistoryModule.HistoryEntry(null, 'reddit', imageDownloadUrl); + historyEntry.source.sourceUrl = 'https://www.reddit.com/' + submission.permalink; + callback(historyEntry); + } + } catch (e) { + this._error("Could not create request. (" + e + ")", callback); + return; + } + }); + } +}); + var GenericJsonAdapter = new Lang.Class({ Name: "GenericJsonAdapter", Extends: BaseAdapter, diff --git a/randomwallpaper@iflow.space/wallpaperController.js b/randomwallpaper@iflow.space/wallpaperController.js index f9e9e23..b9d2901 100644 --- a/randomwallpaper@iflow.space/wallpaperController.js +++ b/randomwallpaper@iflow.space/wallpaperController.js @@ -54,6 +54,7 @@ var WallpaperController = new Lang.Class({ this._desktopperAdapter = new SourceAdapter.DesktopperAdapter(); this._unsplashAdapter = new SourceAdapter.UnsplashAdapter(); this._wallhavenAdapter = new SourceAdapter.WallhavenAdapter(); + this._redditAdapter = new SourceAdapter.RedditAdapter(); this._genericJsonAdapter = new SourceAdapter.GenericJsonAdapter(); this._updateHistory(); @@ -98,6 +99,9 @@ var WallpaperController = new Lang.Class({ this.imageSourceAdapter = this._wallhavenAdapter; break; case 3: + this.imageSourceAdapter = this._redditAdapter; + break; + case 4: this.imageSourceAdapter = this._genericJsonAdapter; break; default: From 92f0b44e543b7b3a466e3adb4bd4b2adb73c6214 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oskar=20K=C3=B6=C3=B6k?= Date: Mon, 13 Aug 2018 01:03:19 +0300 Subject: [PATCH 2/5] fix indentation --- randomwallpaper@iflow.space/sourceAdapter.js | 36 ++++++++++---------- 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/randomwallpaper@iflow.space/sourceAdapter.js b/randomwallpaper@iflow.space/sourceAdapter.js index eec828a..8c6de28 100644 --- a/randomwallpaper@iflow.space/sourceAdapter.js +++ b/randomwallpaper@iflow.space/sourceAdapter.js @@ -367,35 +367,35 @@ var RedditAdapter = new Lang.Class({ requestRandomImage: function (callback) { let session = new Soup.SessionAsync(); - const subreddits = this._settings.get('subreddits', 'string').split(',').map(s => s.trim()).join('+'); - const require_sfw = this._settings.get('allow-sfw', 'boolean'); - const url = encodeURI(`https://www.reddit.com/r/${subreddits}.json`); + const subreddits = this._settings.get('subreddits', 'string').split(',').map(s => s.trim()).join('+'); + const require_sfw = this._settings.get('allow-sfw', 'boolean'); + const url = encodeURI(`https://www.reddit.com/r/${subreddits}.json`); let message = Soup.Message.new('GET', url); if (message === null) { - this._error("Could not create request.", callback); - return; + this._error("Could not create request.", callback); + return; } session.queue_message(message, (session, message) => { try { - const submissions = JSON.parse(message.response_body.data).data.children.filter(child => { - if(child.data.post_hint !== 'image') return false; - if(require_sfw) return child.data.over_18 === false; - return true; - }); - if(submissions.length === 0) { - this._error("No suitable submissions found!", callback); - return; - } - const random = Math.floor(Math.random() * submissions.length); - const submission = submissions[random].data; - const imageDownloadUrl = submission.preview.images[0].source.url; + const submissions = JSON.parse(message.response_body.data).data.children.filter(child => { + if(child.data.post_hint !== 'image') return false; + if(require_sfw) return child.data.over_18 === false; + return true; + }); + if(submissions.length === 0) { + this._error("No suitable submissions found!", callback); + return; + } + const random = Math.floor(Math.random() * submissions.length); + const submission = submissions[random].data; + const imageDownloadUrl = submission.preview.images[0].source.url; if (callback) { let historyEntry = new HistoryModule.HistoryEntry(null, 'reddit', imageDownloadUrl); - historyEntry.source.sourceUrl = 'https://www.reddit.com/' + submission.permalink; + historyEntry.source.sourceUrl = 'https://www.reddit.com/' + submission.permalink; callback(historyEntry); } } catch (e) { From 4cc27badee1b92e07adc9e3a8fbed8df3650b6d0 Mon Sep 17 00:00:00 2001 From: Wolfgang Rumpler Date: Sun, 19 Aug 2018 10:47:33 +0200 Subject: [PATCH 3/5] enhance reddit linking --- randomwallpaper@iflow.space/sourceAdapter.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/randomwallpaper@iflow.space/sourceAdapter.js b/randomwallpaper@iflow.space/sourceAdapter.js index 8c6de28..138326f 100644 --- a/randomwallpaper@iflow.space/sourceAdapter.js +++ b/randomwallpaper@iflow.space/sourceAdapter.js @@ -395,7 +395,8 @@ var RedditAdapter = new Lang.Class({ if (callback) { let historyEntry = new HistoryModule.HistoryEntry(null, 'reddit', imageDownloadUrl); - historyEntry.source.sourceUrl = 'https://www.reddit.com/' + submission.permalink; + historyEntry.source.sourceUrl = 'https://www.reddit.com/' + submission.subreddit_name_prefixed; + historyEntry.source.imageLinkUrl = 'https://www.reddit.com/' + submission.permalink; callback(historyEntry); } } catch (e) { From f462de4494bb4860778b47a1e9c4321d0f8a8f22 Mon Sep 17 00:00:00 2001 From: Wolfgang Rumpler Date: Sun, 19 Aug 2018 11:01:56 +0200 Subject: [PATCH 4/5] update source names --- randomwallpaper@iflow.space/settings.ui | 8 ++++---- randomwallpaper@iflow.space/sourceAdapter.js | 6 +++--- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/randomwallpaper@iflow.space/settings.ui b/randomwallpaper@iflow.space/settings.ui index 5c65552..b7fec11 100644 --- a/randomwallpaper@iflow.space/settings.ui +++ b/randomwallpaper@iflow.space/settings.ui @@ -811,10 +811,10 @@ You can also define a prefix that will be added to the image URL. False 0 - unsplash.com - desktoppr.co - alpha.wallhaven.cc - reddit + Unsplash + Desktoppr + Wallhaven + Reddit Generic JSON diff --git a/randomwallpaper@iflow.space/sourceAdapter.js b/randomwallpaper@iflow.space/sourceAdapter.js index 138326f..ad3e3a1 100644 --- a/randomwallpaper@iflow.space/sourceAdapter.js +++ b/randomwallpaper@iflow.space/sourceAdapter.js @@ -107,7 +107,7 @@ var DesktopperAdapter = new Lang.Class({ let imageDownloadUrl = encodeURI(response.image.url); if (callback) { - let historyEntry = new HistoryModule.HistoryEntry(null, 'desktopper.co', imageDownloadUrl); + let historyEntry = new HistoryModule.HistoryEntry(null, 'Desktopper', imageDownloadUrl); historyEntry.source.sourceUrl = 'https://www.desktoppr.co/'; callback(historyEntry); } @@ -298,7 +298,7 @@ var WallhavenAdapter = new Lang.Class({ imageDownloadUrl = encodeURI(imageDownloadUrl); if (callback) { - let historyEntry = new HistoryModule.HistoryEntry(null, 'wallhaven.cc', imageDownloadUrl); + let historyEntry = new HistoryModule.HistoryEntry(null, 'Wallhaven', imageDownloadUrl); historyEntry.source.sourceUrl = 'https://alpha.wallhaven.cc/'; historyEntry.source.imageLinkUrl = url; callback(historyEntry); @@ -394,7 +394,7 @@ var RedditAdapter = new Lang.Class({ const imageDownloadUrl = submission.preview.images[0].source.url; if (callback) { - let historyEntry = new HistoryModule.HistoryEntry(null, 'reddit', imageDownloadUrl); + let historyEntry = new HistoryModule.HistoryEntry(null, 'Reddit', imageDownloadUrl); historyEntry.source.sourceUrl = 'https://www.reddit.com/' + submission.subreddit_name_prefixed; historyEntry.source.imageLinkUrl = 'https://www.reddit.com/' + submission.permalink; callback(historyEntry); From 2a7f178d4c0d28b144b90170446e1b4477fdc3f9 Mon Sep 17 00:00:00 2001 From: Wolfgang Rumpler Date: Sun, 19 Aug 2018 11:19:41 +0200 Subject: [PATCH 5/5] enhance strings in settings ui --- randomwallpaper@iflow.space/settings.ui | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/randomwallpaper@iflow.space/settings.ui b/randomwallpaper@iflow.space/settings.ui index b7fec11..530a5b6 100644 --- a/randomwallpaper@iflow.space/settings.ui +++ b/randomwallpaper@iflow.space/settings.ui @@ -241,7 +241,7 @@ You can also define a prefix that will be added to the image URL. True True - wallpaper, wallpapers, earthporn + e.g.: wallpaper, wallpapers, minimalwallpaper False @@ -407,7 +407,7 @@ You can also define a prefix that will be added to the image URL. True False True - Also change the gnome lock screen image to the new wallpaper. + Change the gnome lock screen image to the new wallpaper. True True 1 @@ -633,7 +633,7 @@ You can also define a prefix that will be added to the image URL. True False True - Disable the desktop preview of the background while hovering the history items. Try enabeling if you encounter crashes or laggs of the gnome shell while using the extension. + Disable the desktop preview of the background while hovering the history items. Try enabling if you encounter crashes or lags of the gnome-shell while using the extension. True True 1 @@ -775,7 +775,7 @@ You can also define a prefix that will be added to the image URL. True False True - The source that is used to fetch random wallpapers. You can select between unsplash.com, desktoppr.co, wallhaven.cc and a generic JSON source for experienced users. + The source that is used to fetch random wallpapers. You can select between built-in ones or the generic JSON source for experienced users. True 1 0 @@ -1145,7 +1145,7 @@ You can also define a prefix that will be added to the image URL. True False True - Automatically fetch a new wallpaper based on a period. + Automatically fetch new wallpapers based on an interval. True True 1 @@ -1517,7 +1517,7 @@ You can also define a prefix that will be added to the image URL. True False - This results in a smaller wallpaper pool but the images are considered to have higher quality. + This option results in a smaller wallpaper pool, but the images are considered to be of higher quality. True 1 0