Skip to content

Commit

Permalink
V7 / code review changes (#14)
Browse files Browse the repository at this point in the history
* clean up settings & translations, avoid global instance

* avoid using eventhandler instance in global scope

* cleanup / update metadata

* code cleanup
  • Loading branch information
cinatic authored Apr 18, 2022
1 parent ccce679 commit fa94157
Show file tree
Hide file tree
Showing 21 changed files with 178 additions and 762 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,17 @@ const { GObject, St } = imports.gi
const ExtensionUtils = imports.misc.extensionUtils
const Me = ExtensionUtils.getCurrentExtension()

const { Settings } = Me.imports.helpers.settings
const { SettingsHandler } = Me.imports.helpers.settings

var ProjectSelectButtons = GObject.registerClass({}, class ProjectSelectButtons extends St.BoxLayout {
_init () {
super._init({
style_class: 'project-select-buttons'
})

this._settingsChangedId = Settings.connect('changed', (value, key) => {
this._settings = new SettingsHandler()

this._settingsChangedId = this._settings.connect('changed', (value, key) => {
if (key === 'gitlab-accounts' || key === 'selected-gitlab-account-index') {
this._sync()
}
Expand All @@ -29,18 +31,18 @@ var ProjectSelectButtons = GObject.registerClass({}, class ProjectSelectButtons
_createButtons () {
this.destroy_all_children()

const gitlabAccounts = Settings.gitlab_accounts
const gitlabAccounts = this._settings.gitlab_accounts

gitlabAccounts.forEach((gitlabAccount, index) => {
const additionalStyleClasses = index === Settings.selected_gitlab_account_index ? 'active' : ''
const additionalStyleClasses = index === this._settings.selected_gitlab_account_index ? 'active' : ''

const gitlabAccountButton = new St.Button({
style_class: `message button ${additionalStyleClasses}`,
label: gitlabAccount.name
})

gitlabAccountButton.connect('clicked', () => {
Settings.selected_gitlab_account_index = index
this._settings.selected_gitlab_account_index = index
})

this.add_child(gitlabAccountButton)
Expand All @@ -49,7 +51,7 @@ var ProjectSelectButtons = GObject.registerClass({}, class ProjectSelectButtons

_onDestroy () {
if (this._settingsChangedId) {
Settings.disconnect(this._settingsChangedId)
this._settings.disconnect(this._settingsChangedId)
}
}
})
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@ const ExtensionUtils = imports.misc.extensionUtils
const Me = ExtensionUtils.getCurrentExtension()
const { ProjectsScreen } = Me.imports.components.screens.projectsScreen.projectsScreen
const { ProjectDetailsScreen } = Me.imports.components.screens.projectDetailsScreen.projectDetailsScreen
const { EventHandler } = Me.imports.helpers.eventHandler

var ScreenWrapper = GObject.registerClass(
class ScreenWrapper extends St.Widget {
_init () {
_init (mainEventHandler) {
super._init({
style_class: 'screen-wrapper'
})

this._showScreenConnectId = EventHandler.connect('show-screen', (sender, { screen, additionalData }) => this.showScreen(screen, additionalData))
this._mainEventHandler = mainEventHandler
this._showScreenConnectId = this._mainEventHandler.connect('show-screen', (sender, { screen, additionalData }) => this.showScreen(screen, additionalData))

this.showScreen()
}
Expand All @@ -23,12 +23,12 @@ var ScreenWrapper = GObject.registerClass(

switch (screenName) {
case 'project-details':
screen = new ProjectDetailsScreen(additionalData.item)
screen = new ProjectDetailsScreen(additionalData.item, this._mainEventHandler)
break

case 'projects':
default:
screen = new ProjectsScreen()
screen = new ProjectsScreen(this._mainEventHandler)
break
}

Expand All @@ -38,7 +38,7 @@ var ScreenWrapper = GObject.registerClass(

_onDestroy () {
if (this._showScreenConnectId) {
EventHandler.disconnect(this._showScreenConnectId)
this._mainEventHandler.disconnect(this._showScreenConnectId)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,20 @@ const TABS = {
}

var ProjectDetailsScreen = GObject.registerClass({}, class ProjectDetailsScreen extends St.BoxLayout {
_init (projectItem) {
_init (projectItem, mainEventHandler) {
super._init({
style_class: 'screen project-details-screen',
vertical: true
})

this._mainEventHandler = mainEventHandler
this._selectedTab = TABS.COMMITS

this.projectItem = projectItem

const searchBar = new SearchBar({
back_screen_name: 'projects'
back_screen_name: 'projects',
mainEventHandler: this._mainEventHandler
})

// Static Details Header // TODO: don't be lazy and create a own component for it -.-
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,13 @@ const ExtensionUtils = imports.misc.extensionUtils
const Me = ExtensionUtils.getCurrentExtension()

const { clearCache } = Me.imports.helpers.data
const { EventHandler } = Me.imports.helpers.eventHandler
const { FlatList } = Me.imports.components.flatList.flatList
const { ProjectSelectButtons } = Me.imports.components.gitlab.projectSelectButtons
const { ProjectCard } = Me.imports.components.cards.projectCard
const { SearchBar } = Me.imports.components.searchBar.searchBar

const {
Settings,
SettingsHandler,
GITLAB_ACCOUNTS,
SELECTED_GITLAB_ACCOUNT_INDEX
} = Me.imports.helpers.settings
Expand All @@ -26,21 +25,24 @@ const SETTINGS_KEYS_TO_REFRESH = [
]

var ProjectsScreen = GObject.registerClass({}, class ProjectsScreen extends St.BoxLayout {
_init () {
_init (mainEventHandler) {
super._init({
style_class: 'screen projects-screen',
vertical: true
})

this._mainEventHandler = mainEventHandler
this._settings = new SettingsHandler()

this._settingsChangedId = null

const searchBar = new SearchBar()
const searchBar = new SearchBar({ mainEventHandler: this._mainEventHandler })
this._list = new FlatList()

this.add_child(searchBar)

this._projectSelectButtons = new ProjectSelectButtons()
this._projectSelectButtons.visible = Settings.gitlab_accounts.length > 1
this._projectSelectButtons.visible = this._settings.gitlab_accounts.length > 1
this.add_child(this._projectSelectButtons)

this.add_child(this._list)
Expand All @@ -52,15 +54,15 @@ var ProjectsScreen = GObject.registerClass({}, class ProjectsScreen extends St.B

searchBar.connect('text-change', (sender, searchText) => this._filter_results(searchText))

this._settingsChangedId = Settings.connect('changed', (value, key) => {
this._settingsChangedId = this._settings.connect('changed', (value, key) => {
if (SETTINGS_KEYS_TO_REFRESH.includes(key)) {
this._loadData()
}

this._projectSelectButtons.visible = Settings.gitlab_accounts.length > 1
this._projectSelectButtons.visible = this._settings.gitlab_accounts.length > 1
})

this._list.connect('clicked-item', (sender, item) => EventHandler.emit('show-screen', {
this._list.connect('clicked-item', (sender, item) => this._mainEventHandler.emit('show-screen', {
screen: 'project-details',
additionalData: {
item: item.cardItem
Expand Down Expand Up @@ -90,7 +92,7 @@ var ProjectsScreen = GObject.registerClass({}, class ProjectsScreen extends St.B
}

async _loadData () {
if (!Settings.selected_gitlab_account) {
if (!this._settings.selected_gitlab_account) {
this._list.show_error_info(Translations.TOKEN_ERROR)
return
}
Expand Down Expand Up @@ -126,7 +128,7 @@ var ProjectsScreen = GObject.registerClass({}, class ProjectsScreen extends St.B

_onDestroy () {
if (this._settingsChangedId) {
Settings.disconnect(this._settingsChangedId)
this._settings.disconnect(this._settingsChangedId)
}
}
})
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ const Util = imports.misc.util

const Me = ExtensionUtils.getCurrentExtension()

const { EventHandler } = Me.imports.helpers.eventHandler
const { IconButton } = Me.imports.components.buttons.iconButton
const { Translations } = Me.imports.helpers.translations

Expand All @@ -17,12 +16,13 @@ var SearchBar = GObject.registerClass({
'refresh': {}
}
}, class SearchBar extends St.BoxLayout {
_init ({ back_screen_name } = {}) {
_init ({ back_screen_name, mainEventHandler } = {}) {
super._init({
style_class: 'search-bar',
x_expand: true
})

this._mainEventHandler = mainEventHandler
this.back_screen_name = back_screen_name

this._searchAreaBox = this._createSearchArea()
Expand All @@ -45,7 +45,7 @@ var SearchBar = GObject.registerClass({
style_class: 'navigate-back-icon-button',
icon_name: 'go-previous-symbolic',
text: Translations.BACK,
onClick: () => EventHandler.emit('show-screen', { screen: this.back_screen_name })
onClick: () => this._mainEventHandler.emit('show-screen', { screen: this.back_screen_name })
})

searchInputBox.add_child(backIconButton)
Expand Down Expand Up @@ -95,7 +95,7 @@ var SearchBar = GObject.registerClass({
icon_name: 'emblem-system-symbolic',
icon_size: 18,
onClick: () => {
EventHandler.emit('hide-panel')
this._mainEventHandler.emit('hide-panel')
Util.spawn(['gnome-shell-extension-prefs', 'gitlab-extension@infinicode.de'])
}
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const Me = ExtensionUtils.getCurrentExtension()

const { Adw, GdkPixbuf, Gio, GLib, GObject, Gtk } = imports.gi

const { Settings } = Me.imports.helpers.settings
const { SettingsHandler } = Me.imports.helpers.settings
const { Translations } = Me.imports.helpers.translations

var AboutPage = GObject.registerClass({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const Me = ExtensionUtils.getCurrentExtension()

const { Adw, Gio, GObject, Gtk } = imports.gi

const { Settings } = Me.imports.helpers.settings
const { SettingsHandler } = Me.imports.helpers.settings
const { Translations } = Me.imports.helpers.translations

const { NewItemModel } = Me.imports.components.settings.subcomponents.newItemModel
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const Me = ExtensionUtils.getCurrentExtension()

const { Adw, Gio, GObject, Gtk } = imports.gi

const { Settings } = Me.imports.helpers.settings
const { SettingsHandler } = Me.imports.helpers.settings
const { Translations } = Me.imports.helpers.translations

var SettingsPage = GObject.registerClass({
Expand Down Expand Up @@ -32,6 +32,8 @@ class GeneralPreferenceGroup extends Adw.PreferencesGroup {
title: Translations.SETTINGS.TITLE_GENERAL
})

this._settings = new SettingsHandler()

const panelPositions = new Gtk.StringList()
panelPositions.append(Translations.SETTINGS.POSITION_IN_PANEL_LEFT)
panelPositions.append(Translations.SETTINGS.POSITION_IN_PANEL_CENTER)
Expand All @@ -40,11 +42,11 @@ class GeneralPreferenceGroup extends Adw.PreferencesGroup {
const panelPositionRow = new Adw.ComboRow({
title: Translations.SETTINGS.POSITION_IN_PANEL,
model: panelPositions,
selected: Settings.position_in_panel
selected: this._settings.position_in_panel
})

panelPositionRow.connect('notify::selected', (widget) => {
Settings.position_in_panel = widget.selected
this._settings.position_in_panel = widget.selected
})
this.add(panelPositionRow)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const { Gio, GObject } = imports.gi

const { GitlabAccountItem } = Me.imports.components.settings.subcomponents.gitlabAccountItem

const { Settings, GITLAB_ACCOUNTS, DEFAULT_GITLAB_DATA } = Me.imports.helpers.settings
const { SettingsHandler, GITLAB_ACCOUNTS, DEFAULT_GITLAB_DATA } = Me.imports.helpers.settings
const { Translations } = Me.imports.helpers.translations

const SETTING_KEYS_TO_REFRESH = [
Expand All @@ -23,10 +23,12 @@ var GitlabAccountModelList = GObject.registerClass({
constructor () {
super()

this._settings = new SettingsHandler()

this.#items = this.convert_items()

this.#changedId =
Settings.connect('changed', (value, key) => {
this._settings.connect('changed', (value, key) => {
if (!SETTING_KEYS_TO_REFRESH.includes(key)) {
return
}
Expand All @@ -40,7 +42,7 @@ var GitlabAccountModelList = GObject.registerClass({
}

convert_items () {
return Settings.gitlab_accounts.map(item => {
return this._settings.gitlab_accounts.map(item => {
const gitlabAccountItem = new GitlabAccountItem()

gitlabAccountItem.id = item.id || Gio.dbus_generate_guid()
Expand Down Expand Up @@ -129,7 +131,7 @@ var GitlabAccountModelList = GObject.registerClass({
}

save_items () {
Settings.gitlab_accounts = this.#items
this._settings.gitlab_accounts = this.#items
}

vfunc_get_item_type () {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const { Adw, Gdk, Gio, GLib, GObject, Gtk, Pango } = imports.gi
const Gettext = imports.gettext.domain(Me.metadata['gettext-domain'])
const _ = Gettext.gettext

const { Settings, SETTINGS_SCHEMA_DOMAIN } = Me.imports.helpers.settings
const { SettingsHandler, SETTINGS_SCHEMA_DOMAIN } = Me.imports.helpers.settings
const { initTranslations, Translations } = Me.imports.helpers.translations

var GitlabAccountRow = GObject.registerClass({
Expand Down
Loading

0 comments on commit fa94157

Please sign in to comment.