Skip to content

Commit

Permalink
feat: add exclusion support. closes #41
Browse files Browse the repository at this point in the history
  • Loading branch information
oae committed Sep 11, 2022
1 parent dca98a1 commit e66b0c0
Show file tree
Hide file tree
Showing 12 changed files with 150 additions and 49 deletions.
10 changes: 7 additions & 3 deletions resources/po/ar.po
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,19 @@ msgstr "اختر موقع قاعدة بيانات پانو"
msgid "Failed to select directory"
msgstr "فشل اختيار المجلد"

#: src/prefs/general/exclusionGroup.ts:13
#: src/prefs/general/exclusionGroup.ts:16
msgid "Manage Exclusions"
msgstr ""

#: src/prefs/general/exclusionGroup.ts:18
#: src/prefs/general/exclusionGroup.ts:23
msgid "Excluded Apps"
msgstr ""

#: src/prefs/general/exclusionGroup.ts:42
#: src/prefs/general/exclusionGroup.ts:24
msgid "Pano will stop tracking if any window from the list is focussed"
msgstr ""

#: src/prefs/general/exclusionGroup.ts:53
msgid "Window class name"
msgstr ""

Expand Down
22 changes: 13 additions & 9 deletions resources/po/en.po
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ msgstr "Are you sure you want to clear history?"

#: src/prefs/dangerZone/index.ts:10
msgid "Danger Zone"
msgstr ""
msgstr "Danger Zone"

#: src/prefs/general/dbLocation.ts:22
msgid "Database Location"
Expand All @@ -39,21 +39,25 @@ msgstr "Choose pano database location"
msgid "Failed to select directory"
msgstr "Failed to select directory"

#: src/prefs/general/exclusionGroup.ts:13
#: src/prefs/general/exclusionGroup.ts:16
msgid "Manage Exclusions"
msgstr ""
msgstr "Manage Exclusions"

#: src/prefs/general/exclusionGroup.ts:18
#: src/prefs/general/exclusionGroup.ts:23
msgid "Excluded Apps"
msgstr ""
msgstr "Excluded Apps"

#: src/prefs/general/exclusionGroup.ts:24
msgid "Pano will stop tracking if any window from the list is focussed"
msgstr "Pano will stop tracking if any window from the list is focussed"

#: src/prefs/general/exclusionGroup.ts:42
#: src/prefs/general/exclusionGroup.ts:53
msgid "Window class name"
msgstr ""
msgstr "Window class name"

#: src/prefs/general/generalGroup.ts:14
msgid "General Options"
msgstr ""
msgstr "General Options"

#: src/prefs/general/historyLength.ts:13
msgid "History Length"
Expand All @@ -65,7 +69,7 @@ msgstr "You can limit your clipboard history length between 10 - 500"

#: src/prefs/general/index.ts:11
msgid "General"
msgstr ""
msgstr "General"

#: src/prefs/general/pasteOnSelect.ts:13
msgid "Paste on Select"
Expand Down
10 changes: 7 additions & 3 deletions resources/po/fr.po
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,19 @@ msgstr "Choisissez l'emplacement de la base de données pano"
msgid "Failed to select directory"
msgstr "La sélection du répertoire a échouée"

#: src/prefs/general/exclusionGroup.ts:13
#: src/prefs/general/exclusionGroup.ts:16
msgid "Manage Exclusions"
msgstr ""

#: src/prefs/general/exclusionGroup.ts:18
#: src/prefs/general/exclusionGroup.ts:23
msgid "Excluded Apps"
msgstr ""

#: src/prefs/general/exclusionGroup.ts:42
#: src/prefs/general/exclusionGroup.ts:24
msgid "Pano will stop tracking if any window from the list is focussed"
msgstr ""

#: src/prefs/general/exclusionGroup.ts:53
msgid "Window class name"
msgstr ""

Expand Down
10 changes: 7 additions & 3 deletions resources/po/hr.po
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,19 @@ msgstr "Odaberi lokaciju baze podataka panoa"
msgid "Failed to select directory"
msgstr "Neuspjeli odabir direktorija"

#: src/prefs/general/exclusionGroup.ts:13
#: src/prefs/general/exclusionGroup.ts:16
msgid "Manage Exclusions"
msgstr ""

#: src/prefs/general/exclusionGroup.ts:18
#: src/prefs/general/exclusionGroup.ts:23
msgid "Excluded Apps"
msgstr ""

#: src/prefs/general/exclusionGroup.ts:42
#: src/prefs/general/exclusionGroup.ts:24
msgid "Pano will stop tracking if any window from the list is focussed"
msgstr ""

#: src/prefs/general/exclusionGroup.ts:53
msgid "Window class name"
msgstr ""

Expand Down
10 changes: 7 additions & 3 deletions resources/po/oc.po
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,19 @@ msgstr "Causir l'emplaçament de la basa de donadas de pano"
msgid "Failed to select directory"
msgstr "Seleccion del repertòri pas reüssida"

#: src/prefs/general/exclusionGroup.ts:13
#: src/prefs/general/exclusionGroup.ts:16
msgid "Manage Exclusions"
msgstr ""

#: src/prefs/general/exclusionGroup.ts:18
#: src/prefs/general/exclusionGroup.ts:23
msgid "Excluded Apps"
msgstr ""

#: src/prefs/general/exclusionGroup.ts:42
#: src/prefs/general/exclusionGroup.ts:24
msgid "Pano will stop tracking if any window from the list is focussed"
msgstr ""

#: src/prefs/general/exclusionGroup.ts:53
msgid "Window class name"
msgstr ""

Expand Down
10 changes: 7 additions & 3 deletions resources/po/pano@elhan.io.pot
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ msgstr ""
msgid "Database Location"
msgstr ""

#: src/prefs/general/exclusionGroup.ts:18
#: src/prefs/general/exclusionGroup.ts:23
msgid "Excluded Apps"
msgstr ""

Expand All @@ -66,14 +66,18 @@ msgstr ""
msgid "History Length"
msgstr ""

#: src/prefs/general/exclusionGroup.ts:13
#: src/prefs/general/exclusionGroup.ts:16
msgid "Manage Exclusions"
msgstr ""

#: src/prefs/general/shortcutRow.ts:75
msgid "New shortcut"
msgstr ""

#: src/prefs/general/exclusionGroup.ts:24
msgid "Pano will stop tracking if any window from the list is focussed"
msgstr ""

#: src/prefs/general/pasteOnSelect.ts:13
msgid "Paste on Select"
msgstr ""
Expand All @@ -90,7 +94,7 @@ msgstr ""
msgid "Type to search"
msgstr ""

#: src/prefs/general/exclusionGroup.ts:42
#: src/prefs/general/exclusionGroup.ts:53
msgid "Window class name"
msgstr ""

Expand Down
22 changes: 13 additions & 9 deletions resources/po/tr.po
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ msgstr "Geçmişi temizlemek istediğine emin misiniz?"

#: src/prefs/dangerZone/index.ts:10
msgid "Danger Zone"
msgstr ""
msgstr "Tehlikeli bölge"

#: src/prefs/general/dbLocation.ts:22
msgid "Database Location"
Expand All @@ -39,21 +39,25 @@ msgstr "Pano veritabanı konumunu seçin"
msgid "Failed to select directory"
msgstr "Dizin seçilemedi"

#: src/prefs/general/exclusionGroup.ts:13
#: src/prefs/general/exclusionGroup.ts:16
msgid "Manage Exclusions"
msgstr ""
msgstr "Hariç Tutulanları Yönet"

#: src/prefs/general/exclusionGroup.ts:18
#: src/prefs/general/exclusionGroup.ts:23
msgid "Excluded Apps"
msgstr ""
msgstr "Hariç Tutulan Uygulamalar"

#: src/prefs/general/exclusionGroup.ts:24
msgid "Pano will stop tracking if any window from the list is focussed"
msgstr "Listedeki herhangi bir pencereye odaklanılırsa Pano izlemeyi durduracak"

#: src/prefs/general/exclusionGroup.ts:42
#: src/prefs/general/exclusionGroup.ts:53
msgid "Window class name"
msgstr ""
msgstr "Pencere sınıfı adı"

#: src/prefs/general/generalGroup.ts:14
msgid "General Options"
msgstr ""
msgstr "Genel seçenekler"

#: src/prefs/general/historyLength.ts:13
msgid "History Length"
Expand All @@ -65,7 +69,7 @@ msgstr "Pano geçmişi uzunluğunu 10 - 500 arasında sınırlayabilirsin"

#: src/prefs/general/index.ts:11
msgid "General"
msgstr ""
msgstr "Genel"

#: src/prefs/general/pasteOnSelect.ts:13
msgid "Paste on Select"
Expand Down
7 changes: 7 additions & 0 deletions resources/schemas/org.gnome.shell.extensions.pano.gschema.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,12 @@
<summary>Play audio on copy</summary>
<description>Plays an audio when copying a new content.</description>
</key>
<key name="exclusion-list" type="as">
<default>['Bitwarden', '1Password', 'KeePassXC']</default>
<summary>Exclusion list</summary>
<description>
Excludes clipboard tracking for windows that has class name listed in here.
</description>
</key>
</schema>
</schemalist>
27 changes: 27 additions & 0 deletions src/extension.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { DBus, DBusExportedObject, Settings } from '@gi-types/gio2';
import { PRIORITY_DEFAULT, Source, SOURCE_REMOVE, timeout_add } from '@gi-types/glib2';
import { Global } from '@gi-types/shell0';
import { PanoWindow } from '@pano/containers/panoWindow';
import { clipboardManager } from '@pano/utils/clipboardManager';
import { db } from '@pano/utils/db';
Expand All @@ -25,6 +27,8 @@ class PanoExtension {
private isEnabled = false;
private settings: Settings;
private lastDBpath: string;
private windowTrackerId: number | null;
private timeoutId: number | null;

constructor() {
setupAppDirs();
Expand Down Expand Up @@ -66,10 +70,33 @@ class PanoExtension {
this.keyManager.listenFor(this.settings.get_string('shortcut'), () => this.panoWindow.toggle());
});
clipboardManager.startTracking();
this.windowTrackerId = Global.get().display.connect('notify::focus-window', () => {
const wmClass = Global.get().display.focus_window?.get_wm_class();
if (wmClass && (this.settings.get_value('exclusion-list').deep_unpack() as string[]).indexOf(wmClass) >= 0) {
clipboardManager.stopTracking();
} else if (clipboardManager.isTracking === false) {
this.timeoutId = timeout_add(PRIORITY_DEFAULT, 300, () => {
clipboardManager.startTracking();
if (this.timeoutId) {
Source.remove(this.timeoutId);
}
this.timeoutId = null;
return SOURCE_REMOVE;
});
}
});
debug('extension is enabled');
}

disable(): void {
if (this.windowTrackerId) {
Global.get().display.disconnect(this.windowTrackerId);
}
if (this.timeoutId) {
Source.remove(this.timeoutId);
}
this.windowTrackerId = null;
this.timeoutId = null;
removeVirtualKeyboard();
removeSoundContext();
this.isEnabled = false;
Expand Down
33 changes: 31 additions & 2 deletions src/prefs/general/exclusionGroup.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,27 @@
import { ActionRow, ExpanderRow, PreferencesGroup } from '@gi-types/adw1';
import { Settings } from '@gi-types/gio2';
import { Variant } from '@gi-types/glib2';
import { Align, Button, Entry } from '@gi-types/gtk4';
import { registerGObjectClass } from '@pano/utils/gjs';
import { _ } from '@pano/utils/shell';
import { getCurrentExtensionSettings, _ } from '@pano/utils/shell';

@registerGObjectClass
export class ExclusionGroup extends PreferencesGroup {
private exclusionRow: ExpanderRow;
private exclusionButton: Button;
private settings: Settings;

constructor() {
super({
title: _('Manage Exclusions'),
margin_top: 20,
});

this.settings = getCurrentExtensionSettings();

this.exclusionRow = new ExpanderRow({
title: _('Excluded Apps'),
subtitle: _('Pano will stop tracking if any window from the list is focussed'),
});

this.exclusionButton = new Button({
Expand All @@ -33,6 +39,11 @@ export class ExclusionGroup extends PreferencesGroup {

this.set_header_suffix(this.exclusionButton);
this.add(this.exclusionRow);
const savedWindowClasses = this.settings.get_value('exclusion-list').deep_unpack() as string[];
savedWindowClasses.forEach((w) => this.exclusionRow.add_row(this.createExcludedApp(w)));
if (savedWindowClasses.length > 0) {
this.exclusionRow.set_expanded(true);
}
}

private createEntryRow(): ActionRow {
Expand All @@ -59,11 +70,22 @@ export class ExclusionGroup extends PreferencesGroup {
okButton.connect('clicked', () => {
if (entry.get_text().trim()) {
this.exclusionRow.remove(entryRow);
this.exclusionRow.add_row(this.createExcludedApp(entry.get_text()));
this.exclusionRow.add_row(this.createExcludedApp(entry.get_text().trim()));
this.exclusionButton.set_sensitive(true);
this.settings.set_value(
'exclusion-list',
new Variant('as', [
...(this.settings.get_value('exclusion-list').deep_unpack() as string[]),
entry.get_text().trim(),
]),
);
}
});

entry.connect('activate', () => {
okButton.emit('clicked');
});

const cancelButton = new Button({
css_classes: ['flat'],
icon_name: 'window-close-symbolic',
Expand Down Expand Up @@ -96,6 +118,13 @@ export class ExclusionGroup extends PreferencesGroup {
});
removeButton.connect('clicked', () => {
this.exclusionRow.remove(excludedRow);
this.settings.set_value(
'exclusion-list',
new Variant(
'as',
(this.settings.get_value('exclusion-list').deep_unpack() as string[]).filter((w) => w !== appClassName),
),
);
});

excludedRow.add_suffix(removeButton);
Expand Down
2 changes: 1 addition & 1 deletion src/prefs/prefs.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { PreferencesWindow } from '@gi-types/adw1';
import { initTranslations, logger } from '@pano/utils/shell';
import { DangerZonePage } from '@pano/prefs/dangerZone';
import { GeneralPage } from '@pano/prefs/general';
import { initTranslations, logger } from '@pano/utils/shell';

const debug = logger('prefs');
const init = (): void => {
Expand Down
Loading

0 comments on commit e66b0c0

Please sign in to comment.