forked from DenysMb/ChatAI-Plasmoid
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Started with the option to launch Plasma without starting the webview in the background, to save memory during boot. - Added support for opening external links in the system's default browser. - Added support for file downloads with a progress bar, the option to open the file, open the folder, choose the default folder, and notify when attempting to download the same file more than once simultaneously. - Added the ability to print to PDF. - Buttons for back, refresh, forward, auto-hide, downloads, pin, and close can be optionally included. - The close button terminates the webview, again to reduce memory consumption if needed. - Auto-hide with 2 pixels of space to hover over and make the header appear. - The header is automatically moved to the bottom if the plasmoid is placed on the top bar of the screen. - Moved the Custom URL option inside the dropdown and removed the button from the header. - Added a simple way to add sites in the settings. - Added the option to use the site's favicon as the icon. - Enabled microphone, webcam, screen sharing, notifications, and geolocation options. - Some sites were added to the default list.
- Loading branch information
Showing
9 changed files
with
2,203 additions
and
381 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,67 +1,105 @@ | ||
import QtQuick | ||
import QtQuick.Layouts 1.1 | ||
import org.kde.kirigami 2.20 as Kirigami | ||
import org.kde.plasma.plasmoid 2.0 | ||
import org.kde.plasma.core 2.0 as PlasmaCore | ||
|
||
Loader { | ||
property var models; | ||
Item { | ||
id: compactRoot | ||
|
||
property var models | ||
property var webview | ||
property string fallbackIcon: "help-about" | ||
|
||
TapHandler { | ||
property bool wasExpanded: false | ||
|
||
acceptedButtons: Qt.LeftButton | ||
|
||
onPressedChanged: if (pressed) { | ||
wasExpanded = root.expanded; | ||
} | ||
onTapped: root.expanded = !wasExpanded | ||
MouseArea { | ||
id: mouseArea | ||
anchors.fill: parent | ||
onClicked: root.expanded = !root.expanded | ||
} | ||
|
||
Kirigami.Icon { | ||
anchors.fill: parent | ||
source: Qt.resolvedUrl(getIcon()) | ||
} | ||
|
||
// WebView connection handlers | ||
// Monitor and respond to webview state changes | ||
Connections { | ||
// Parent webview connection | ||
target: parent && parent.webviewRoot && parent.webviewRoot.webview | ||
? parent.webviewRoot.webview | ||
: null | ||
enabled: target ? true : false | ||
} | ||
|
||
// Direct webview connection for loading state changes | ||
Connections { | ||
target: webview | ||
enabled: webview !== null | ||
function onLoadingChanged(loadingInfo) { | ||
if (loadingInfo?.status === WebEngineLoadRequest.LoadSucceededStatus) { | ||
// Handle successful load | ||
} | ||
} | ||
} | ||
|
||
// Helper Functions | ||
// Determines and returns the appropriate chat model icon based on: | ||
// - Current chat service | ||
// - System theme (light/dark) | ||
// - User icon style preferences | ||
function getChatModelIcon() { | ||
const currentModel = models.find(model => Plasmoid.configuration.url.includes(model.url)); | ||
const colorContrast = getBackgroundColorContrast(); | ||
const isNotColorfulAndIsOneOfChatModelsThatHaveOnlyColorfulIcons = !Plasmoid.configuration.useColorfulChatIcon && ["lobechat", "bigagi"].includes(currentModel?.id); | ||
const currentModel = models.find(model => Plasmoid.configuration.url.includes(model.url)) | ||
const colorContrast = getBackgroundColorContrast() | ||
const hasOnlyColorfulIcon = !Plasmoid.configuration.useColorfulChatIcon && | ||
["lobechat", "bigagi"].includes(currentModel?.id) | ||
|
||
if (!currentModel || currentModel?.id === "blackbox" || isNotColorfulAndIsOneOfChatModelsThatHaveOnlyColorfulIcons) { | ||
return `assets/logo-${colorContrast}.svg`; | ||
if (!currentModel || currentModel?.id === "blackbox" || hasOnlyColorfulIcon) { | ||
return `assets/logo-${colorContrast}.svg` | ||
} | ||
|
||
if (Plasmoid.configuration.useColorfulChatIcon) { | ||
return `assets/colorful/${currentModel.id}.svg`; | ||
return `assets/colorful/${currentModel.id}.svg` | ||
} | ||
|
||
const filledOrOutlined = Plasmoid.configuration.useFilledChatIcon ? "filled" : "outlined"; | ||
|
||
return `assets/${filledOrOutlined}/${currentModel.id}-${colorContrast}.svg`; | ||
const style = Plasmoid.configuration.useFilledChatIcon ? "filled" : "outlined" | ||
return `assets/${style}/${currentModel.id}-${colorContrast}.svg` | ||
} | ||
|
||
// Main icon selection function that determines which icon to display: | ||
// 1. Website favicon (if enabled) | ||
// 2. Chat model specific icon (if enabled) | ||
// 3. Default icon based on theme | ||
function getIcon() { | ||
if (Plasmoid.configuration.useFilledChatIcon || Plasmoid.configuration.useOutlinedChatIcon || Plasmoid.configuration.useColorfulChatIcon) { | ||
return getChatModelIcon(); | ||
} else if (Plasmoid.configuration.useDefaultDarkIcon) { | ||
return "assets/logo-dark.svg"; | ||
} else if (Plasmoid.configuration.useDefaultLightIcon) { | ||
return "assets/logo-light.svg"; | ||
} else { | ||
const colorContrast = getBackgroundColorContrast(); | ||
|
||
return `assets/logo-${colorContrast}.svg`; | ||
if (Plasmoid.configuration.useFavicon) { | ||
const faviconUrl = Plasmoid.configuration.favIcon || Plasmoid.configuration.lastFavIcon | ||
if (faviconUrl) { | ||
return faviconUrl.replace("image://favicon/", "") | ||
} | ||
} | ||
|
||
if (Plasmoid.configuration.useFilledChatIcon || | ||
Plasmoid.configuration.useOutlinedChatIcon || | ||
Plasmoid.configuration.useColorfulChatIcon) { | ||
return getChatModelIcon() || fallbackIcon | ||
} | ||
|
||
const contrast = getBackgroundColorContrast() | ||
return Plasmoid.configuration.useDefaultDarkIcon ? "assets/logo-dark.svg" : | ||
Plasmoid.configuration.useDefaultLightIcon ? "assets/logo-light.svg" : | ||
`assets/logo-${contrast}.svg` | ||
} | ||
|
||
// Calculates whether to use light or dark icons based on | ||
// the system background color using luminance formula | ||
// Returns: "dark" or "light" based on background contrast | ||
function getBackgroundColorContrast() { | ||
const hex = `${PlasmaCore.Theme.backgroundColor}`.substring(1); | ||
const r = parseInt(hex.substring(0, 2), 16); | ||
const g = parseInt(hex.substring(2, 4), 16); | ||
const b = parseInt(hex.substring(4, 6), 16); | ||
const luma = 0.2126 * r + 0.7152 * g + 0.0722 * b; | ||
|
||
return luma > 128 ? "dark" : "light"; | ||
const hex = `${PlasmaCore.Theme.backgroundColor}`.substring(1) | ||
const [r, g, b] = [ | ||
parseInt(hex.substring(0, 2), 16), | ||
parseInt(hex.substring(2, 4), 16), | ||
parseInt(hex.substring(4, 6), 16) | ||
] | ||
const luma = 0.2126 * r + 0.7152 * g + 0.0722 * b | ||
return luma > 128 ? "dark" : "light" | ||
} | ||
} | ||
} |
Oops, something went wrong.