[gnome-sound-recorder/wip/cdavis/typescript] general: Use explicit public and private access modifiers
- From: Christopher Davis <christopherdavis src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-sound-recorder/wip/cdavis/typescript] general: Use explicit public and private access modifiers
- Date: Tue, 9 Aug 2022 16:10:18 +0000 (UTC)
commit 242ae09529c7be6010a2d86526d926e8ff488e2b
Author: Christopher Davis <christopherdavis gnome org>
Date: Tue Aug 9 11:06:00 2022 -0400
general: Use explicit public and private access modifiers
Previously we had a convention of using underscores to denote
that a field or function was private. However, this convention
was merely a soft guide that wasn't enforced by anything.
In practice this meant that some fields that should have been
marked as private weren't, and fields that were marked as private
were used outside of their intended files.
As part of the shift to TypeScript, which aims to use hard rules
to enforce conventions, we can adopt these access modifiers and
use them to clean up our code a bit. Where appropriate we've removed
the underscores on fields and functions and prepended access
modifiers appropriate for their use. The addition of these modifiers
allow us to know if a private field isn't in use, meaning that
we can clean up some dead fields.
We still use underscores in two scenarios:
* Fields generated by GObject.registerClass() use the underscore
convention. In order for us to align our TypeScript code we need
to continue using underscores for them when we declare them.
* Private fields that have public accessors still use underscores.
src/application.ts | 12 +++----
src/meson.build | 15 ++++++++
src/recorder.ts | 74 +++++++++++++++++++-------------------
src/recorderWidget.ts | 28 +++++++--------
src/recording.ts | 52 +++++++++++++--------------
src/recordingList.ts | 34 +++++++++---------
src/recordingListWidget.ts | 50 +++++++++++++-------------
src/row.ts | 89 +++++++++++++++++++++++-----------------------
src/waveform.ts | 66 +++++++++++++++++-----------------
src/window.ts | 76 +++++++++++++++++++--------------------
10 files changed, 254 insertions(+), 242 deletions(-)
---
diff --git a/src/application.ts b/src/application.ts
index 64acfaf..52f12e7 100644
--- a/src/application.ts
+++ b/src/application.ts
@@ -58,7 +58,7 @@ export const Application = GObject.registerClass(class Application extends Adw.A
});
}
- _initAppMenu(): void {
+ private initAppMenu(): void {
const profileAction = Settings.create_action('audio-profile');
this.add_action(profileAction);
@@ -66,7 +66,7 @@ export const Application = GObject.registerClass(class Application extends Adw.A
this.add_action(channelAction);
const aboutAction = new Gio.SimpleAction({ name: 'about' });
- aboutAction.connect('activate', this._showAbout.bind(this));
+ aboutAction.connect('activate', this.showAbout.bind(this));
this.add_action(aboutAction);
const quitAction = new Gio.SimpleAction({ name: 'quit' });
@@ -95,7 +95,7 @@ export const Application = GObject.registerClass(class Application extends Adw.A
this.set_accels_for_action('recording.export', ['<Primary>s']);
}
- vfunc_startup(): void {
+ public vfunc_startup(): void {
super.vfunc_startup();
log('Sound Recorder (%s)'.format(pkg.name));
log('Version: %s'.format(pkg.version));
@@ -111,17 +111,17 @@ export const Application = GObject.registerClass(class Application extends Adw.A
console.error(`Failed to create directory ${e}`);
}
}
- this._initAppMenu();
+ this.initAppMenu();
}
- vfunc_activate(): void {
+ public vfunc_activate(): void {
this.window = new Window({ application: this });
if (pkg.name.endsWith('Devel'))
this.window.add_css_class('devel');
this.window.show();
}
- _showAbout(): void {
+ private showAbout(): void {
let appName = GLib.get_application_name();
if (!appName)
appName = _('Sound Recorder');
diff --git a/src/meson.build b/src/meson.build
index df60098..d0f735c 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -14,11 +14,26 @@ app = configure_file(
configuration: app_conf
)
+sources = files(
+ 'application.ts',
+ 'main.ts',
+ 'recorder.ts',
+ 'recorderWidget.ts',
+ 'recording.ts',
+ 'recordingList.ts',
+ 'recordingListWidget.ts',
+ 'row.ts',
+ 'utils.ts',
+ 'waveform.ts',
+ 'window.ts',
+)
+
tsc = find_program('tsc', required: true)
tsc_out = meson.project_build_root() / 'tsc-out'
typescript = custom_target(
'typescript-compile',
+ input: sources,
build_by_default: true,
build_always_stale: true,
command: [ tsc, '--outDir', tsc_out ],
diff --git a/src/recorder.ts b/src/recorder.ts
index ee61231..fd31eba 100644
--- a/src/recorder.ts
+++ b/src/recorder.ts
@@ -81,24 +81,24 @@ export const Recorder = GObject.registerClass({
0.0, 1.0, 0.0),
},
}, class Recorder extends GObject.Object {
- _peaks: number[];
+ private peaks: number[];
- _duration!: number;
- _current_peak!: number;
+ private _duration!: number;
+ private _current_peak!: number;
- pipeline: Gst.Pipeline;
- level?: Gst.Element;
- ebin?: Gst.Element;
- filesink?: Gst.Element;
- recordBus?: Gst.Bus | null;
- handlerId?: number | null;
- file?: Gio.File;
- timeout?: number | null;
- _pipeState?: Gst.State;
+ private pipeline: Gst.Pipeline;
+ private level?: Gst.Element;
+ private ebin?: Gst.Element;
+ private filesink?: Gst.Element;
+ private recordBus?: Gst.Bus | null;
+ private handlerId?: number | null;
+ private file?: Gio.File;
+ private timeout?: number | null;
+ private pipeState?: Gst.State;
constructor() {
super();
- this._peaks = [];
+ this.peaks = [];
let srcElement: Gst.Element;
let audioConvert: Gst.Element;
@@ -126,7 +126,7 @@ export const Recorder = GObject.registerClass({
audioConvert.link_filtered(this.level, caps);
}
- start(): void {
+ public start(): void {
let index = 1;
do {
@@ -139,12 +139,12 @@ export const Recorder = GObject.registerClass({
this.recordBus.add_signal_watch();
this.handlerId = this.recordBus.connect('message', (_, message: Gst.Message) => {
if (message)
- this._onMessageReceived(message);
+ this.onMessageReceived(message);
});
if (this.ebin && this.level && this.filesink) {
- this.ebin.set_property('profile', this._getProfile());
+ this.ebin.set_property('profile', this.getProfile());
this.filesink.set_property('location', this.file.get_path());
this.level.link(this.ebin);
this.ebin.link(this.filesink);
@@ -160,16 +160,16 @@ export const Recorder = GObject.registerClass({
});
}
- pause(): void {
+ public pause(): void {
this.state = Gst.State.PAUSED;
}
- resume(): void {
+ public resume(): void {
if (this.state === Gst.State.PAUSED)
this.state = Gst.State.PLAYING;
}
- stop(): RecordingClass | undefined {
+ public stop(): RecordingClass | undefined {
this.state = Gst.State.NULL;
this.duration = 0;
if (this.timeout) {
@@ -185,17 +185,17 @@ export const Recorder = GObject.registerClass({
}
- if (this.file && this.file.query_exists(null) && this._peaks.length > 0) {
+ if (this.file && this.file.query_exists(null) && this.peaks.length > 0) {
const recording = new Recording(this.file);
- recording.peaks = this._peaks.slice();
- this._peaks.length = 0;
+ recording.peaks = this.peaks.slice();
+ this.peaks.length = 0;
return recording;
}
return undefined;
}
- _onMessageReceived(message: Gst.Message): void {
+ private onMessageReceived(message: Gst.Message): void {
switch (message.type) {
case Gst.MessageType.ELEMENT: {
if (GstPbutils.is_missing_plugin_message(message)) {
@@ -231,12 +231,12 @@ export const Recorder = GObject.registerClass({
}
}
- _getChannel(): number {
+ private _getChannel(): number {
const channelIndex = Settings.get_enum('audio-channel');
return AudioChannels[channelIndex].channels;
}
- _getProfile(): GstPbutils.EncodingContainerProfile | undefined {
+ private getProfile(): GstPbutils.EncodingContainerProfile | undefined {
const profileIndex = Settings.get_enum('audio-profile');
const profile = EncodingProfiles[profileIndex];
@@ -256,40 +256,40 @@ export const Recorder = GObject.registerClass({
return undefined;
}
- get duration(): number {
+ public get duration(): number {
return this._duration;
}
- set duration(val: number) {
+ public set duration(val: number) {
this._duration = val;
this.notify('duration');
}
// eslint-disable-next-line camelcase
- get current_peak(): number {
+ public get current_peak(): number {
return this._current_peak;
}
// eslint-disable-next-line camelcase
- set current_peak(peak: number) {
- if (this._peaks) {
+ public set current_peak(peak: number) {
+ if (this.peaks) {
if (peak > 0)
peak = 0;
this._current_peak = Math.pow(10, peak / 20);
- this._peaks.push(this._current_peak);
+ this.peaks.push(this._current_peak);
this.notify('current-peak');
}
}
- get state(): Gst.State | undefined {
- return this._pipeState;
+ public get state(): Gst.State | undefined {
+ return this.pipeState;
}
- set state(s: Gst.State | undefined) {
- this._pipeState = s;
- if (this._pipeState) {
- const ret = this.pipeline.set_state(this._pipeState);
+ public set state(s: Gst.State | undefined) {
+ this.pipeState = s;
+ if (this.pipeState) {
+ const ret = this.pipeline.set_state(this.pipeState);
if (ret === Gst.StateChangeReturn.FAILURE)
log('Unable to update the recorder pipeline state');
diff --git a/src/recorderWidget.ts b/src/recorderWidget.ts
index 2e486fe..ce251d2 100644
--- a/src/recorderWidget.ts
+++ b/src/recorderWidget.ts
@@ -29,15 +29,15 @@ export const RecorderWidget = GObject.registerClass({
'stopped': { param_types: [GObject.TYPE_OBJECT] },
},
}, class RecorderWidget extends Gtk.Box {
- _recorderBox!: Gtk.Box;
- _playbackStack!: Gtk.Stack;
- _recorderTime!: Gtk.Label;
- _pauseBtn!: Gtk.Button;
- _resumeBtn!: Gtk.Button;
+ private _recorderBox!: Gtk.Box;
+ private _playbackStack!: Gtk.Stack;
+ private _recorderTime!: Gtk.Label;
+ private _pauseBtn!: Gtk.Button;
+ private _resumeBtn!: Gtk.Button;
- recorder: RecorderClass;
- waveform: WaveFormClass;
- actionsGroup: Gio.SimpleActionGroup;
+ private recorder: RecorderClass;
+ private waveform: WaveFormClass;
+ public actionsGroup: Gio.SimpleActionGroup;
constructor(recorder: RecorderClass) {
super();
@@ -76,7 +76,7 @@ export const RecorderWidget = GObject.registerClass({
startAction.bind_property('enabled', cancelAction, 'enabled', GObject.BindingFlags.INVERT_BOOLEAN);
}
- onPause(): void {
+ private onPause(): void {
this._playbackStack.visible_child_name = 'recorder-start';
this.state = RecorderState.Paused;
@@ -84,7 +84,7 @@ export const RecorderWidget = GObject.registerClass({
this.emit('paused');
}
- onResume(): void {
+ private onResume(): void {
this._playbackStack.visible_child_name = 'recorder-pause';
this.state = RecorderState.Recording;
@@ -92,7 +92,7 @@ export const RecorderWidget = GObject.registerClass({
this.emit('resumed');
}
- onStart(): void {
+ private onStart(): void {
this._playbackStack.visible_child_name = 'recorder-pause';
this.state = RecorderState.Recording;
@@ -100,7 +100,7 @@ export const RecorderWidget = GObject.registerClass({
this.emit('started');
}
- onCancel(): void {
+ private onCancel(): void {
this.onPause();
const dialog = new Gtk.MessageDialog({
modal: true,
@@ -139,14 +139,14 @@ export const RecorderWidget = GObject.registerClass({
dialog.show();
}
- onStop(): void {
+ private onStop(): void {
this.state = RecorderState.Stopped;
const recording = this.recorder.stop();
this.waveform.destroy();
this.emit('stopped', recording);
}
- set state(recorderState: RecorderState) {
+ public set state(recorderState: RecorderState) {
const pauseAction = this.actionsGroup.lookup('pause') as Gio.SimpleAction;
const resumeAction = this.actionsGroup.lookup('resume') as Gio.SimpleAction;
const startAction = this.actionsGroup.lookup('start') as Gio.SimpleAction;
diff --git a/src/recording.ts b/src/recording.ts
index 5d08df0..62413c1 100644
--- a/src/recording.ts
+++ b/src/recording.ts
@@ -28,22 +28,22 @@ export const Recording = GObject.registerClass({
''),
},
}, class Recording extends GObject.Object {
- _file: Gio.File;
- _peaks: number[];
- _loadedPeaks: number[];
- _extension?: string;
- _timeModified: GLib.DateTime;
- _timeCreated: GLib.DateTime;
- _duration?: number;
+ private _file: Gio.File;
+ private _peaks: number[];
+ private loadedPeaks: number[];
+ private _extension?: string;
+ private _timeModified: GLib.DateTime;
+ private _timeCreated: GLib.DateTime;
+ private _duration?: number;
- pipeline?: Gst.Bin | null;
+ public pipeline?: Gst.Bin | null;
constructor(file: Gio.File) {
super();
this._file = file;
this._peaks = []
- this._loadedPeaks = [];
+ this.loadedPeaks = [];
const info = file.query_info('time::created,time::modified,standard::content-type', 0, null);
const contentType = info.get_attribute_string('standard::content-type');
@@ -71,46 +71,46 @@ export const Recording = GObject.registerClass({
discoverer.discover_uri_async(this.uri);
}
- get name(): string | null {
+ public get name(): string | null {
return this._file.get_basename();
}
- set name(filename: string | null) {
+ public set name(filename: string | null) {
if (filename && filename !== this.name) {
this._file = this._file.set_display_name(filename, null);
this.notify('name');
}
}
- get extension(): string | undefined {
+ public get extension(): string | undefined {
return this._extension;
}
- get timeModified(): GLib.DateTime {
+ public get timeModified(): GLib.DateTime {
return this._timeModified;
}
- get timeCreated(): GLib.DateTime {
+ public get timeCreated(): GLib.DateTime {
return this._timeCreated;
}
- get duration(): number {
+ public get duration(): number {
if (this._duration)
return this._duration;
else
return 0;
}
- get file(): Gio.File {
+ public get file(): Gio.File {
return this._file;
}
- get uri(): string {
+ public get uri(): string {
return this._file.get_uri();
}
// eslint-disable-next-line camelcase
- set peaks(data: number[]) {
+ public set peaks(data: number[]) {
if (data.length > 0) {
this._peaks = data;
this.emit('peaks-updated');
@@ -124,16 +124,16 @@ export const Recording = GObject.registerClass({
}
// eslint-disable-next-line camelcase
- get peaks(): number[] {
+ public get peaks(): number[] {
return this._peaks;
}
- delete(): void {
+ public delete(): void {
this._file.trash_async(GLib.PRIORITY_HIGH, null, null);
this.waveformCache.trash_async(GLib.PRIORITY_DEFAULT, null, null);
}
- save(dest: Gio.File): void {
+ public save(dest: Gio.File): void {
this.file.copy_async(dest, // @ts-expect-error TypeScript isn't reading async function params
correctly
Gio.FileCreateFlags.NONE, GLib.PRIORITY_DEFAULT, null, null, (obj: Gio.File, res:
Gio.AsyncResult) => {
if (obj.copy_finish(res))
@@ -141,11 +141,11 @@ export const Recording = GObject.registerClass({
});
}
- get waveformCache(): Gio.File {
+ public get waveformCache(): Gio.File {
return CacheDir.get_child(`${this.name}_data`);
}
- loadPeaks(): void {
+ public loadPeaks(): void {
if (this.waveformCache.query_exists(null)) {
this.waveformCache.load_bytes_async(null, (obj: Gio.File | null, res: Gio.AsyncResult) => {
const bytes = obj?.load_bytes_finish(res)[0];
@@ -168,7 +168,7 @@ export const Recording = GObject.registerClass({
}
}
- generatePeaks(): void {
+ private generatePeaks(): void {
this.pipeline = Gst.parse_launch('uridecodebin name=uridecodebin ! audioconvert !
audio/x-raw,channels=1 ! level name=level ! fakesink name=faked') as Gst.Bin;
@@ -192,13 +192,13 @@ export const Recording = GObject.registerClass({
if (peakVal) {
const peak = peakVal.get_nth(0) as number;
- this._loadedPeaks.push(Math.pow(10, peak / 20));
+ this.loadedPeaks.push(Math.pow(10, peak / 20));
}
}
break;
}
case Gst.MessageType.EOS:
- this.peaks = this._loadedPeaks;
+ this.peaks = this.loadedPeaks;
this.pipeline?.set_state(Gst.State.NULL);
this.pipeline = null;
break;
diff --git a/src/recordingList.ts b/src/recordingList.ts
index d12edff..08940bc 100644
--- a/src/recordingList.ts
+++ b/src/recordingList.ts
@@ -9,10 +9,10 @@ import { Recording, RecordingClass } from './recording.js';
export type RecordingListClass = InstanceType<typeof RecordingList>;
export const RecordingList = GObject.registerClass(class RecordingList extends Gio.ListStore {
- _enumerator?: Gio.FileEnumerator;
+ private enumerator?: Gio.FileEnumerator;
- cancellable: Gio.Cancellable;
- dirMonitor: Gio.FileMonitor;
+ public cancellable: Gio.Cancellable;
+ public dirMonitor: Gio.FileMonitor;
constructor() {
super();
@@ -39,12 +39,12 @@ export const RecordingList = GObject.registerClass(class RecordingList extends G
Gio.FileQueryInfoFlags.NOFOLLOW_SYMLINKS,
GLib.PRIORITY_LOW,
this.cancellable,
- this._enumerateDirectory.bind(this));
+ this.enumerateDirectory.bind(this));
this.copyOldFiles();
}
- copyOldFiles(): void {
+ private copyOldFiles(): void {
// Necessary code to move old recordings into the new location for few releases
// FIXME: Remove by 3.40/3.42
const oldDir = Gio.file_new_for_path(GLib.build_filenamev([GLib.get_home_dir(), _('Recordings')]));
@@ -56,11 +56,11 @@ export const RecordingList = GObject.registerClass(class RecordingList extends G
const allCopied = true;
fileEnumerator.next_files_async(5, GLib.PRIORITY_LOW, this.cancellable, (obj, res) => {
- this._copyFiles(obj, res, allCopied);
+ this.copyFiles(obj, res, allCopied);
});
}
- _copyFiles(fileEnumerator: Gio.FileEnumerator | null, res: Gio.AsyncResult, allCopied: boolean) {
+ private copyFiles(fileEnumerator: Gio.FileEnumerator | null, res: Gio.AsyncResult, allCopied: boolean) {
const oldDir = fileEnumerator?.container;
try {
const fileInfos = fileEnumerator?.next_files_finish(res);
@@ -91,7 +91,7 @@ export const RecordingList = GObject.registerClass(class RecordingList extends G
});
fileEnumerator?.next_files_async(5, GLib.PRIORITY_LOW, this.cancellable, (obj, res) => {
- this._copyFiles(obj, res, allCopied);
+ this.copyFiles(obj, res, allCopied);
});
} else {
fileEnumerator?.close(this.cancellable);
@@ -116,16 +116,16 @@ export const RecordingList = GObject.registerClass(class RecordingList extends G
}
}
- _enumerateDirectory(obj: Gio.File | null, res: Gio.AsyncResult): void {
- this._enumerator = obj?.enumerate_children_finish(res);
- if (this._enumerator === null) {
+ private enumerateDirectory(obj: Gio.File | null, res: Gio.AsyncResult): void {
+ this.enumerator = obj?.enumerate_children_finish(res);
+ if (this.enumerator === null) {
log('The contents of the Recordings directory were not indexed.');
return;
}
- this._enumerator?.next_files_async(5, GLib.PRIORITY_LOW, this.cancellable,
this._onNextFiles.bind(this));
+ this.enumerator?.next_files_async(5, GLib.PRIORITY_LOW, this.cancellable,
this.onNextFiles.bind(this));
}
- _onNextFiles(obj: Gio.FileEnumerator | null, res: Gio.AsyncResult): void {
+ private onNextFiles(obj: Gio.FileEnumerator | null, res: Gio.AsyncResult): void {
try {
const fileInfos = obj?.next_files_finish(res);
if (fileInfos && fileInfos.length) {
@@ -134,9 +134,9 @@ export const RecordingList = GObject.registerClass(class RecordingList extends G
const recording = new Recording(file);
this.sortedInsert(recording);
});
- this._enumerator?.next_files_async(5, GLib.PRIORITY_LOW, this.cancellable,
this._onNextFiles.bind(this));
+ this.enumerator?.next_files_async(5, GLib.PRIORITY_LOW, this.cancellable,
this.onNextFiles.bind(this));
} else {
- this._enumerator?.close(this.cancellable);
+ this.enumerator?.close(this.cancellable);
}
} catch (e: unknown) {
if (e instanceof GLib.Error) {
@@ -146,7 +146,7 @@ export const RecordingList = GObject.registerClass(class RecordingList extends G
}
}
- getIndex(file: Gio.File): number {
+ private getIndex(file: Gio.File): number {
for (let i = 0; i < this.get_n_items(); i++) {
const item = this.get_item(i) as RecordingClass;
if (item.uri === file.get_uri())
@@ -155,7 +155,7 @@ export const RecordingList = GObject.registerClass(class RecordingList extends G
return -1;
}
- sortedInsert(recording: RecordingClass): void {
+ private sortedInsert(recording: RecordingClass): void {
let added = false;
for (let i = 0; i < this.get_n_items(); i++) {
diff --git a/src/recordingListWidget.ts b/src/recordingListWidget.ts
index 4470173..1c05cf1 100644
--- a/src/recordingListWidget.ts
+++ b/src/recordingListWidget.ts
@@ -16,10 +16,10 @@ export const RecordingsListWidget = GObject.registerClass({
'row-deleted': { param_types: [GObject.TYPE_OBJECT, GObject.TYPE_INT] },
},
}, class RecordingsListWidget extends Adw.Bin {
- _player: GstPlayer.Player;
- list: Gtk.ListBox;
- activeRow?: RowClass | null;
- activePlayingRow?: RowClass | null;
+ private player: GstPlayer.Player;
+ public list: Gtk.ListBox;
+ public activeRow?: RowClass | null;
+ public activePlayingRow?: RowClass | null;
constructor(model: Gio.ListModel, player: GstPlayer.Player) {
super();
@@ -34,8 +34,8 @@ export const RecordingsListWidget = GObject.registerClass({
this.set_child(this.list);
- this._player = player;
- this._player.connect('state-changed', (_player: GstPlayer.Player, state: GstPlayer.PlayerState) => {
+ this.player = player;
+ this.player.connect('state-changed', (_player: GstPlayer.Player, state: GstPlayer.PlayerState) => {
if (state === GstPlayer.PlayerState.STOPPED && this.activePlayingRow) {
this.activePlayingRow.state = RowState.Paused;
this.activePlayingRow.waveform.position = 0.0;
@@ -45,9 +45,9 @@ export const RecordingsListWidget = GObject.registerClass({
}
});
- this._player.connect('position-updated', (_player: GstPlayer.Player, pos: number) => {
+ this.player.connect('position-updated', (_player: GstPlayer.Player, pos: number) => {
if (this.activePlayingRow) {
- const duration = this.activePlayingRow._recording.duration;
+ const duration = this.activePlayingRow.recording.duration;
this.activePlayingRow.waveform.position = pos / duration;
}
});
@@ -65,12 +65,12 @@ export const RecordingsListWidget = GObject.registerClass({
this.activePlayingRow.waveform.position = 0.0;
this.activePlayingRow = row;
- this._player.set_uri(recording.uri);
+ this.player.set_uri(recording.uri);
}
});
row.waveform.connect('position-changed', (_wave, _position) => {
- this._player.seek(_position * row._recording.duration);
+ this.player.seek(_position * row.recording.duration);
});
row.connect('play', (_row: RowClass) => {
@@ -78,29 +78,29 @@ export const RecordingsListWidget = GObject.registerClass({
if (this.activePlayingRow !== _row) {
this.activePlayingRow.state = RowState.Paused;
this.activePlayingRow.waveform.position = 0.0;
- this._player.set_uri(recording.uri);
+ this.player.set_uri(recording.uri);
}
} else {
- this._player.set_uri(recording.uri);
+ this.player.set_uri(recording.uri);
}
this.activePlayingRow = _row;
- this._player.play();
+ this.player.play();
});
row.connect('pause', () => {
- this._player.pause();
+ this.player.pause();
});
- row.connect('seek-backward', (_row: RowClass) => {
- let position = this._player.position - 10 * Gst.SECOND;
- position = position < 0 || position > _row._recording.duration ? 0 : position;
- this._player.seek(position);
+ row.connect('seek-backward', (row: RowClass) => {
+ let position = this.player.position - 10 * Gst.SECOND;
+ position = position < 0 || position > row.recording.duration ? 0 : position;
+ this.player.seek(position);
});
row.connect('seek-forward', (_row: RowClass) => {
- let position = this._player.position + 10 * Gst.SECOND;
- position = position < 0 || position > _row._recording.duration ? 0 : position;
- this._player.seek(position);
+ let position = this.player.position + 10 * Gst.SECOND;
+ position = position < 0 || position > _row.recording.duration ? 0 : position;
+ this.player.seek(position);
});
row.connect('deleted', () => {
@@ -109,12 +109,12 @@ export const RecordingsListWidget = GObject.registerClass({
if (row === this.activePlayingRow) {
this.activePlayingRow = null;
- this._player.stop();
+ this.player.stop();
}
const index = row.get_index();
this.isolateAt(index, false);
- this.emit('row-deleted', row._recording, index);
+ this.emit('row-deleted', row.recording, index);
});
return row;
@@ -123,7 +123,7 @@ export const RecordingsListWidget = GObject.registerClass({
this.list.connect('row-activated', this.rowActivated.bind(this));
}
- rowActivated(_list: Gtk.ListBox, row: RowClass): void {
+ private rowActivated(_list: Gtk.ListBox, row: RowClass): void {
if (row.editMode && row.expanded || this.activeRow && this.activeRow.editMode &&
this.activeRow.expanded)
return;
@@ -137,7 +137,7 @@ export const RecordingsListWidget = GObject.registerClass({
this.activeRow = row;
}
- isolateAt(index: number, expanded: boolean): void {
+ private isolateAt(index: number, expanded: boolean): void {
const before = this.list.get_row_at_index(index - 1);
const current = this.list.get_row_at_index(index);
const after = this.list.get_row_at_index(index + 1);
diff --git a/src/row.ts b/src/row.ts
index 850951d..01994ba 100644
--- a/src/row.ts
+++ b/src/row.ts
@@ -37,39 +37,38 @@ export const Row = GObject.registerClass({
false),
},
}, class Row extends Gtk.ListBoxRow {
- _playbackStack!: Gtk.Stack;
- _mainStack!: Gtk.Stack;
- _waveformStack!: Gtk.Stack;
- _rightStack!: Gtk.Stack;
- _name!: Gtk.Label;
- _entry!: Gtk.Entry;
- _date!: Gtk.Label;
- _duration!: Gtk.Label;
- _revealer!: Gtk.Revealer;
- _playbackControls!: Gtk.Box;
- _saveBtn!: Gtk.Button;
- _playBtn!: Gtk.Button;
- _pauseBtn!: Gtk.Button;
-
- _recording: RecordingClass;
- _expanded: boolean;
- _editMode: boolean;
- _state: RowState;
-
- waveform: WaveFormClass;
- actionGroup: Gio.SimpleActionGroup;
- exportDialog?: Gtk.FileChooserNative | null;
-
- saveRenameAction: Gio.SimpleAction;
- renameAction: Gio.SimpleAction;
- pauseAction: Gio.SimpleAction;
- playAction: Gio.SimpleAction;
- keyController: Gtk.EventControllerKey;
+ private _playbackStack!: Gtk.Stack;
+ private _mainStack!: Gtk.Stack;
+ private _waveformStack!: Gtk.Stack;
+ private _rightStack!: Gtk.Stack;
+ private _name!: Gtk.Label;
+ private _entry!: Gtk.Entry;
+ private _date!: Gtk.Label;
+ private _duration!: Gtk.Label;
+ private _revealer!: Gtk.Revealer;
+ private _playbackControls!: Gtk.Box;
+ private _playBtn!: Gtk.Button;
+ private _pauseBtn!: Gtk.Button;
+
+ public recording: RecordingClass;
+ private _expanded: boolean;
+ private _editMode: boolean;
+ private _state: RowState;
+
+ public waveform: WaveFormClass;
+ private actionGroup: Gio.SimpleActionGroup;
+ private exportDialog?: Gtk.FileChooserNative | null;
+
+ private saveRenameAction: Gio.SimpleAction;
+ private renameAction: Gio.SimpleAction;
+ private pauseAction: Gio.SimpleAction;
+ private playAction: Gio.SimpleAction;
+ private keyController: Gtk.EventControllerKey;
constructor(recording: RecordingClass) {
super();
- this._recording = recording;
+ this.recording = recording;
this._expanded = false;
this._editMode = false;
this._state = RowState.Paused;
@@ -80,11 +79,11 @@ export const Row = GObject.registerClass({
}, WaveType.Player);
this._waveformStack.add_named(this.waveform, 'wave');
- if (this._recording._peaks.length > 0) {
- this.waveform.peaks = this._recording.peaks;
+ if (this.recording.peaks.length > 0) {
+ this.waveform.peaks = this.recording.peaks;
this._waveformStack.visible_child_name = 'wave';
} else {
- this._recording.loadPeaks();
+ this.recording.loadPeaks();
}
if (recording.timeModified)
@@ -102,12 +101,12 @@ export const Row = GObject.registerClass({
exportAction.connect('activate', () => {
const window = this.root as Gtk.Window;
this.exportDialog = Gtk.FileChooserNative.new(_('Export Recording'), window,
Gtk.FileChooserAction.SAVE, _('_Export'), _('_Cancel'));
- this.exportDialog.set_current_name(`${this._recording.name}.${this._recording.extension}`);
+ this.exportDialog.set_current_name(`${this.recording.name}.${this.recording.extension}`);
this.exportDialog.connect('response', (_dialog: Gtk.FileChooserNative, response: number) => {
if (response === Gtk.ResponseType.ACCEPT) {
const dest = this.exportDialog?.get_file();
if (dest)
- this._recording.save(dest);
+ this.recording.save(dest);
}
this.exportDialog?.destroy();
this.exportDialog = null;
@@ -137,7 +136,7 @@ export const Row = GObject.registerClass({
this.playAction = new Gio.SimpleAction({ name: 'play', enabled: true });
this.playAction.connect('activate', () => {
- this.emit('play', this._recording.uri);
+ this.emit('play', this.recording.uri);
this.state = RowState.Playing;
});
this.actionGroup.add_action(this.playAction);
@@ -178,12 +177,12 @@ export const Row = GObject.registerClass({
this.saveRenameAction.activate(null);
});
- this._recording.connect('peaks-updated', (_recording: RecordingClass) => {
+ this.recording.connect('peaks-updated', (_recording: RecordingClass) => {
this._waveformStack.visible_child_name = 'wave';
this.waveform.peaks = _recording.peaks;
});
- this._recording.connect('peaks-loading', () => {
+ this.recording.connect('peaks-loading', () => {
this._waveformStack.visible_child_name = 'loading';
});
@@ -198,10 +197,10 @@ export const Row = GObject.registerClass({
});
}
- onRenameRecording(): void {
+ private onRenameRecording(): void {
try {
if (this._name.label !== this._entry.text)
- this._recording.name = this._entry.text;
+ this.recording.name = this._entry.text;
this.editMode = false;
this.renameAction.enabled = true;
@@ -211,7 +210,7 @@ export const Row = GObject.registerClass({
}
}
- set editMode(state: boolean) {
+ public set editMode(state: boolean) {
this._mainStack.visible_child_name = state ? 'edit' : 'display';
this._editMode = state;
@@ -234,20 +233,20 @@ export const Row = GObject.registerClass({
}
}
- get editMode(): boolean {
+ public get editMode(): boolean {
return this._editMode;
}
- set expanded(state: boolean) {
+ public set expanded(state: boolean) {
this._expanded = state;
this.notify('expanded');
}
- get expanded(): boolean {
+ public get expanded(): boolean {
return this._expanded;
}
- set state(rowState: RowState) {
+ public set state(rowState: RowState) {
this._state = rowState;
switch (rowState) {
@@ -266,7 +265,7 @@ export const Row = GObject.registerClass({
}
}
- get state(): RowState {
+ public get state(): RowState {
return this._state;
}
});
diff --git a/src/waveform.ts b/src/waveform.ts
index b5d09ce..906efb8 100644
--- a/src/waveform.ts
+++ b/src/waveform.ts
@@ -57,55 +57,53 @@ export const WaveForm = GObject.registerClass({
'gesture-pressed': {},
},
}, class WaveForm extends Gtk.DrawingArea {
- _peaks: number[];
- _position: number;
- _dragGesture?: Gtk.GestureDrag;
- _hcId: number;
- _lastX?: number;
+ private _peaks: number[];
+ private _position: number;
+ private dragGesture?: Gtk.GestureDrag;
+ private hcId: number;
+ private lastX?: number;
- lastPosition: number;
- waveType: WaveType;
+ private waveType: WaveType;
constructor(params: Partial<Gtk.DrawingArea.ConstructorProperties> | undefined, type: WaveType) {
super(params);
this._peaks = [];
this._position = 0;
- this.lastPosition = 0;
this.waveType = type;
if (this.waveType === WaveType.Player) {
- this._dragGesture = Gtk.GestureDrag.new();
- this._dragGesture.connect('drag-begin', this.dragBegin.bind(this));
- this._dragGesture.connect('drag-update', this.dragUpdate.bind(this));
- this._dragGesture.connect('drag-end', this.dragEnd.bind(this));
- this.add_controller(this._dragGesture);
+ this.dragGesture = Gtk.GestureDrag.new();
+ this.dragGesture.connect('drag-begin', this.dragBegin.bind(this));
+ this.dragGesture.connect('drag-update', this.dragUpdate.bind(this));
+ this.dragGesture.connect('drag-end', this.dragEnd.bind(this));
+ this.add_controller(this.dragGesture);
}
- this._hcId = Adw.StyleManager.get_default().connect('notify::high-contrast', () => {
+ this.hcId = Adw.StyleManager.get_default().connect('notify::high-contrast', () => {
this.queue_draw();
});
this.set_draw_func(this.drawFunc);
}
- dragBegin(gesture: Gtk.GestureDrag): void {
+ private dragBegin(gesture: Gtk.GestureDrag): void {
gesture.set_state(Gtk.EventSequenceState.CLAIMED);
this.emit('gesture-pressed');
}
- dragUpdate(_gesture: Gtk.GestureDrag, offsetX: number): void {
- if (this._lastX) {
- this._position = this._clamped(offsetX + this._lastX);
+ private dragUpdate(_gesture: Gtk.GestureDrag, offsetX: number): void {
+ if (this.lastX) {
+ this._position = this.clamped(offsetX + this.lastX);
this.queue_draw();
}
}
- dragEnd(): void {
- this._lastX = this._position;
+ private dragEnd(): void {
+ this.lastX = this._position;
this.emit('position-changed', this.position);
}
- drawFunc(superDa: Gtk.DrawingArea, ctx: Cairo.Context) {
+ private drawFunc(superDa: Gtk.DrawingArea, ctx: Cairo.Context) {
const da = superDa as WaveFormClass;
const maxHeight = da.get_allocated_height();
const vertiCenter = maxHeight / 2;
@@ -128,7 +126,7 @@ export const WaveForm = GObject.registerClass({
ctx.setLineCap(Cairo.LineCap.ROUND);
ctx.setLineWidth(2);
- da._setSourceRGBA(ctx, dividerColor);
+ da.setSourceRGBA(ctx, dividerColor);
ctx.moveTo(horizCenter, vertiCenter - maxHeight);
ctx.lineTo(horizCenter, vertiCenter + maxHeight);
@@ -138,9 +136,9 @@ export const WaveForm = GObject.registerClass({
da._peaks.forEach(peak => {
if (da.waveType === WaveType.Player && pointer > horizCenter)
- da._setSourceRGBA(ctx, rightColor);
+ da.setSourceRGBA(ctx, rightColor);
else
- da._setSourceRGBA(ctx, leftColor);
+ da.setSourceRGBA(ctx, leftColor);
ctx.moveTo(pointer, vertiCenter + peak * maxHeight);
ctx.lineTo(pointer, vertiCenter - peak * maxHeight);
@@ -153,7 +151,7 @@ export const WaveForm = GObject.registerClass({
});
}
- set peak(p: number) {
+ public set peak(p: number) {
if (this._peaks) {
if (this._peaks.length > this.get_allocated_width() / (2 * GUTTER))
this._peaks.pop();
@@ -163,25 +161,25 @@ export const WaveForm = GObject.registerClass({
}
}
- set peaks(p: number[]) {
+ public set peaks(p: number[]) {
this._peaks = p;
this.queue_draw();
}
- set position(pos: number) {
+ public set position(pos: number) {
if (this._peaks) {
- this._position = this._clamped(-pos * this._peaks.length * GUTTER);
- this._lastX = this._position;
+ this._position = this.clamped(-pos * this._peaks.length * GUTTER);
+ this.lastX = this._position;
this.queue_draw();
this.notify('position');
}
}
- get position(): number {
+ public get position(): number {
return -this._position / (this._peaks.length * GUTTER);
}
- _clamped(position: number): number {
+ private clamped(position: number): number {
if (position > 0)
position = 0;
else if (position < -this._peaks.length * GUTTER)
@@ -190,12 +188,12 @@ export const WaveForm = GObject.registerClass({
return position;
}
- _setSourceRGBA(cr: Cairo.Context, rgba: Gdk.RGBA): void {
+ private setSourceRGBA(cr: Cairo.Context, rgba: Gdk.RGBA): void {
cr.setSourceRGBA(rgba.red, rgba.green, rgba.blue, rgba.alpha);
}
- destroy(): void {
- Adw.StyleManager.get_default().disconnect(this._hcId);
+ public destroy(): void {
+ Adw.StyleManager.get_default().disconnect(this.hcId);
this._peaks.length = 0;
this.queue_draw();
}
diff --git a/src/window.ts b/src/window.ts
index 7d0770a..4ecb4c6 100644
--- a/src/window.ts
+++ b/src/window.ts
@@ -47,24 +47,24 @@ export const Window = GObject.registerClass({
'mainStack', 'emptyPage', 'column', 'headerRevealer', 'toastOverlay',
],
}, class Window extends Adw.ApplicationWindow {
- _mainStack!: Gtk.Stack;
- _emptyPage!: Adw.StatusPage;
- _column!: Adw.Clamp;
- _headerRevealer!: Gtk.Revealer;
- _toastOverlay!: Adw.ToastOverlay;
+ private _mainStack!: Gtk.Stack;
+ private _emptyPage!: Adw.StatusPage;
+ private _column!: Adw.Clamp;
+ private _headerRevealer!: Gtk.Revealer;
+ private _toastOverlay!: Adw.ToastOverlay;
- recorder: RecorderClass;
- recorderWidget: RecorderWidgetClass;
- player: GstPlayer.Player;
- _recordingList: RecordingListClass;
- itemsSignalId: number;
- _recordingListWidget: RecordingsListWidgetClass;
+ private recorder: RecorderClass;
+ private recorderWidget: RecorderWidgetClass;
+ private player: GstPlayer.Player;
+ private recordingList: RecordingListClass;
+ private itemsSignalId: number;
+ private recordingListWidget: RecordingsListWidgetClass;
- toastUndo: boolean;
- undoSignalID: number | null;
- undoAction: Gio.SimpleAction;
+ private toastUndo: boolean;
+ private undoSignalID: number | null;
+ private undoAction: Gio.SimpleAction;
- _state: WindowState;
+ private _state: WindowState;
constructor(params: Partial<Adw.Application.ConstructorProperties>) {
super(params);
@@ -81,20 +81,20 @@ export const Window = GObject.registerClass({
this.player.connect('end-of-stream', () => this.player.stop());
- this._recordingList = new RecordingList();
- this.itemsSignalId = this._recordingList.connect('items-changed', () => {
+ this.recordingList = new RecordingList();
+ this.itemsSignalId = this.recordingList.connect('items-changed', () => {
if (this.state !== WindowState.Recorder) {
- if (this._recordingList.get_n_items() === 0)
+ if (this.recordingList.get_n_items() === 0)
this.state = WindowState.Empty;
else
this.state = WindowState.List;
}
});
- this._recordingListWidget = new RecordingsListWidget(this._recordingList, this.player);
+ this.recordingListWidget = new RecordingsListWidget(this.recordingList, this.player);
- this._recordingListWidget.connect('row-deleted', (_listBox: Gtk.ListBox, recording: RecordingClass,
index: number) => {
- this._recordingList.remove(index);
+ this.recordingListWidget.connect('row-deleted', (_listBox: Gtk.ListBox, recording: RecordingClass,
index: number) => {
+ this.recordingList.remove(index);
let message: string;
if (recording.name) {
message = _('"%s" deleted').format(recording.name);
@@ -119,7 +119,7 @@ export const Window = GObject.registerClass({
action.state = new GLib.Variant('b', !state);
});
this.add_action(openMenuAction);
- this._column.set_child(this._recordingListWidget);
+ this._column.set_child(this.recordingListWidget);
this.recorderWidget.connect('started', this.onRecorderStarted.bind(this));
this.recorderWidget.connect('canceled', this.onRecorderCanceled.bind(this));
@@ -128,13 +128,13 @@ export const Window = GObject.registerClass({
this._emptyPage.icon_name = `${pkg.name}-symbolic`;
}
- vfunc_close_request(): boolean {
- this._recordingList.cancellable.cancel();
+ public vfunc_close_request(): boolean {
+ this.recordingList.cancellable.cancel();
if (this.itemsSignalId)
- this._recordingList.disconnect(this.itemsSignalId);
+ this.recordingList.disconnect(this.itemsSignalId);
- for (let i = 0; i < this._recordingList.get_n_items(); i++) {
- const recording = this._recordingList.get_item(i) as RecordingClass;
+ for (let i = 0; i < this.recordingList.get_n_items(); i++) {
+ const recording = this.recordingList.get_item(i) as RecordingClass;
if (recording.pipeline)
recording.pipeline.set_state(Gst.State.NULL);
}
@@ -144,31 +144,31 @@ export const Window = GObject.registerClass({
return true;
}
- onRecorderStarted(): void {
+ private onRecorderStarted(): void {
this.player.stop();
- const activeRow = this._recordingListWidget.activeRow;
+ const activeRow = this.recordingListWidget.activeRow;
if (activeRow && activeRow.editMode)
activeRow.editMode = false;
this.state = WindowState.Recorder;
}
- onRecorderCanceled(): void {
- if (this._recordingList.get_n_items() === 0)
+ private onRecorderCanceled(): void {
+ if (this.recordingList.get_n_items() === 0)
this.state = WindowState.Empty;
else
this.state = WindowState.List;
}
- onRecorderStopped(_widget: RecorderWidgetClass, recording: RecordingClass): void {
- this._recordingList.insert(0, recording);
- const row = this._recordingListWidget.list.get_row_at_index(0) as RowClass;
+ private onRecorderStopped(_widget: RecorderWidgetClass, recording: RecordingClass): void {
+ this.recordingList.insert(0, recording);
+ const row = this.recordingListWidget.list.get_row_at_index(0) as RowClass;
row.editMode = true;
this.state = WindowState.List;
}
- sendNotification(message: string, recording: RecordingClass, index: number): void {
+ private sendNotification(message: string, recording: RecordingClass, index: number): void {
const toast = Adw.Toast.new(message);
toast.connect('dismissed', () => {
if (!this.toastUndo)
@@ -181,7 +181,7 @@ export const Window = GObject.registerClass({
this.undoAction.disconnect(this.undoSignalID);
this.undoSignalID = this.undoAction.connect('activate', () => {
- this._recordingList.insert(index, recording);
+ this.recordingList.insert(index, recording);
this.toastUndo = true;
});
@@ -190,7 +190,7 @@ export const Window = GObject.registerClass({
this._toastOverlay.add_toast(toast);
}
- set state(state: WindowState) {
+ public set state(state: WindowState) {
let visibleChild: string;
let isHeaderVisible = true;
@@ -212,7 +212,7 @@ export const Window = GObject.registerClass({
this._state = state;
}
- get state(): WindowState {
+ public get state(): WindowState {
return this._state;
}
});
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]