Files
dash-to-panel/src/extension.js

180 lines
5.3 KiB
JavaScript
Raw Normal View History

2016-09-21 00:18:00 +00:00
/*
2016-12-23 11:08:39 -05:00
* Dash-To-Panel extension for Gnome 3
2018-12-25 17:26:26 -05:00
* Copyright 2016 Jason DeRose (jderose9) and Charles Gagnon (charlesg99)
2016-09-21 00:18:00 +00:00
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
2016-12-23 11:08:39 -05:00
* the Free Software Foundation, either version 2 of the License, or
2016-09-21 00:18:00 +00:00
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
2025-01-31 11:49:22 -05:00
import Gio from 'gi://Gio'
2016-09-21 00:18:00 +00:00
2025-01-31 11:49:22 -05:00
import * as Main from 'resource:///org/gnome/shell/ui/main.js'
import { EventEmitter } from 'resource:///org/gnome/shell/misc/signals.js'
2025-01-31 12:40:50 -05:00
import { Extension } from 'resource:///org/gnome/shell/extensions/extension.js'
import * as PanelSettings from './panelSettings.js'
2025-01-31 11:49:22 -05:00
import * as PanelManager from './panelManager.js'
import * as AppIcons from './appIcons.js'
import * as Utils from './utils.js'
2025-01-31 11:49:22 -05:00
const UBUNTU_DOCK_UUID = 'ubuntu-dock@ubuntu.com'
2025-01-31 11:49:22 -05:00
let panelManager
let startupCompleteHandler
let ubuntuDockDelayId = 0
2023-08-13 20:32:43 +02:00
2025-01-31 11:49:22 -05:00
export let DTP_EXTENSION = null
export let SETTINGS = null
export let DESKTOPSETTINGS = null
export let TERMINALSETTINGS = null
export let PERSISTENTSTORAGE = null
export let EXTENSION_PATH = null
2023-08-13 22:57:43 +02:00
2023-08-13 03:06:21 +02:00
export default class DashToPanelExtension extends Extension {
2025-01-31 11:49:22 -05:00
constructor(metadata) {
super(metadata)
2023-08-19 15:31:03 +02:00
2025-01-31 11:49:22 -05:00
this._realHasOverview = Main.sessionMode.hasOverview
2023-08-13 03:06:21 +02:00
2025-01-31 11:49:22 -05:00
//create an object that persists until gnome-shell is restarted, even if the extension is disabled
PERSISTENTSTORAGE = {}
}
2023-08-13 03:06:21 +02:00
async enable() {
2025-01-31 11:49:22 -05:00
DTP_EXTENSION = this
SETTINGS = this.getSettings('org.gnome.shell.extensions.dash-to-panel')
DESKTOPSETTINGS = new Gio.Settings({
schema_id: 'org.gnome.desktop.interface',
})
TERMINALSETTINGS = new Gio.Settings({
schema_id: 'org.gnome.desktop.default-applications.terminal',
})
EXTENSION_PATH = this.path
2025-01-31 11:49:22 -05:00
//create a global object that can emit signals and conveniently expose functionalities to other extensions
global.dashToPanel = new EventEmitter()
2023-09-21 22:34:50 -07:00
// reset to be safe
SETTINGS.set_boolean('prefs-opened', false)
await PanelSettings.init(SETTINGS)
// To remove later, try to map settings using monitor indexes to monitor ids
PanelSettings.adjustMonitorSettings(SETTINGS)
// show the donate icon every 120 days (10368000000 milliseconds)
let donateIconUnixtime = SETTINGS.get_string('hide-donate-icon-unixtime')
if (donateIconUnixtime && donateIconUnixtime < Date.now() - 10368000000)
SETTINGS.set_string('hide-donate-icon-unixtime', '')
Main.layoutManager.startInOverview = !SETTINGS.get_boolean(
'hide-overview-on-startup',
)
if (
SETTINGS.get_boolean('hide-overview-on-startup') &&
Main.layoutManager._startingUp
) {
Main.sessionMode.hasOverview = false
startupCompleteHandler = Main.layoutManager.connect(
'startup-complete',
() => (Main.sessionMode.hasOverview = this._realHasOverview),
)
}
this.enableGlobalStyles()
let completeEnable = () => {
panelManager = new PanelManager.PanelManager()
panelManager.enable()
ubuntuDockDelayId = 0
}
// disable ubuntu dock if present
if (Main.extensionManager._extensionOrder.indexOf(UBUNTU_DOCK_UUID) >= 0) {
let disabled = global.settings.get_strv('disabled-extensions')
if (disabled.indexOf(UBUNTU_DOCK_UUID) < 0) {
disabled.push(UBUNTU_DOCK_UUID)
global.settings.set_strv('disabled-extensions', disabled)
// wait a bit so ubuntu dock can disable itself and restore the showappsbutton
ubuntuDockDelayId = setTimeout(completeEnable, 200)
}
} else completeEnable()
2025-01-31 11:49:22 -05:00
}
disable() {
if (ubuntuDockDelayId) clearTimeout(ubuntuDockDelayId)
PanelSettings.disable(SETTINGS)
2025-01-31 11:49:22 -05:00
panelManager.disable()
2018-05-05 13:04:17 -04:00
2025-01-31 11:49:22 -05:00
DTP_EXTENSION = null
SETTINGS = null
DESKTOPSETTINGS = null
TERMINALSETTINGS = null
panelManager = null
2018-05-05 13:04:17 -04:00
delete global.dashToPanel
2019-09-22 22:32:32 -04:00
this.disableGlobalStyles()
AppIcons.resetRecentlyClickedApp()
Update to Gnome 40 (#1303) * 1 * renamed ui.viewSelector to ui.searchController * add arrowIcon null check * add object null check * add _showAppsButton null check * fixed _workspacesDisplay * removed shadow-type properties * removed packing from ui * renamed margin_left/right to margin_start/end * renamed GtkRadioButton to GtkToggleButton, removed draw_indicator and image_position * removed xalign from buttons, stock -> icon_name, GtkFileChooserButton -> BtkButton (todo connect a GtkFileChooserNative), removed format-value (todo connect GtkScaleFormatValueFunc callback) * removed events, relief * comment arrowIcon.set_icon_name and _hbox.get_last_child out * called gtk4-builder-tool simplify --3to4 on Settings.ui * fix _workspaceDisplay * revert Settings.ui back to old gtk3 version * removed _builder.connect_signals_full and added a BuilderScope instead, use class specific add functions, removed show_all for widgets, updated margins* for GtkGrid * add try catch aroung object.connect * fixed _searchEntry path * disabled _newUpdateWorkspacesViews temporarily, because it is very buggy right now * fixed _searchEntry path (this time for real?) * dialog.show_all() -> dialog.show(), widget.get_toplevel() -> widget.get_root(), fixed adjustScrollableHeight (no longer crashes, still does not work correctly) * updated GtkGrid.attach calls * added Gtk.FileChooserNative for show_applications_icon_file_filebutton * added packing again to ui (commented) and also added layout row/column/width/height in exchange for top_attach/left_attach/colspan/rowspan * renamed colspan/rowspan to column-span/row-span * removed all packaing left_attach/top_attach * updated adjustScrollableHeight so the dialog will have a reasonable size again * limit shell-version to 40 since it is not backwards compatible right now * called _updateBackgrounds in layoutManager ,fixed overview <-> _overview typo? * pass Settings instead of Settings._settings to BuilderScope * workaround for showAppsIcon (_showAppsButton seems to be no longer be available) * replaced newlines in the ui file with the newline unicode symbol, so code block collapsing works peroperly * moved the scrolled window directly into each notebook tab, so the tab headers are always visible * fixed taskbarListBox children loops * commented non working elements out (panel on left/right, import/export settings, update) * renamed Settings to Preferences to avoid confusion with dconf settings object * updated this.widget to this.notebook * fixed dialogs size and expand * fixed window preview options having too many columns * removed all packing with expand/fill/position (already uncommented) * removed menu arrows since they are no longer recommended for gnome40 * removed adjustScrollableHeight, default sizes are acceptable * updated ui required version to gtk 4.0 * updated path to dash.showAppsButton * fixes for showAppsButton * fixed clickToExit * fixed import/export settings * added disable show overview on startup option * removed old show apps animation * fixed panel on left/right side * fixed scroll on volume icon no longer will scrolling on the volume icon switch workspaces as well * commented some setFocusedMonitor support out, caused issues on Xorg * removed oldDash * updated hide overview on startup, no longer closes overview after suspend etc * removed _newOverviewRelayout * removed _newUpdateWorkspacesViews * commented setFocusedMonitor out completly, because show overview on non primary monitor does not work properly for now * fixed typo * fixed merging error * check if func is valid in hookVfunc * updated ui to gtk4, fixed merging error * fixed layout for apply changes to all monitors * fix behaviour tab and app icon margin/padding grid * fix animate launching new windows grid row * fixed about tab Co-authored-by: Cole Gerdemann <corvettecole@gmail.com>
2021-05-08 15:07:25 +02:00
2025-01-31 11:49:22 -05:00
if (startupCompleteHandler) {
Main.layoutManager.disconnect(startupCompleteHandler)
startupCompleteHandler = null
}
2025-01-29 16:56:08 -05:00
2025-01-31 11:49:22 -05:00
Main.sessionMode.hasOverview = this._realHasOverview
}
openPreferences() {
if (SETTINGS.get_boolean('prefs-opened')) {
let prefsWindow = Utils.getAllMetaWindows().find(
(w) =>
w.title == 'Dash to Panel' &&
w.wm_class == 'org.gnome.Shell.Extensions',
)
if (prefsWindow) Main.activateWindow(prefsWindow)
return
}
super.openPreferences()
}
resetGlobalStyles() {
this.disableGlobalStyles()
this.enableGlobalStyles()
}
enableGlobalStyles() {
let globalBorderRadius = SETTINGS.get_int('global-border-radius')
if (globalBorderRadius)
Main.layoutManager.uiGroup.add_style_class_name(
`br${globalBorderRadius * 4}`,
)
}
disableGlobalStyles() {
;['br4', 'br8', 'br12', 'br16', 'br20'].forEach((c) =>
Main.layoutManager.uiGroup.remove_style_class_name(c),
)
}
2025-01-31 11:49:22 -05:00
}