[gnome-sound-recorder/bilelmoussaoui/misc-imports] misc: clean up imports



commit 6a0c9c757456cc046036f64e95edb234cc18b1e7
Author: Bilal Elmoussaoui <bil elmoussaoui gmail com>
Date:   Sun Jun 14 15:04:26 2020 +0200

    misc: clean up imports

 src/application.js   | 37 +++++++++++++++----------------------
 src/main.js          |  2 +-
 src/mainWindow.js    | 17 +++++++----------
 src/player.js        |  4 +---
 src/recorder.js      | 18 ++++++------------
 src/recording.js     |  6 +-----
 src/recordingList.js | 22 ++++++++--------------
 src/row.js           |  3 +--
 src/waveform.js      |  3 +--
 9 files changed, 41 insertions(+), 71 deletions(-)
---
diff --git a/src/application.js b/src/application.js
index 05acbd7..5052b95 100644
--- a/src/application.js
+++ b/src/application.js
@@ -1,4 +1,4 @@
-/* exported settings Application */
+/* exported Application RecordingsDir Settings */
 /*
 * Copyright 2013 Meg Ford
 * This library is free software; you can redistribute it and/or
@@ -18,17 +18,13 @@
 *
 */
 
-const Gio = imports.gi.Gio;
-const GLib = imports.gi.GLib;
-const GObject = imports.gi.GObject;
-const Gst = imports.gi.Gst;
-const Gtk = imports.gi.Gtk;
-const Gdk = imports.gi.Gdk;
+const { Gdk, Gio, GLib, GObject, Gst, Gtk } = imports.gi;
 
-const MainWindow = imports.mainWindow;
+/* Translators: "Recordings" here refers to the name of the directory where the application places files */
+const RecordingsDir = Gio.file_new_for_path(GLib.build_filenamev([GLib.get_home_dir(), _('Recordings')]));
+const Settings = new Gio.Settings({ schema: pkg.name });
 
-
-var settings = new Gio.Settings({ schema: pkg.name });
+const { MainWindow } = imports.mainWindow;
 
 var Application = GObject.registerClass(class Application extends Gtk.Application {
     _init() {
@@ -55,7 +51,7 @@ var Application = GObject.registerClass(class Application extends Gtk.Applicatio
 
     _initAppMenu() {
         function getDefaultProfile() {
-            switch (settings.get_enum('audio-profile')) {
+            switch (Settings.get_enum('audio-profile')) {
             case 0:
                 return new GLib.Variant('s', 'vorbis');
             case 1:
@@ -79,16 +75,16 @@ var Application = GObject.registerClass(class Application extends Gtk.Applicatio
             action.change_state(parameter);
         });
         profileAction.connect('change-state', (action, state) => {
-            settings.set_value('audio-profile', state);
+            Settings.set_value('audio-profile', state);
         });
-        settings.connect('changed::audio-profile', () => {
+        Settings.connect('changed::audio-profile', () => {
             profileAction.state = getDefaultProfile();
         });
         this.add_action(profileAction);
 
 
         function getDefaultChannel() {
-            switch (settings.get_enum('audio-channel')) {
+            switch (Settings.get_enum('audio-channel')) {
             case 0:
                 return new GLib.Variant('s', 'stereo');
             case 1:
@@ -106,9 +102,9 @@ var Application = GObject.registerClass(class Application extends Gtk.Applicatio
             action.change_state(parameter);
         });
         channelAction.connect('change-state', (action, state) => {
-            settings.set_value('audio-channel', state);
+            Settings.set_value('audio-channel', state);
         });
-        settings.connect('changed::audio-channel', () => {
+        Settings.connect('changed::audio-channel', () => {
             channelAction.state = getDefaultChannel();
         });
         this.add_action(channelAction);
@@ -139,18 +135,15 @@ var Application = GObject.registerClass(class Application extends Gtk.Applicatio
     }
 
     ensureDirectory() {
-        /* Translators: "Recordings" here refers to the name of the directory where the application places 
files */
-        let path = GLib.build_filenamev([GLib.get_home_dir(), _('Recordings')]);
-
         // Ensure Recordings directory
-        GLib.mkdir_with_parents(path, 0o0755);
-        this.saveDir = Gio.file_new_for_path(path);
+        GLib.mkdir_with_parents(RecordingsDir.get_path(), 0o0755);
     }
 
     vfunc_activate() {
-        (this.window = new MainWindow.MainWindow({ application: this })).show();
+        this.window = new MainWindow({ application: this });
         if (pkg.name.endsWith('Devel'))
             this.window.get_style_context().add_class('devel');
+        this.window.show();
     }
 
     _loadStyleSheet() {
diff --git a/src/main.js b/src/main.js
index 84d393c..8fdfd22 100644
--- a/src/main.js
+++ b/src/main.js
@@ -40,7 +40,7 @@ pkg.require({
     'Handy': '1',
 });
 
-const Application = imports.application.Application;
+const { Application } = imports.application;
 
 function main(argv) {
     return new Application().run(argv);
diff --git a/src/mainWindow.js b/src/mainWindow.js
index bc79244..c818219 100644
--- a/src/mainWindow.js
+++ b/src/mainWindow.js
@@ -17,18 +17,15 @@
 * Author: Meg Ford <megford gnome org>
 *
 */
+const { GObject, Gst, Handy } = imports.gi;
 
-const Gst = imports.gi.Gst;
-const GObject = imports.gi.GObject;
-const Handy = imports.gi.Handy;
-
+const { Player } = imports.player;
+const { Recorder } = imports.recorder;
+const { RecordingList } = imports.recordingList;
+const { Row, RowState } = imports.row;
 const Utils = imports.utils;
-const RecordingList = imports.recordingList.RecordingList;
-const Row = imports.row.Row;
-const RowState = imports.row.RowState;
-const Player = imports.player.Player;
-const Recorder = imports.recorder.Recorder;
-const WaveForm = imports.waveform.WaveForm;
+const { WaveForm } = imports.waveform;
+
 
 var MainWindow = GObject.registerClass({
     Template: 'resource:///org/gnome/SoundRecorder/ui/window.ui',
diff --git a/src/player.js b/src/player.js
index 4a52dc6..59af66c 100644
--- a/src/player.js
+++ b/src/player.js
@@ -17,9 +17,7 @@
  * Author: Meg Ford <megford gnome org>
  *
  */
-const Gst = imports.gi.Gst;
-const Gio = imports.gi.Gio;
-const Gtk = imports.gi.Gtk;
+const { Gio, Gst, Gtk } = imports.gi;
 
 
 var Player = class Player {
diff --git a/src/recorder.js b/src/recorder.js
index eb4dba0..f00e72f 100644
--- a/src/recorder.js
+++ b/src/recorder.js
@@ -17,15 +17,10 @@
  *  Author: Meg Ford <megford gnome org>
  *
  */
+const { Gio, GLib, GObject, Gst, GstPbutils } = imports.gi;
 
-const Gio = imports.gi.Gio;
-const GLib = imports.gi.GLib;
-const Gst = imports.gi.Gst;
-const GstPbutils = imports.gi.GstPbutils;
-const Recording = imports.recording.Recording;
-const GObject = imports.gi.GObject;
-
-const Application = imports.application;
+const { RecordingsDir, Settings } = imports.application;
+const { Recording } = imports.recording;
 
 // All supported encoding profiles.
 var EncodingProfiles = [
@@ -107,12 +102,11 @@ var Recorder = new GObject.registerClass({
     start() {
         this.baseTime = 0;
 
-        const dir = Gio.Application.get_default().saveDir;
         const dateTime = GLib.DateTime.new_now_local();
         /* Translators: ""Recording from %F %A at %T"" is the default name assigned to a file created
             by the application (for example, "Recording from 2020-03-11 Wednesday at 19:43:05"). */
         const clipName = dateTime.format(_('Recording from %F %A at %T'));
-        const clip = dir.get_child_for_display_name(clipName);
+        const clip = RecordingsDir.get_child_for_display_name(clipName);
         const fileUri = clip.get_path();
         this.file = Gio.file_new_for_path(fileUri);
 
@@ -220,12 +214,12 @@ var Recorder = new GObject.registerClass({
     }
 
     _getChannel() {
-        let channelIndex = Application.settings.get_enum('audio-channel');
+        let channelIndex = Settings.get_enum('audio-channel');
         return AudioChannels[channelIndex].channels;
     }
 
     _getProfile() {
-        let profileIndex = Application.settings.get_enum('audio-profile');
+        let profileIndex = Settings.get_enum('audio-profile');
         const profile = EncodingProfiles[profileIndex];
 
         let audioCaps = Gst.Caps.from_string(profile.audioCaps);
diff --git a/src/recording.js b/src/recording.js
index 6e8838b..d4c358a 100644
--- a/src/recording.js
+++ b/src/recording.js
@@ -1,9 +1,5 @@
 /* exported Recording */
-const GLib = imports.gi.GLib;
-const Gst = imports.gi.Gst;
-const GObject = imports.gi.GObject;
-const GstPbutils = imports.gi.GstPbutils;
-
+const { GLib, GObject, Gst, GstPbutils } = imports.gi;
 
 var Recording = new GObject.registerClass({
     Properties: {
diff --git a/src/recordingList.js b/src/recordingList.js
index 74dcd95..df7e05c 100644
--- a/src/recordingList.js
+++ b/src/recordingList.js
@@ -1,28 +1,23 @@
 /* exported RecordingList */
-const Gio = imports.gi.Gio;
-const GLib = imports.gi.GLib;
-const GObject = imports.gi.GObject;
-
-const Recording = imports.recording.Recording;
+const { Gio, GLib, GObject } = imports.gi;
 
+const { RecordingsDir } = imports.application;
+const { Recording } = imports.recording;
 
 var RecordingList = new GObject.registerClass(class RecordingList extends Gio.ListStore {
     _init() {
         super._init({ });
-        this._saveDir = Gio.Application.get_default().saveDir;
 
         // Monitor Direcotry actions
-        let dirMonitor = this._saveDir.monitor_directory(Gio.FileMonitorFlags.WATCH_MOVES, null);
+        let dirMonitor = RecordingsDir.monitor_directory(Gio.FileMonitorFlags.WATCH_MOVES, null);
         dirMonitor.connect('changed', (_dirMonitor, file1, file2, eventType) => {
-            // Monitor if file action done on _saveDir
             let index = this.getIndex(file1);
 
             switch (eventType) {
             case Gio.FileMonitorEvent.DELETED:
-                if (Gio.Application.get_default().saveDir.equal(file1)) {
+                if (RecordingsDir.equal(file1))
                     Gio.Application.get_default().ensureDirectory();
-                    this._saveDir = Gio.Application.get_default().saveDir;
-                }
+
                 break;
             case Gio.FileMonitorEvent.MOVED_OUT:
                 if (index >= 0)
@@ -36,7 +31,7 @@ var RecordingList = new GObject.registerClass(class RecordingList extends Gio.Li
 
         });
 
-        this._saveDir.enumerate_children_async('standard::name',
+        RecordingsDir.enumerate_children_async('standard::name',
             Gio.FileQueryInfoFlags.NOFOLLOW_SYMLINKS,
             GLib.PRIORITY_LOW,
             null,
@@ -56,8 +51,7 @@ var RecordingList = new GObject.registerClass(class RecordingList extends Gio.Li
         let fileInfos = obj.next_files_finish(res);
         if (fileInfos.length) {
             fileInfos.forEach(info => {
-                const path = GLib.build_filenamev([this._saveDir.get_path(), info.get_name()]);
-                const file = Gio.file_new_for_path(path);
+                const file = RecordingsDir.get_child(info.get_name());
                 const recording = new Recording(file);
                 this.sortedInsert(recording);
             });
diff --git a/src/row.js b/src/row.js
index 2ca4427..aec1b49 100644
--- a/src/row.js
+++ b/src/row.js
@@ -1,6 +1,5 @@
 /* exported Row */
-const GObject = imports.gi.GObject;
-const Handy = imports.gi.Handy;
+const { GObject, Handy } = imports.gi;
 
 var Utils = imports.utils;
 
diff --git a/src/waveform.js b/src/waveform.js
index 1ea6e93..810364c 100644
--- a/src/waveform.js
+++ b/src/waveform.js
@@ -20,8 +20,7 @@
 
 // based on code from Pitivi
 
-const GObject = imports.gi.GObject;
-const Gtk = imports.gi.Gtk;
+const { GObject, Gtk } = imports.gi;
 const Cairo = imports.cairo;
 
 const WAVE_SAMPLES = 40;


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]