Skip to content

Commit

Permalink
style: fix linter errors for new config
Browse files Browse the repository at this point in the history
  • Loading branch information
Leleat committed Aug 11, 2024
1 parent 87d1363 commit f537dbd
Show file tree
Hide file tree
Showing 18 changed files with 1,069 additions and 415 deletions.
71 changes: 52 additions & 19 deletions tiling-assistant@leleat-on-github/extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,17 +53,21 @@ class SettingsOverrider {
}

_maybeUpdateOverriden(schemaId, key, value) {
if (this._wasOverridden) return undefined;
if (this._wasOverridden) {
return undefined;
}

const savedSettings = this._settings
.getValue('overridden-settings')
.deepUnpack();
const prefKey = `${schemaId}.${key}`;
const oldValue = savedSettings[prefKey];

if (value !== undefined)
if (value !== undefined) {
savedSettings[prefKey] = value ?? this._maybeNullValue;
else delete savedSettings[prefKey];
} else {
delete savedSettings[prefKey];
}

this._settings.setValue(
'overridden-settings',
Expand All @@ -78,7 +82,9 @@ class SettingsOverrider {
const userValue = settings.get_user_value(key);

const values = this._overrides.get(settings.schemaId) ?? new Map();
if (!values.size) this._overrides.set(settings.schemaId, values);
if (!values.size) {
this._overrides.set(settings.schemaId, values);
}
values.set(key, userValue);

settings.set_value(key, value);
Expand All @@ -92,15 +98,22 @@ class SettingsOverrider {

remove(schema, key) {
const settings = this._originalSettings.get(schema);
if (!settings) return;
if (!settings) {
return;
}

const values = this._overrides.get(settings.schemaId);
const value = values?.get(key);

if (value === undefined) return;
if (value === undefined) {
return;
}

if (value) settings.set_value(key, value);
else settings.reset(key);
if (value) {
settings.set_value(key, value);
} else {
settings.reset(key);
}

values.delete(key);
this._maybeUpdateOverriden(settings.schemaId, key, undefined);
Expand All @@ -122,14 +135,20 @@ class SettingsOverrider {
new Gio.Settings({schema_id: schemaId});

value = value.get_variant();
if (value.equal(this._maybeNullValue)) settings.reset(key);
else settings.set_value(key, value);
if (value.equal(this._maybeNullValue)) {
settings.reset(key);
} else {
settings.set_value(key, value);
}
});
} else {
this._originalSettings.forEach((settings) => {
this._overrides.get(settings.schemaId).forEach((value, key) => {
if (value) settings.set_value(key, value);
else settings.reset(key);
if (value) {
settings.set_value(key, value);
} else {
settings.reset(key);
}
});
});
}
Expand Down Expand Up @@ -316,7 +335,9 @@ export default class TilingAssistantExtension extends Extension {
* properties of windows before locking the screen.
*/
_saveBeforeSessionLock() {
if (!Main.sessionMode.isLocked) return;
if (!Main.sessionMode.isLocked) {
return;
}

this._wasLocked = true;

Expand All @@ -330,7 +351,9 @@ export default class TilingAssistantExtension extends Extension {
try {
parent.make_directory_with_parents(null);
} catch (e) {
if (e.code !== Gio.IOErrorEnum.EXISTS) throw e;
if (e.code !== Gio.IOErrorEnum.EXISTS) {
throw e;
}
}

const path = GLib.build_filenamev([
Expand All @@ -342,7 +365,9 @@ export default class TilingAssistantExtension extends Extension {
try {
file.create(Gio.FileCreateFlags.NONE, null);
} catch (e) {
if (e.code !== Gio.IOErrorEnum.EXISTS) throw e;
if (e.code !== Gio.IOErrorEnum.EXISTS) {
throw e;
}
}

file.replace_contents(
Expand All @@ -362,7 +387,9 @@ export default class TilingAssistantExtension extends Extension {
* reload them here.
*/
_loadAfterSessionLock() {
if (!this._wasLocked) return;
if (!this._wasLocked) {
return;
}

this._wasLocked = false;

Expand All @@ -372,16 +399,22 @@ export default class TilingAssistantExtension extends Extension {
'/tiling-assistant/tiledSessionRestore2.json',
]);
const file = Gio.File.new_for_path(path);
if (!file.query_exists(null)) return;
if (!file.query_exists(null)) {
return;
}

try {
file.create(Gio.FileCreateFlags.NONE, null);
} catch (e) {
if (e.code !== Gio.IOErrorEnum.EXISTS) throw e;
if (e.code !== Gio.IOErrorEnum.EXISTS) {
throw e;
}
}

const [success, contents] = file.load_contents(null);
if (!success || !contents.length) return;
if (!success || !contents.length) {
return;
}

const states = JSON.parse(new TextDecoder().decode(contents));
const keysAsNumbers = (entries) =>
Expand Down
69 changes: 60 additions & 9 deletions tiling-assistant@leleat-on-github/prefs.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,21 @@ export default class Prefs extends ExtensionPreferences {
settings.connect(
'changed::enable-advanced-experimental-features',
() => {
settings.get_boolean('enable-advanced-experimental-features') ?
window.add(layoutsPage)
: window.remove(layoutsPage);
if (
settings.get_boolean(
'enable-advanced-experimental-features',
)
) {
window.add(layoutsPage);
} else {
window.remove(layoutsPage);
}
},
);

if (settings.get_boolean('enable-advanced-experimental-features'))
if (settings.get_boolean('enable-advanced-experimental-features')) {
window.add(layoutsPage);
}

// Bind settings to GUI
this._bindSwitches(settings, builder);
Expand Down Expand Up @@ -115,8 +122,11 @@ export default class Prefs extends ExtensionPreferences {
});
}

/*
/**
* Bind GUI AdwComboRows to settings.
*
* @param {Gio.Settings} settings
* @param {Gtk.Builder} builder
*/
_bindComboRows(settings, builder) {
const comboRows = [
Expand All @@ -137,8 +147,11 @@ export default class Prefs extends ExtensionPreferences {
});
}

/*
/**
* Bind GUI color buttons to settings.
*
* @param {Gio.Settings} settings
* @param {Gtk.Builder} builder
*/
_bindColorButtons(settings, builder) {
const switches = ['focus-hint-color'];
Expand All @@ -158,8 +171,11 @@ export default class Prefs extends ExtensionPreferences {
});
}

/*
/**
* Bind radioButtons to settings.
*
* @param {Gio.Settings} settings
* @param {Gtk.Builder} builder
*/
_bindRadioButtons(settings, builder) {
// These 'radioButtons' are basically just used as a 'fake ComboBox' with
Expand Down Expand Up @@ -207,13 +223,18 @@ export default class Prefs extends ExtensionPreferences {
);

// Set initial state
if (idx === currActive) checkButton.activate();
if (idx === currActive) {
checkButton.activate();
}
});
});
}

/*
/**
* Bind keybinding widgets to settings.
*
* @param {Gio.Settings} settings
* @param {Gtk.Builder} builder
*/
_bindKeybindings(settings, builder) {
const shortcuts = Shortcuts.getAllKeys();
Expand All @@ -229,6 +250,9 @@ export default class Prefs extends ExtensionPreferences {
* discoverable through the GUI and need to first be set with the gsetting.
* The normal rows should have the id of: GSETTING_WITH_UNDERSCORES_row.
* ShortcutListeners have the format of GSETTING_WITH_UNDERSCORES.
*
* @param {Gio.Settings} settings
* @param {Gtk.Builder} builder
*/
_setDeprecatedSettings(settings, builder) {
// Keybindings
Expand All @@ -252,6 +276,12 @@ export default class Prefs extends ExtensionPreferences {
});
}

/**
*
* @param {Adw.fillPreferencesWindow} window - The preferences window
* @param {Gio.Settings} settings - The settings object
* @param {Gtk.Builder} builder - The builder object
*/
_addHeaderBarInfoButton(window, settings, builder) {
// Add headerBar button for menu
// TODO: is this a 'reliable' method to access the headerbar?
Expand Down Expand Up @@ -310,6 +340,10 @@ export default class Prefs extends ExtensionPreferences {
returnButton.connect('clicked', () => window.close_subpage());
}

/**
*
* @param {Adw.PreferencesWindow} window
*/
_openBugReport(window) {
Gtk.show_uri(
window,
Expand All @@ -318,6 +352,10 @@ export default class Prefs extends ExtensionPreferences {
);
}

/**
*
* @param {Adw.PreferencesWindow} window
*/
_openUserGuide(window) {
Gtk.show_uri(
window,
Expand All @@ -326,6 +364,10 @@ export default class Prefs extends ExtensionPreferences {
);
}

/**
*
* @param {Adw.PreferencesWindow} window
*/
_openChangelog(window) {
Gtk.show_uri(
window,
Expand All @@ -334,6 +376,10 @@ export default class Prefs extends ExtensionPreferences {
);
}

/**
*
* @param {Adw.PreferencesWindow} window
*/
_openLicense(window) {
Gtk.show_uri(
window,
Expand All @@ -342,6 +388,11 @@ export default class Prefs extends ExtensionPreferences {
);
}

/**
*
* @param {Adw.PreferencesWindow} window
* @param {Gtk.Builder} builder
*/
_openHiddenSettings(window, builder) {
const hiddenSettingsPage = builder.get_object('hidden_settings');
window.present_subpage(hiddenSettingsPage);
Expand Down
32 changes: 23 additions & 9 deletions tiling-assistant@leleat-on-github/src/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -182,10 +182,18 @@ export class Direction {

static opposite(dir) {
let opposite = 0;
if (dir & this.N) opposite |= this.S;
if (dir & this.S) opposite |= this.N;
if (dir & this.W) opposite |= this.E;
if (dir & this.E) opposite |= this.W;
if (dir & this.N) {
opposite |= this.S;
}
if (dir & this.S) {
opposite |= this.N;
}
if (dir & this.W) {
opposite |= this.E;
}
if (dir & this.E) {
opposite |= this.W;
}

return opposite;
}
Expand Down Expand Up @@ -275,7 +283,9 @@ export class Layout {
*/
validate() {
const rects = this.getItems().map((i) => i.rect);
if (!rects.length) return [false, 'No valid rectangles defined.', -1];
if (!rects.length) {
return [false, 'No valid rectangles defined.', -1];
}

const getOverlapArea = (r1, r2) => {
return (
Expand All @@ -295,23 +305,27 @@ export class Layout {
for (let i = 0; i < rects.length; i++) {
const rect = rects[i];

if (rect.width <= 0 || rect.width > 1)
if (rect.width <= 0 || rect.width > 1) {
return [false, `Rectangle ${i} has an invalid width.`, i];
}

if (rect.height <= 0 || rect.height > 1)
if (rect.height <= 0 || rect.height > 1) {
return [false, `Rectangle ${i} has an invalid height.`, i];
}

if (
rect.x < 0 ||
rect.y < 0 ||
rect.x + rect.width > 1 ||
rect.y + rect.height > 1
)
) {
return [false, `Rectangle ${i} extends beyond the screen.`, i];
}

for (let j = i + 1; j < rects.length; j++) {
if (getOverlapArea(rect, rects[j]) !== 0)
if (getOverlapArea(rect, rects[j]) !== 0) {
return [false, `Rectangles ${i} and ${j} overlap.`, j];
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ import {Meta} from '../gi.js';
export const baseIconSizes = [96, 64, 48, 32, 22];
export const APP_ICON_HOVER_TIMEOUT = 200; // milliseconds

/**
*
* @param {Meta.Workspace} workspace
*/
export function getWindows(workspace) {
// We ignore skip-taskbar windows in switchers, but if they are attached
// to their parent, their position in the MRU list may be more appropriate
Expand Down
Loading

0 comments on commit f537dbd

Please sign in to comment.