From 0b93ed730790e08453b5b68ec5abbb0afc4d537c Mon Sep 17 00:00:00 2001 From: Nicolas Constant Date: Sat, 12 Aug 2023 01:33:07 -0400 Subject: [PATCH 1/6] language autodetection functionnal --- .../create-status/create-status.component.ts | 2 + src/app/services/electron.service.ts | 38 ++++++++++++++++ src/app/services/language.service.ts | 43 ++++++++++++++++++- 3 files changed, 82 insertions(+), 1 deletion(-) diff --git a/src/app/components/create-status/create-status.component.ts b/src/app/components/create-status/create-status.component.ts index 240d878f..a3282fe7 100644 --- a/src/app/components/create-status/create-status.component.ts +++ b/src/app/components/create-status/create-status.component.ts @@ -68,6 +68,8 @@ export class CreateStatusComponent implements OnInit, OnDestroy { this.detectAutosuggestion(value); this._status = value; + this.languageService.autoDetectLang(value); + setTimeout(() => { this.autoGrow(); }, 0); diff --git a/src/app/services/electron.service.ts b/src/app/services/electron.service.ts index 65c82c1c..d587026f 100644 --- a/src/app/services/electron.service.ts +++ b/src/app/services/electron.service.ts @@ -1,10 +1,30 @@ import { Injectable } from '@angular/core'; +import { Subject } from 'rxjs'; @Injectable({ providedIn: 'root' }) export class MyElectronService { + detectedLangSubject = new Subject(); + constructor() { + try { + if ((window).api) { + (window).api.receive("detectedLang", (data) => { + const result = []; + for (const l of data) { + let newLang = new DetectedLang(l[0], l[1]); + result.push(newLang); + } + this.detectedLangSubject.next(result); + }); + } + } + catch (err) { + console.error(err); + } + + this.detectLang("ceci est une phrase"); } setLang(lang: string) { @@ -17,4 +37,22 @@ export class MyElectronService { console.error(err); } } + + detectLang(text: string) { + try { + if ((window).api) { + (window).api.send("detectLang", text); + } + } + catch (err) { + console.error(err); + } + } +} + +export class DetectedLang { + constructor( + public lang: string, + public score: number + ) {} } diff --git a/src/app/services/language.service.ts b/src/app/services/language.service.ts index a51b2090..c1949bd4 100644 --- a/src/app/services/language.service.ts +++ b/src/app/services/language.service.ts @@ -3,7 +3,7 @@ import { Injectable } from '@angular/core'; import { BehaviorSubject } from 'rxjs'; import { ILanguage } from '../states/settings.state'; -import { MyElectronService } from './electron.service'; +import { DetectedLang, MyElectronService } from './electron.service'; import { SettingsService } from './settings.service'; @Injectable({ @@ -19,6 +19,47 @@ export class LanguageService { ) { this.configuredLanguagesChanged.next(this.getConfiguredLanguages()); this.selectedLanguageChanged.next(this.getSelectedLanguage()); + + this.electronService.detectedLangSubject.subscribe(l => { + this.detectedLanguage(l); + }); + } + + private detectedLanguage(lang: DetectedLang[]) { + if(!lang) return; + + console.warn(lang); + + if(lang.length >= 1){ + const languages = this.getConfiguredLanguages(); + + let firstLang = lang[0].lang; + let firstLocalLang = languages.find(x => x.iso639 == firstLang); + if(firstLocalLang){ + this.setSelectedLanguage(firstLocalLang); + return; + } + + if(lang.length > 1){ + firstLang = lang[1].lang; + firstLocalLang = languages.find(x => x.iso639 == firstLang); + if(firstLocalLang){ + this.setSelectedLanguage(firstLocalLang); + return; + } + } + } + } + + autoDetectLang(text: string): void { + if(!text || text.length < 6) return; + + console.warn('autodetect'); + console.warn(text); + + //TODO: add settings to disable + + this.electronService.detectLang(text); } getSelectedLanguage(): ILanguage { From 10fa412173953e0ce7e0dc65196feeecb58e4c4a Mon Sep 17 00:00:00 2001 From: Nicolas Constant Date: Sat, 12 Aug 2023 16:50:35 -0400 Subject: [PATCH 2/6] ensure language is set to provide translation --- .../stream/status/status-translate/status-translate.component.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/app/components/stream/status/status-translate/status-translate.component.ts b/src/app/components/stream/status/status-translate/status-translate.component.ts index 87d55804..f2143c9b 100644 --- a/src/app/components/stream/status/status-translate/status-translate.component.ts +++ b/src/app/components/stream/status/status-translate/status-translate.component.ts @@ -64,6 +64,7 @@ export class StatusTranslateComponent implements OnInit, OnDestroy { .then(canTranslate => { if (canTranslate && !this.status.isRemote + && this.status.status.language && this.configuredLanguages.length > 0 && this.configuredLanguages.findIndex(x => x.iso639 === this.status.status.language) === -1) { From 8703df27d5f61813e23676c92e8fab36bd94dd8c Mon Sep 17 00:00:00 2001 From: Nicolas Constant Date: Sat, 12 Aug 2023 17:05:25 -0400 Subject: [PATCH 3/6] display years, fix #603 --- src/app/pipes/time-ago.pipe.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/app/pipes/time-ago.pipe.ts b/src/app/pipes/time-ago.pipe.ts index 256f1099..fb073d2d 100644 --- a/src/app/pipes/time-ago.pipe.ts +++ b/src/app/pipes/time-ago.pipe.ts @@ -30,7 +30,7 @@ export class TimeAgoPipe implements PipeTransform { const hours = minutes / 60; const days = hours / 24; // const months = days / 30.416; - // const years = days / 365; + const years = days / 365; if (seconds <= 59) { text = Math.round(seconds) + 's'; @@ -38,8 +38,10 @@ export class TimeAgoPipe implements PipeTransform { text = Math.round(minutes) + 'm'; } else if (hours <= 23) { text = Math.round(hours) + 'h'; - } else { + } else if (days < 365) { text = Math.round(days) + 'd'; + } else { + text = Math.round(years) + 'y'; } if (minutes < 1) { From d7f988ecb9d04edf1e8b92034eda420b7ab0b3ee Mon Sep 17 00:00:00 2001 From: Nicolas Constant Date: Sat, 12 Aug 2023 17:16:57 -0400 Subject: [PATCH 4/6] added lang autodetect disable option --- .../settings/settings.component.html | 10 +++++++- .../settings/settings.component.ts | 9 +++++++ src/app/services/language.service.ts | 25 ++++++++----------- src/app/states/settings.state.ts | 2 ++ 4 files changed, 30 insertions(+), 16 deletions(-) diff --git a/src/app/components/floating-column/settings/settings.component.html b/src/app/components/floating-column/settings/settings.component.html index b6ffe302..f5764f81 100644 --- a/src/app/components/floating-column/settings/settings.component.html +++ b/src/app/components/floating-column/settings/settings.component.html @@ -62,12 +62,20 @@ remove + placeholder="Find Language" autocomplete="off" + class="form-control form-control-sm language__search" />
{{ l.name }} ({{l.iso639}}) add
+ + + + +

Twitter Bridge

diff --git a/src/app/components/floating-column/settings/settings.component.ts b/src/app/components/floating-column/settings/settings.component.ts index 051b23f5..89d4e178 100644 --- a/src/app/components/floating-column/settings/settings.component.ts +++ b/src/app/components/floating-column/settings/settings.component.ts @@ -29,6 +29,7 @@ export class SettingsComponent implements OnInit, OnDestroy { disableRemoteStatusFetchingEnabled: boolean; disableAvatarNotificationsEnabled: boolean; disableSoundsEnabled: boolean; + disableLangAutodetectEnabled: boolean; version: string; hasPleromaAccount: boolean; @@ -146,6 +147,7 @@ export class SettingsComponent implements OnInit, OnDestroy { this.twitterBridgeInstance = settings.twitterBridgeInstance; this.configuredLangs = this.languageService.getConfiguredLanguages(); + this.disableLangAutodetectEnabled = settings.disableLangAutodetec; } ngOnDestroy(): void { @@ -273,6 +275,13 @@ export class SettingsComponent implements OnInit, OnDestroy { return false; } + onDisableLangAutodetectChanged() { + this.notifyRestartNeeded(); + let settings = this.settingsService.getSettings(); + settings.disableLangAutodetec = this.disableLangAutodetectEnabled; + this.settingsService.saveSettings(settings); + } + onDisableAutofocusChanged() { this.notifyRestartNeeded(); let settings = this.settingsService.getSettings(); diff --git a/src/app/services/language.service.ts b/src/app/services/language.service.ts index c1949bd4..9b880ac7 100644 --- a/src/app/services/language.service.ts +++ b/src/app/services/language.service.ts @@ -24,26 +24,24 @@ export class LanguageService { this.detectedLanguage(l); }); } - + private detectedLanguage(lang: DetectedLang[]) { - if(!lang) return; + if (!lang) return; - console.warn(lang); - - if(lang.length >= 1){ + if (lang.length >= 1) { const languages = this.getConfiguredLanguages(); let firstLang = lang[0].lang; let firstLocalLang = languages.find(x => x.iso639 == firstLang); - if(firstLocalLang){ + if (firstLocalLang) { this.setSelectedLanguage(firstLocalLang); return; } - if(lang.length > 1){ + if (lang.length > 1) { firstLang = lang[1].lang; firstLocalLang = languages.find(x => x.iso639 == firstLang); - if(firstLocalLang){ + if (firstLocalLang) { this.setSelectedLanguage(firstLocalLang); return; } @@ -52,14 +50,11 @@ export class LanguageService { } autoDetectLang(text: string): void { - if(!text || text.length < 6) return; + if (!text || text.length < 5) return; - console.warn('autodetect'); - console.warn(text); - - //TODO: add settings to disable - - this.electronService.detectLang(text); + if (!this.settingsService.getSettings().disableLangAutodetec) { + this.electronService.detectLang(text); + } } getSelectedLanguage(): ILanguage { diff --git a/src/app/states/settings.state.ts b/src/app/states/settings.state.ts index 2c6b9f7b..84a4c104 100644 --- a/src/app/states/settings.state.ts +++ b/src/app/states/settings.state.ts @@ -84,6 +84,7 @@ export class GlobalSettings { configuredLanguages: ILanguage[] = []; selectedLanguage: ILanguage; + disableLangAutodetec: boolean; } export interface ILanguage { @@ -181,6 +182,7 @@ export class SettingsState { newSettings.twitterBridgeInstance = oldSettings.twitterBridgeInstance; newSettings.configuredLanguages = oldSettings.configuredLanguages; newSettings.selectedLanguage = oldSettings.selectedLanguage; + newSettings.disableLangAutodetec = oldSettings.disableLangAutodetec; return newSettings; } From 450a0088d54d0792e61a296c8e6f1944d49ac6e9 Mon Sep 17 00:00:00 2001 From: Nicolas Constant Date: Sat, 12 Aug 2023 17:59:34 -0400 Subject: [PATCH 5/6] added alt label display option, fix #387 --- .../settings/settings.component.html | 19 +++++++++++++------ .../settings/settings.component.ts | 10 ++++++++++ .../attachement-image.component.html | 3 ++- .../attachement-image.component.scss | 18 ++++++++++++++++++ .../attachement-image.component.ts | 8 +++++++- src/app/states/settings.state.ts | 3 +++ 6 files changed, 53 insertions(+), 8 deletions(-) diff --git a/src/app/components/floating-column/settings/settings.component.html b/src/app/components/floating-column/settings/settings.component.html index f5764f81..d4d9f31e 100644 --- a/src/app/components/floating-column/settings/settings.component.html +++ b/src/app/components/floating-column/settings/settings.component.html @@ -69,13 +69,13 @@ add
- + - + (change)="onDisableLangAutodetectChanged()" type="checkbox" name="disableLangAutodetec" + value="disableLangAutodetec" id="disableLangAutodetec"> +

Twitter Bridge

@@ -167,7 +167,8 @@ - +
loading behavior:
@@ -194,7 +195,8 @@ - +
@@ -207,6 +209,11 @@
+ + +

About

diff --git a/src/app/components/floating-column/settings/settings.component.ts b/src/app/components/floating-column/settings/settings.component.ts index 89d4e178..090911aa 100644 --- a/src/app/components/floating-column/settings/settings.component.ts +++ b/src/app/components/floating-column/settings/settings.component.ts @@ -30,6 +30,7 @@ export class SettingsComponent implements OnInit, OnDestroy { disableAvatarNotificationsEnabled: boolean; disableSoundsEnabled: boolean; disableLangAutodetectEnabled: boolean; + enableAltLabelEnabled: boolean; version: string; hasPleromaAccount: boolean; @@ -148,6 +149,7 @@ export class SettingsComponent implements OnInit, OnDestroy { this.configuredLangs = this.languageService.getConfiguredLanguages(); this.disableLangAutodetectEnabled = settings.disableLangAutodetec; + this.enableAltLabelEnabled = settings.enableAltLabel; } ngOnDestroy(): void { @@ -275,6 +277,14 @@ export class SettingsComponent implements OnInit, OnDestroy { return false; } + + onEnableAltLabelChanged(){ + this.notifyRestartNeeded(); + let settings = this.settingsService.getSettings(); + settings.enableAltLabel = this.enableAltLabelEnabled; + this.settingsService.saveSettings(settings); + } + onDisableLangAutodetectChanged() { this.notifyRestartNeeded(); let settings = this.settingsService.getSettings(); diff --git a/src/app/components/stream/status/attachements/attachement-image/attachement-image.component.html b/src/app/components/stream/status/attachements/attachement-image/attachement-image.component.html index 10275faa..957bb122 100644 --- a/src/app/components/stream/status/attachements/attachement-image/attachement-image.component.html +++ b/src/app/components/stream/status/attachements/attachement-image/attachement-image.component.html @@ -1,4 +1,5 @@ -
+
+
ALT
diff --git a/src/app/components/stream/status/attachements/attachement-image/attachement-image.component.scss b/src/app/components/stream/status/attachements/attachement-image/attachement-image.component.scss index f270e80a..44a95067 100644 --- a/src/app/components/stream/status/attachements/attachement-image/attachement-image.component.scss +++ b/src/app/components/stream/status/attachements/attachement-image/attachement-image.component.scss @@ -29,6 +29,24 @@ opacity: 1; cursor: pointer; } + + &__alt { + display: inline; + color: white; + + z-index: 10; + + position: absolute; + bottom: 5px; + left: 5px; + + font-size: 10px; + font-weight: bolder; + + background-color: rgba($color: #000000, $alpha: 0.5); + border-radius: 3px; + padding: 2px 5px; + } } img, diff --git a/src/app/components/stream/status/attachements/attachement-image/attachement-image.component.ts b/src/app/components/stream/status/attachements/attachement-image/attachement-image.component.ts index 052cc501..2568f66b 100644 --- a/src/app/components/stream/status/attachements/attachement-image/attachement-image.component.ts +++ b/src/app/components/stream/status/attachements/attachement-image/attachement-image.component.ts @@ -1,6 +1,7 @@ import { Component, OnInit, Input, Output, EventEmitter } from '@angular/core'; import { faLink } from "@fortawesome/free-solid-svg-icons"; +import { SettingsService } from '../../../../../services/settings.service'; import { Attachment } from '../../../../../services/models/mastodon.interfaces'; @Component({ @@ -10,11 +11,16 @@ import { Attachment } from '../../../../../services/models/mastodon.interfaces'; }) export class AttachementImageComponent implements OnInit { faLink = faLink; + displayAltLabel: boolean; @Input() attachment: Attachment; @Output() openEvent = new EventEmitter(); - constructor() { } + constructor( + private readonly settingsService: SettingsService + ) { + this.displayAltLabel = this.settingsService.getSettings().enableAltLabel; + } ngOnInit() { } diff --git a/src/app/states/settings.state.ts b/src/app/states/settings.state.ts index 84a4c104..03e2543d 100644 --- a/src/app/states/settings.state.ts +++ b/src/app/states/settings.state.ts @@ -85,6 +85,8 @@ export class GlobalSettings { configuredLanguages: ILanguage[] = []; selectedLanguage: ILanguage; disableLangAutodetec: boolean; + + enableAltLabel: boolean; } export interface ILanguage { @@ -183,6 +185,7 @@ export class SettingsState { newSettings.configuredLanguages = oldSettings.configuredLanguages; newSettings.selectedLanguage = oldSettings.selectedLanguage; newSettings.disableLangAutodetec = oldSettings.disableLangAutodetec; + newSettings.enableAltLabel = oldSettings.enableAltLabel; return newSettings; } From 2def5725f5db9dd8f7d86b2f31f729745d1f0130 Mon Sep 17 00:00:00 2001 From: Nicolas Constant Date: Sat, 12 Aug 2023 18:41:41 -0400 Subject: [PATCH 6/6] option to stop animated avatar, fix #335 --- .../settings/settings.component.html | 6 ++++++ .../floating-column/settings/settings.component.ts | 8 ++++++++ .../components/stream/status/status.component.html | 6 +++--- .../components/stream/status/status.component.ts | 14 ++++++++++++++ src/app/states/settings.state.ts | 2 ++ 5 files changed, 33 insertions(+), 3 deletions(-) diff --git a/src/app/components/floating-column/settings/settings.component.html b/src/app/components/floating-column/settings/settings.component.html index d4d9f31e..ea108557 100644 --- a/src/app/components/floating-column/settings/settings.component.html +++ b/src/app/components/floating-column/settings/settings.component.html @@ -214,6 +214,12 @@ (change)="onEnableAltLabelChanged()" type="checkbox" name="enableAltLabel" value="enableAltLabel" id="enableAltLabel"> +
+ + +

About

diff --git a/src/app/components/floating-column/settings/settings.component.ts b/src/app/components/floating-column/settings/settings.component.ts index 090911aa..30139494 100644 --- a/src/app/components/floating-column/settings/settings.component.ts +++ b/src/app/components/floating-column/settings/settings.component.ts @@ -31,6 +31,7 @@ export class SettingsComponent implements OnInit, OnDestroy { disableSoundsEnabled: boolean; disableLangAutodetectEnabled: boolean; enableAltLabelEnabled: boolean; + enableFreezeAvatarEnabled: boolean; version: string; hasPleromaAccount: boolean; @@ -150,6 +151,7 @@ export class SettingsComponent implements OnInit, OnDestroy { this.configuredLangs = this.languageService.getConfiguredLanguages(); this.disableLangAutodetectEnabled = settings.disableLangAutodetec; this.enableAltLabelEnabled = settings.enableAltLabel; + this.enableFreezeAvatarEnabled = settings.enableFreezeAvatar; } ngOnDestroy(): void { @@ -277,6 +279,12 @@ export class SettingsComponent implements OnInit, OnDestroy { return false; } + onEnableFreezeAvatarChanged(){ + this.notifyRestartNeeded(); + let settings = this.settingsService.getSettings(); + settings.enableFreezeAvatar = this.enableFreezeAvatarEnabled; + this.settingsService.saveSettings(settings); + } onEnableAltLabelChanged(){ this.notifyRestartNeeded(); diff --git a/src/app/components/stream/status/status.component.html b/src/app/components/stream/status/status.component.html index 7257da73..48035763 100644 --- a/src/app/components/stream/status/status.component.html +++ b/src/app/components/stream/status/status.component.html @@ -2,7 +2,7 @@
boosted + (auxclick)="openUrl(status.account.url)"> boosted
@@ -60,9 +60,9 @@
- + - + (); @@ -103,6 +106,7 @@ export class StatusComponent implements OnInit { constructor( public elem: ElementRef, private readonly toolsService: ToolsService, + private readonly settingsService: SettingsService, private readonly statusesStateService: StatusesStateService) { } ngOnInit() { @@ -111,12 +115,22 @@ export class StatusComponent implements OnInit { this.statusWrapper = notification.editedStatus; } }); + + this.freezeAvatarEnabled = this.settingsService.getSettings().enableFreezeAvatar; } ngOnDestroy() { if (this.statusesStateServiceSub) this.statusesStateServiceSub.unsubscribe(); } + getAvatar(acc: Account): string { + if(this.freezeAvatarEnabled){ + return acc.avatar_static; + } else { + return acc.avatar; + } + } + private ensureMentionAreDisplayed(data: string): string { const mentions = this.displayedStatus.mentions; if (!mentions || mentions.length === 0) return data; diff --git a/src/app/states/settings.state.ts b/src/app/states/settings.state.ts index 03e2543d..05778012 100644 --- a/src/app/states/settings.state.ts +++ b/src/app/states/settings.state.ts @@ -87,6 +87,7 @@ export class GlobalSettings { disableLangAutodetec: boolean; enableAltLabel: boolean; + enableFreezeAvatar: boolean; } export interface ILanguage { @@ -186,6 +187,7 @@ export class SettingsState { newSettings.selectedLanguage = oldSettings.selectedLanguage; newSettings.disableLangAutodetec = oldSettings.disableLangAutodetec; newSettings.enableAltLabel = oldSettings.enableAltLabel; + newSettings.enableFreezeAvatar = oldSettings.enableFreezeAvatar; return newSettings; }