Skip to content

Commit

Permalink
V22 / code review changes (#103)
Browse files Browse the repository at this point in the history
* clean translation & settings init

* avoid global settings handler instance

* avoid using global eventhandler instance

* update metadata

* code cleanup
  • Loading branch information
cinatic authored Apr 18, 2022
1 parent 4e4cf26 commit 5f684d5
Show file tree
Hide file tree
Showing 18 changed files with 217 additions and 289 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,20 @@ const Me = ExtensionUtils.getCurrentExtension()

const { isNullOrEmpty } = Me.imports.helpers.data
const { IconButton } = Me.imports.components.buttons.iconButton
const { EventHandler } = Me.imports.helpers.eventHandler
const { TaskPriority } = Me.imports.services.meta.taskWarrior
const { setTaskDone, setTaskUndone, startTask, stopTask } = Me.imports.services.taskService

var TaskCard = GObject.registerClass({
GTypeName: 'TaskWhisperer_TaskCard'
}, class TaskCard extends St.Button {
_init (quoteSummary) {
_init (quoteSummary, mainEventHandler) {
super._init({
style_class: 'card message task-card',
can_focus: true,
x_expand: true
})

this._mainEventHandler = mainEventHandler
this.cardItem = quoteSummary

const vContentBox = new St.BoxLayout({
Expand Down Expand Up @@ -204,26 +204,26 @@ var TaskCard = GObject.registerClass({

async _startTask () {
await startTask(this.cardItem.ID)
EventHandler.emit('refresh-tasks')
this._mainEventHandler.emit('refresh-tasks')
}

async _stopTask () {
await stopTask(this.cardItem.ID)
EventHandler.emit('refresh-tasks')
this._mainEventHandler.emit('refresh-tasks')
}

async _setTaskDone () {
await setTaskDone(this.cardItem.ID)
EventHandler.emit('refresh-tasks')
this._mainEventHandler.emit('refresh-tasks')
}

async _setTaskUnDone () {
await setTaskUndone(this.cardItem.UUID)
EventHandler.emit('refresh-tasks')
this._mainEventHandler.emit('refresh-tasks')
}

_editTask () {
EventHandler.emit('show-screen', {
this._mainEventHandler.emit('show-screen', {
screen: 'edit-task',
additionalData: {
item: this.cardItem
Expand Down
22 changes: 12 additions & 10 deletions taskwhisperer-extension@infinicode.de/components/panel/menuItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ const { Clutter, GObject, St } = imports.gi
const ExtensionUtils = imports.misc.extensionUtils
const Me = ExtensionUtils.getCurrentExtension()

const { EventHandler } = Me.imports.helpers.eventHandler
const { Settings, TASKWHISPERER_SHOW_PANEL_ICON, TASKWHISPERER_SHOW_TEXT_IN_PANEL } = Me.imports.helpers.settings
const { SettingsHandler, TASKWHISPERER_SHOW_PANEL_ICON, TASKWHISPERER_SHOW_TEXT_IN_PANEL } = Me.imports.helpers.settings
const { Translations } = Me.imports.helpers.translations
const ComponentsHelper = Me.imports.helpers.components

Expand All @@ -16,7 +15,7 @@ const SETTING_KEYS_TO_REFRESH = [
var MenuItem = GObject.registerClass({
GTypeName: 'TaskWhisperer_MenuItem'
}, class MenuItem extends St.BoxLayout {
_init () {
_init (mainEventHandler) {
super._init({
style_class: 'menu-item',
x_expand: true,
Expand All @@ -25,15 +24,18 @@ var MenuItem = GObject.registerClass({
y_expand: true,
})

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

this._taskCount = 0

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

this._refreshMenuTaskCountId = EventHandler.connect('refresh-menu-task-count', (_, { taskCount }) => {
this._refreshMenuTaskCountId = this._mainEventHandler.connect('refresh-menu-task-count', (_, { taskCount }) => {
this._taskCount = taskCount
this._sync()
})
Expand All @@ -58,7 +60,7 @@ var MenuItem = GObject.registerClass({
y_align: Clutter.ActorAlign.CENTER
})

if (Settings.show_taskwarrior_icon) {
if (this._settings.show_taskwarrior_icon) {
const icon = new St.Icon({
y_align: Clutter.ActorAlign.CENTER,
y_expand: true,
Expand All @@ -71,10 +73,10 @@ var MenuItem = GObject.registerClass({

let additionalTaskAmountInformationText

if (Settings.show_task_text_in_panel) {
if (this._settings.show_task_text_in_panel) {
additionalTaskAmountInformationText = Translations.PANEL_TASK_INFO(this._taskCount)
} else {
additionalTaskAmountInformationText = Settings.show_taskwarrior_icon ? `${this._taskCount}` : `${this._taskCount} T`
additionalTaskAmountInformationText = this._settings.show_taskwarrior_icon ? `${this._taskCount}` : `${this._taskCount} T`
}

const label = new St.Label({
Expand All @@ -91,11 +93,11 @@ var MenuItem = GObject.registerClass({

_onDestroy () {
if (this._settingsChangedId) {
Settings.disconnect(this._settingsChangedId)
this._settings.disconnect(this._settingsChangedId)
}

if (this._refreshMenuTaskCountId) {
EventHandler.disconnect(this._refreshMenuTaskCountId)
this._mainEventHandler.disconnect(this._refreshMenuTaskCountId)
}
}
})
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,18 @@ const ExtensionUtils = imports.misc.extensionUtils
const Me = ExtensionUtils.getCurrentExtension()
const { TaskOverviewScreen } = Me.imports.components.screens.taskOverviewScreen.taskOverviewScreen
const { EditTaskScreen } = Me.imports.components.screens.editTaskScreen.editTaskScreen
const { EventHandler } = Me.imports.helpers.eventHandler

var ScreenWrapper = GObject.registerClass({
GTypeName: 'TaskWhisperer_ScreenWrapper'
},
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.connect('destroy', this._onDestroy.bind(this))

Expand All @@ -28,12 +28,12 @@ var ScreenWrapper = GObject.registerClass({

switch (screenName) {
case 'edit-task':
screen = new EditTaskScreen(additionalData.item)
screen = new EditTaskScreen(additionalData.item, this._mainEventHandler)
break

case 'overview':
default:
screen = new TaskOverviewScreen()
screen = new TaskOverviewScreen(this._mainEventHandler)
break
}

Expand All @@ -43,7 +43,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 @@ -3,20 +3,20 @@ const { Clutter, GObject, St } = imports.gi
const ExtensionUtils = imports.misc.extensionUtils
const Me = ExtensionUtils.getCurrentExtension()

const { EventHandler } = Me.imports.helpers.eventHandler
const { ButtonGroup } = Me.imports.components.buttons.buttonGroup
const { SearchBar } = Me.imports.components.searchBar.searchBar
const { Translations } = Me.imports.helpers.translations
const { TaskPriority } = Me.imports.services.meta.taskWarrior
const { createTask, modifyTask } = Me.imports.services.taskService

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

this._mainEventHandler = mainEventHandler
this.task = taskItem || {}
this.newTask = {}

Expand All @@ -25,7 +25,8 @@ var EditTaskScreen = GObject.registerClass({}, class EditTaskScreen extends St.B
const searchBar = new SearchBar({
back_screen_name: 'overview',
showFilterInputBox: false,
showRefreshIcon: false
showRefreshIcon: false,
mainEventHandler: this._mainEventHandler
})

this.add_child(searchBar)
Expand Down Expand Up @@ -161,7 +162,7 @@ var EditTaskScreen = GObject.registerClass({}, class EditTaskScreen extends St.B
if (result.error) {
this._errorPlaceHolder.text = result.error
} else {
EventHandler.emit('show-screen', {
this._mainEventHandler.emit('show-screen', {
screen: 'overview'
})
}
Expand Down
Loading

0 comments on commit 5f684d5

Please sign in to comment.