Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
98 changes: 85 additions & 13 deletions src/util/classes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export interface Rule {
type: 'regex' | 'none';
regex?: string;
ignore_case?: boolean;
select_keys?: string[];
}

export interface Category {
Expand All @@ -23,26 +24,68 @@ export interface Category {
children?: Category[];
}

const COLOR_UNCAT = '#CCC';
const COLOR_GREEN = '#0F0',
COLOR_SUPER_GREEN = '#54e346',
COLOR_BRIGHT_GREEN = '#A8FC00',
COLOR_UNCAT = '#CCC',
COLOR_YELLOW = '#FCC400',
COLOR_SLIGHTLY_YELLOW = '#f5ff65',
COLOR_ORANGE = '#ffba47',
COLOR_RED = '#F80';
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Red is orange now? Previous red was #F33.

Suggested change
COLOR_RED = '#F80';
COLOR_RED = '#F33';


// The default categories
// Should be run through createMissingParents before being used in most cases.
export const defaultCategories: Category[] = [
{
name: ['Work'],
rule: { type: 'regex', regex: 'Google Docs|libreoffice|ReText' },
data: { color: '#0F0' },
Comment on lines -32 to -34
Copy link
Copy Markdown
Member

@ErikBjare ErikBjare Dec 23, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better to keep this parent-category explicit imo. Even if without a rule, such that children inherit color and don't need to be set explicitly for each child.

name: ['Work', 'Writing'],
rule: { type: 'regex', regex: 'Google Docs|Google Sheets|libreoffice|ReText' },
data: { color: COLOR_GREEN },
},
{
name: ['Work', 'Writing'],
rule: {
type: 'regex',
select_keys: ['app'],
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So this is set, but there is no way to change it in the UI?

All select_keys should probably be removed from the default categories until the UI supports it.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that's right.

You can't set them via the UI, but you can import a config file which contains them. I think we should add select_keys to the default config since you can 'export, modify, import' and to mutate these keys and it makes it more explicit how we are deciding which app is in use.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But that's very confusing for the user. They have no indication there is even a select_keys for those categories, right? (unless they export and inspect)

I really don't want to add this specifier to the default rules without:

  1. UI support for it
  2. More thorough testing of these new "multi-rule" categories in the UI.
    • What happens in the UI if a category with multiple rules has children?
    • What happens when you rename a category with multiple rules? Or assign it to a different parent?
    • What happens to color keys when you have multiple rules?
    • Ideally, a category with multiple rules should be listed only once in the category tree, with an indication that there are multiple rules for this one category (without listing it as two seperate categories, since that's likely to get confusing).

regex: 'LibreOffice|TextEdit|MacDown|Obsidian|TextEdit',
},
data: { color: COLOR_GREEN },
},
{
name: ['Work', 'General'],
rule: {
type: 'regex',
regex: 'Preview|Finder|Todoist|1Password|Soulver|System Preferences|VNC Viewer|Streaks',
select_keys: ['app'],
},
data: { color: COLOR_SLIGHTLY_YELLOW },
Comment on lines +52 to +60
Copy link
Copy Markdown
Member

@ErikBjare ErikBjare Dec 23, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
},
{
name: ['Work', 'General'],
rule: {
type: 'regex',
regex: 'Preview|Finder|Todoist|1Password|Soulver|System Preferences|VNC Viewer|Streaks',
select_keys: ['app'],
},
data: { color: COLOR_SLIGHTLY_YELLOW },

Sorry, but I don't like this as a default category. It's too broad to be generally useful, imo. Better to leave underspecified stuff like this up to the user (or if one would keep it, it would belong better in the parent category 'Work', such that child-categories can override).

},
{
name: ['Work', 'Programming'],
rule: {
type: 'regex',
regex: 'GitHub|Stack Overflow|BitBucket|Gitlab|vim|Spyder|kate|Ghidra|Scite',
regex:
'GitHub|Stack Overflow|BitBucket|Gitlab|vim|Spyder|kate|iTerm|Hyper|Alacritty|Script Editor|Ghidra|Scite|jetbrains-idea|jetbrains-pycharm',
},
data: { color: COLOR_SUPER_GREEN },
},
{
name: ['Work', 'Programming'],
rule: { type: 'regex', select_keys: ['url'], regex: 'github.com' },
data: { color: COLOR_SUPER_GREEN },
},
Comment on lines +71 to +75
Copy link
Copy Markdown
Member

@ErikBjare ErikBjare Feb 8, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does having several category rules with the same name work correctly in the web UI? (editing etc)

Seems redundant to specify data several times (how would collisions/differences be handled?).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It does seem to work from my testing!

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This rule will only work in those cases where there is a url set on events at all (only on macOS), which makes me not want this as a default rule (esp with the "hidden" select_keys specifier).

I think it will be very confusing to users which would expect this to work, given it's a default, but for most users it won't (and without a select_keys UI, it would be a mystery why it doesn't work if they were to e.g. edit it).

{
name: ['Work', 'Programming'],
rule: {
type: 'regex',
select_keys: ['app'],
regex: 'Code|Sublime Text|TextMate|iTerm|Script Editor|Base|Postico|Sequel Ace',
},
data: { color: COLOR_SUPER_GREEN },
},
{
name: ['Work', 'Programming', 'ActivityWatch'],
rule: { type: 'regex', regex: 'ActivityWatch|aw-', ignore_case: true },
data: { color: COLOR_SUPER_GREEN },
},
{ name: ['Work', 'Image'], rule: { type: 'regex', regex: 'Gimp|Inkscape' } },
{ name: ['Work', 'Video'], rule: { type: 'regex', regex: 'Kdenlive' } },
Expand All @@ -51,30 +94,39 @@ export const defaultCategories: Category[] = [
{
name: ['Media', 'Games'],
rule: { type: 'regex', regex: 'Minecraft|RimWorld' },
data: { color: '#F80' },
data: { color: COLOR_RED },
Comment on lines -54 to +97
Copy link
Copy Markdown
Member

@ErikBjare ErikBjare Feb 8, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was orange, now red (intentional/improvement?)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
data: { color: '#F80' },
data: { color: COLOR_RED },
data: { color: COLOR_ORANGE },

},
{
name: ['Media', 'Video'],
rule: { type: 'regex', regex: 'YouTube|Plex|VLC' },
data: { color: '#F33' },
data: { color: COLOR_RED },
Comment on lines -59 to +102
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was a dimmer/desaturated red, now a darker/saturated red. Worse contrast with the black text.

},
{
name: ['Media', 'Social Media'],
rule: {
type: 'regex',
regex: 'reddit|Facebook|Twitter|Instagram|devRant',
regex: 'reddit|Facebook|Twitter|Instagram|devRant|LinkedIn',
ignore_case: true,
},
data: { color: '#FCC400' },
data: { color: COLOR_YELLOW },
},
{
name: ['Media', 'Podcasts'],
rule: {
type: 'regex',
regex: 'Podcasts',
select_keys: ['app'],
},
data: { color: COLOR_BRIGHT_GREEN },
},
{
name: ['Media', 'Music'],
rule: {
type: 'regex',
regex: 'Spotify|Deezer',
regex: 'Spotify|Deezer|Amazon Music',
ignore_case: true,
},
data: { color: '#A8FC00' },
data: { color: COLOR_BRIGHT_GREEN },
},
{
name: ['Comms'],
Expand All @@ -85,10 +137,29 @@ export const defaultCategories: Category[] = [
name: ['Comms', 'IM'],
rule: {
type: 'regex',
regex: 'Messenger|Telegram|Signal|WhatsApp|Rambox|Slack|Riot|Element|Discord|Nheko',
regex:
'Messenger|Messages|Discord|Telegram|Signal|WhatsApp|Rambox|Slack|Riot|Element|Discord|Textual|Nheko|Texts',
},
data: { color: COLOR_ORANGE },
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why override the #9FF comms color with something very different?

Suggested change
data: { color: COLOR_ORANGE },

},
{
name: ['Comms', 'Email'],
rule: { type: 'regex', regex: 'Gmail|Thunderbird|mutt|alpine' },
data: { color: COLOR_ORANGE },
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above.

Suggested change
data: { color: COLOR_ORANGE },

},
{
name: ['Comms', 'Meetings'],
rule: { type: 'regex', regex: 'Zoom|Calendar|Cron' },
data: { color: COLOR_SLIGHTLY_YELLOW },
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
data: { color: COLOR_SLIGHTLY_YELLOW },

},
{
name: ['Web Browsing'],
rule: {
type: 'regex',
regex: 'Chrome|Safari|FireFox|Brave',
select_keys: ['app'],
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
select_keys: ['app'],

},
},
{ name: ['Comms', 'Email'], rule: { type: 'regex', regex: 'Gmail|Thunderbird|mutt|alpine' } },
{ name: ['Uncategorized'], rule: { type: null }, data: { color: COLOR_UNCAT } },
];

Expand Down Expand Up @@ -197,6 +268,7 @@ function pickDeepest(categories: Category[]) {
return _.maxBy(categories, c => c.name.length);
}

// TODO this is only used colorize the categories, all categorization is done on the backend
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// TODO this is only used colorize the categories, all categorization is done on the backend
// NOTE: this is only used to colorize the categories, all actual categorization is done on the backend

export function matchString(str: string, categories: Category[] | null): Category | null {
if (!categories) {
console.log(
Expand Down