Skip to content

Commit

Permalink
cleanup, fix global calls, typos
Browse files Browse the repository at this point in the history
  • Loading branch information
cankurttekin authored Sep 9, 2024
1 parent bf088b7 commit 382ab22
Showing 1 changed file with 10 additions and 21 deletions.
31 changes: 10 additions & 21 deletions wikiartwallpaper@cankurttekin/extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@
*
* License: GPL-3.0
*/

const { Shell } = imports.gi;
import { Shell } from 'gi://Shell';
import St from "gi://St";
import Gio from "gi://Gio";
import Clutter from "gi://Clutter";
Expand All @@ -29,7 +28,7 @@ import * as PanelMenu from 'resource:///org/gnome/shell/ui/panelMenu.js';
import * as PopupMenu from 'resource:///org/gnome/shell/ui/popupMenu.js';
import * as Main from 'resource:///org/gnome/shell/ui/main.js';

const WIKIART_WALLPAPER_DIR = GLib.get_user_special_dir(GLib.UserDirectory.DIRECTORY_PICTURES) + '/WikiArtWallpaper/';
let WIKIART_WALLPAPER_DIR = null;
const MAX_ARTWORK_INDEX = 3810;

const TrayIcon = 'wikiartwallpaper';
Expand All @@ -47,7 +46,7 @@ const WikiArtWallpaper = GObject.registerClass(
super._init(0.0, "WikiArtWallpaper");

this.extension = extension;

this.session = extension.session;
// Set up the icon for the tray button
this.icon = new St.Icon({
style_class: "system-status-icon",
Expand Down Expand Up @@ -82,9 +81,9 @@ const WikiArtWallpaper = GObject.registerClass(
setWallpaperAdjustment(wallpaperAdjustment);
});

this.strechedMenuItem = new PopupMenu.PopupMenuItem("Streched");
this.strechedMenuItem.connect('activate', () => {
wallpaperAdjustment = 'streched';
this.stretchedMenuItem = new PopupMenu.PopupMenuItem("Stretched");
this.stretchedMenuItem.connect('activate', () => {
wallpaperAdjustment = 'stretched';
setWallpaperAdjustment(wallpaperAdjustment);
});

Expand All @@ -102,7 +101,7 @@ const WikiArtWallpaper = GObject.registerClass(

// Add all adjustment options to a submenu
this.subMenu = new PopupMenu.PopupSubMenuMenuItem('Change Wallpaper Adjustment');
[this.wallpaperMenuItem, this.centeredMenuItem, this.scaledMenuItem, this.strechedMenuItem, this.zoomMenuItem, this.spannedMenuItem]
[this.wallpaperMenuItem, this.centeredMenuItem, this.scaledMenuItem, this.stretchedMenuItem, this.zoomMenuItem, this.spannedMenuItem]
.forEach(e => this.subMenu.menu.addMenuItem(e));
this.menu.addMenuItem(this.subMenu);

Expand Down Expand Up @@ -265,7 +264,6 @@ function setBackgroundColor(color) {

function getWallpaperUrl(url) {
return new Promise((resolve, reject) => {
let session = new Soup.Session();
let message = Soup.Message.new('GET', url);

session.send_and_read_async(message, GLib.PRIORITY_DEFAULT, null, (session, result) => {
Expand Down Expand Up @@ -323,7 +321,9 @@ function convertHtmlToPlainText(html) {

export default class WikiArtWallpaperExtension extends Extension {
enable() {
this.session = new Soup.Session();
// Create and add the extension to the panel
WIKIART_WALLPAPER_DIR = GLib.get_user_special_dir(GLib.UserDirectory.DIRECTORY_PICTURES) + '/WikiArtWallpaper/';
myExtension = new WikiArtWallpaper(this);
Main.panel.addToStatusArea(this.uuid, myExtension);
}
Expand All @@ -334,17 +334,6 @@ export default class WikiArtWallpaperExtension extends Extension {
myExtension.destroy();
myExtension = null;
}

// Remove any active timeout
if (timeoutId) {
GLib.Source.remove(timeoutId);
timeoutId = null;
}

// Clean up any active Soup sessions if needed
if (this.session) {
this.session.abort();
this.session = null;
}
this.session = null;
}
}

0 comments on commit 382ab22

Please sign in to comment.