Skip to content

Commit

Permalink
feat: add session only mode. closes #57, #14
Browse files Browse the repository at this point in the history
  • Loading branch information
oae committed Sep 11, 2022
1 parent 6987b44 commit 0fd04be
Show file tree
Hide file tree
Showing 11 changed files with 181 additions and 11 deletions.
10 changes: 9 additions & 1 deletion resources/po/ar.po
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,18 @@ msgstr "اكتب نصًا للبحث عنه"
msgid "Clears the clipboard database and cache"
msgstr "يمحو قاعدة بيانات الحافظة وذاكرتها المؤقتة"

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

#: src/prefs/dangerZone/sessionOnlyMode.ts:13
msgid "Session Only Mode"
msgstr ""

#: src/prefs/dangerZone/sessionOnlyMode.ts:14
msgid "When enabled, Pano will clear all history on logout/restart/shutdown."
msgstr ""

#: src/prefs/general/dbLocation.ts:22
msgid "Database Location"
msgstr "موقع قاعدة البيانات"
Expand Down
10 changes: 9 additions & 1 deletion resources/po/en.po
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,18 @@ msgstr "Type to search"
msgid "Clears the clipboard database and cache"
msgstr "Clears the clipboard database and cache"

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

#: src/prefs/dangerZone/sessionOnlyMode.ts:13
msgid "Session Only Mode"
msgstr "Session Only Mode"

#: src/prefs/dangerZone/sessionOnlyMode.ts:14
msgid "When enabled, Pano will clear all history on logout/restart/shutdown."
msgstr "When enabled, Pano will clear all history on logout/restart/shutdown."

#: src/prefs/general/dbLocation.ts:22
msgid "Database Location"
msgstr "Database Location"
Expand Down
10 changes: 9 additions & 1 deletion resources/po/fr.po
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,18 @@ msgstr "Tapez pour rechercher"
msgid "Clears the clipboard database and cache"
msgstr "Vider la base de données du presse-papiers et le cache"

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

#: src/prefs/dangerZone/sessionOnlyMode.ts:13
msgid "Session Only Mode"
msgstr ""

#: src/prefs/dangerZone/sessionOnlyMode.ts:14
msgid "When enabled, Pano will clear all history on logout/restart/shutdown."
msgstr ""

#: src/prefs/general/dbLocation.ts:22
msgid "Database Location"
msgstr "Emplacement de la base de données"
Expand Down
10 changes: 9 additions & 1 deletion resources/po/hr.po
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,18 @@ msgstr "Upišite za pretragu"
msgid "Clears the clipboard database and cache"
msgstr "Briše bazu podataka međuspremnika i predmemoriju"

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

#: src/prefs/dangerZone/sessionOnlyMode.ts:13
msgid "Session Only Mode"
msgstr ""

#: src/prefs/dangerZone/sessionOnlyMode.ts:14
msgid "When enabled, Pano will clear all history on logout/restart/shutdown."
msgstr ""

#: src/prefs/general/dbLocation.ts:22
msgid "Database Location"
msgstr "Lokacija baze podataka"
Expand Down
10 changes: 9 additions & 1 deletion resources/po/oc.po
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,18 @@ msgstr "Picatz per recercar"
msgid "Clears the clipboard database and cache"
msgstr "Escafa la basa de donadas del quichapapièrs e lo cache"

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

#: src/prefs/dangerZone/sessionOnlyMode.ts:13
msgid "Session Only Mode"
msgstr ""

#: src/prefs/dangerZone/sessionOnlyMode.ts:14
msgid "When enabled, Pano will clear all history on logout/restart/shutdown."
msgstr ""

#: src/prefs/general/dbLocation.ts:22
msgid "Database Location"
msgstr "Emplaçament de la basa de donadas"
Expand Down
10 changes: 9 additions & 1 deletion resources/po/[email protected]
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ msgstr ""
msgid "Clears the clipboard database and cache"
msgstr ""

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

Expand Down Expand Up @@ -116,6 +116,10 @@ msgstr ""
msgid "Select a shortcut"
msgstr ""

#: src/prefs/dangerZone/sessionOnlyMode.ts:13
msgid "Session Only Mode"
msgstr ""

#: src/components/indicator/settingsMenu.ts:74
msgid "Settings"
msgstr ""
Expand All @@ -140,6 +144,10 @@ msgstr ""
msgid "Watch Exclusions"
msgstr ""

#: src/prefs/dangerZone/sessionOnlyMode.ts:14
msgid "When enabled, Pano will clear all history on logout/restart/shutdown."
msgstr ""

#: src/prefs/general/watchExclusions.ts:14
msgid "When enabled, Pano will not track clipboard from excluded apps"
msgstr ""
Expand Down
12 changes: 11 additions & 1 deletion resources/po/tr.po
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,20 @@ msgstr "Aramak için yazın"
msgid "Clears the clipboard database and cache"
msgstr "Pano veritabanını ve önbelleği temizler"

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

#: src/prefs/dangerZone/sessionOnlyMode.ts:13
msgid "Session Only Mode"
msgstr "Şu anki Oturum Modu"

#: src/prefs/dangerZone/sessionOnlyMode.ts:14
msgid "When enabled, Pano will clear all history on logout/restart/shutdown."
msgstr ""
"Etkinleştirildiğinde, Pano oturum kapatma/yeniden başlatma/kapatma sırasında "
"tüm geçmişi temizleyecektir."

#: src/prefs/general/dbLocation.ts:22
msgid "Database Location"
msgstr "Veritabanı Konumu"
Expand Down
5 changes: 5 additions & 0 deletions resources/schemas/org.gnome.shell.extensions.pano.gschema.xml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@
<summary>Offline mode</summary>
<description>When enabled, Pano will not try to connect to internet.</description>
</key>
<key name="session-only-mode" type="b">
<default>false</default>
<summary>Session only mode</summary>
<description>When enabled, Pano will clear all history on logout/restart/shutdown.</description>
</key>
<key name="watch-exclusion-list" type="b">
<default>true</default>
<summary>Watch exclusion list</summary>
Expand Down
81 changes: 78 additions & 3 deletions src/extension.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { DBus, DBusExportedObject, Settings } from '@gi-types/gio2';
import { DBus, DBusExportedObject, DBusSignalFlags, Settings } from '@gi-types/gio2';
import { PRIORITY_DEFAULT, Source, SOURCE_REMOVE, timeout_add } from '@gi-types/glib2';
import { Global } from '@gi-types/shell0';
import { SettingsMenu } from '@pano/components/indicator/settingsMenu';
import { PanoWindow } from '@pano/containers/panoWindow';
import { clipboardManager } from '@pano/utils/clipboardManager';
import { ClipboardContent, clipboardManager, ContentType } from '@pano/utils/clipboardManager';
import { db } from '@pano/utils/db';
import { KeyManager } from '@pano/utils/keyManager';
import {
Expand All @@ -17,7 +18,6 @@ import {
setupAppDirs,
} from '@pano/utils/shell';
import { addTopChrome, addToStatusArea, removeChrome, removeVirtualKeyboard } from '@pano/utils/ui';
import { SettingsMenu } from '@pano/components/indicator/settingsMenu';
import './styles/stylesheet.css';

const debug = logger('extension');
Expand All @@ -31,6 +31,10 @@ class PanoExtension {
private windowTrackerId: number | null;
private timeoutId: number | null;
private settingsMenu: SettingsMenu | null;
private shutdownSignalId: number | null;
private logoutSignalId: number | null;
private rebootSignalId: number | null;
private systemdSignalId: number | null;

constructor() {
setupAppDirs();
Expand Down Expand Up @@ -68,6 +72,23 @@ class PanoExtension {
});
}

async clearSessionHistory() {
if (this.settings.get_boolean('session-only-mode')) {
debug('clearing session history');
db.shutdown();
clipboardManager.stopTracking();
await deleteAppDirs();
debug('deleted session cache and db');
clipboardManager.setContent(
new ClipboardContent({
type: ContentType.TEXT,
value: '',
}),
);
debug('cleared last clipboard content');
}
}

createIndicator() {
if (this.settings.get_boolean('show-indicator')) {
this.settingsMenu = new SettingsMenu(this.clearHistory.bind(this), () => this.panoWindow.toggle());
Expand All @@ -85,6 +106,44 @@ class PanoExtension {
setupAppDirs();
this.createIndicator();
db.start();
this.logoutSignalId = DBus.session.signal_subscribe(
null,
'org.gnome.SessionManager.EndSessionDialog',
'ConfirmedLogout',
'/org/gnome/SessionManager/EndSessionDialog',
null,
DBusSignalFlags.NONE,
this.clearSessionHistory.bind(this),
);

this.rebootSignalId = DBus.session.signal_subscribe(
null,
'org.gnome.SessionManager.EndSessionDialog',
'ConfirmedReboot',
'/org/gnome/SessionManager/EndSessionDialog',
null,
DBusSignalFlags.NONE,
this.clearSessionHistory.bind(this),
);

this.shutdownSignalId = DBus.session.signal_subscribe(
null,
'org.gnome.SessionManager.EndSessionDialog',
'ConfirmedShutdown',
'/org/gnome/SessionManager/EndSessionDialog',
null,
DBusSignalFlags.NONE,
this.clearSessionHistory.bind(this),
);
this.systemdSignalId = DBus.system.signal_subscribe(
null,
'org.freedesktop.login1.Manager',
'PrepareForShutdown',
'/org/freedesktop/login1',
null,
DBusSignalFlags.NONE,
this.clearSessionHistory.bind(this),
);
addTopChrome(this.panoWindow);
this.keyManager.listenFor('shortcut', () => this.panoWindow.toggle());
this.keyManager.listenFor('incognito-shortcut', () => {
Expand Down Expand Up @@ -137,6 +196,22 @@ class PanoExtension {
removeChrome(this.panoWindow);
debug('extension is disabled');
db.shutdown();
if (this.logoutSignalId) {
DBus.session.signal_unsubscribe(this.logoutSignalId);
this.logoutSignalId = null;
}
if (this.shutdownSignalId) {
DBus.session.signal_unsubscribe(this.shutdownSignalId);
this.shutdownSignalId = null;
}
if (this.rebootSignalId) {
DBus.session.signal_unsubscribe(this.rebootSignalId);
this.rebootSignalId = null;
}
if (this.systemdSignalId) {
DBus.system.signal_unsubscribe(this.systemdSignalId);
this.systemdSignalId = null;
}
}

async clearHistory() {
Expand Down
4 changes: 3 additions & 1 deletion src/prefs/dangerZone/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { PreferencesGroup, PreferencesPage } from '@gi-types/adw1';
import { ClearHistoryRow } from '@pano/prefs/dangerZone/clearHistory';
import { SessionOnlyModeRow } from '@pano/prefs/dangerZone/sessionOnlyMode';
import { registerGObjectClass } from '@pano/utils/gjs';
import { _ } from '@pano/utils/shell';
import { ClearHistoryRow } from './clearHistory';

@registerGObjectClass
export class DangerZonePage extends PreferencesPage {
Expand All @@ -12,6 +13,7 @@ export class DangerZonePage extends PreferencesPage {
});

const dangerZoneGroup = new PreferencesGroup();
dangerZoneGroup.add(new SessionOnlyModeRow());
dangerZoneGroup.add(new ClearHistoryRow());

this.add(dangerZoneGroup);
Expand Down
30 changes: 30 additions & 0 deletions src/prefs/dangerZone/sessionOnlyMode.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { ActionRow } from '@gi-types/adw1';
import { Settings, SettingsBindFlags } from '@gi-types/gio2';
import { Align, Switch } from '@gi-types/gtk4';
import { registerGObjectClass } from '@pano/utils/gjs';
import { getCurrentExtensionSettings, _ } from '@pano/utils/shell';

@registerGObjectClass
export class SessionOnlyModeRow extends ActionRow {
private settings: Settings;

constructor() {
super({
title: _('Session Only Mode'),
subtitle: _('When enabled, Pano will clear all history on logout/restart/shutdown.'),
});

this.settings = getCurrentExtensionSettings();

const sessionOnlySwitch = new Switch({
active: this.settings.get_boolean('session-only-mode'),
valign: Align.CENTER,
halign: Align.CENTER,
});

this.settings.bind('session-only-mode', sessionOnlySwitch, 'active', SettingsBindFlags.DEFAULT);

this.add_suffix(sessionOnlySwitch);
this.set_activatable_widget(sessionOnlySwitch);
}
}

0 comments on commit 0fd04be

Please sign in to comment.