diff options
Diffstat (limited to 'client/src/app/core')
-rw-r--r-- | client/src/app/core/auth/auth-user.model.ts | 15 | ||||
-rw-r--r-- | client/src/app/core/theme/theme.service.ts | 31 |
2 files changed, 18 insertions, 28 deletions
diff --git a/client/src/app/core/auth/auth-user.model.ts b/client/src/app/core/auth/auth-user.model.ts index 1447daead..4ad904beb 100644 --- a/client/src/app/core/auth/auth-user.model.ts +++ b/client/src/app/core/auth/auth-user.model.ts | |||
@@ -67,17 +67,6 @@ class Tokens { | |||
67 | } | 67 | } |
68 | 68 | ||
69 | export class AuthUser extends User implements ServerMyUserModel { | 69 | export class AuthUser extends User implements ServerMyUserModel { |
70 | private static KEYS = { | ||
71 | ID: 'id', | ||
72 | ROLE: 'role', | ||
73 | EMAIL: 'email', | ||
74 | VIDEOS_HISTORY_ENABLED: 'videos-history-enabled', | ||
75 | USERNAME: 'username', | ||
76 | NSFW_POLICY: 'nsfw_policy', | ||
77 | WEBTORRENT_ENABLED: 'peertube-videojs-' + 'webtorrent_enabled', | ||
78 | AUTO_PLAY_VIDEO: 'auto_play_video' | ||
79 | } | ||
80 | |||
81 | tokens: Tokens | 70 | tokens: Tokens |
82 | specialPlaylists: MyUserSpecialPlaylist[] | 71 | specialPlaylists: MyUserSpecialPlaylist[] |
83 | 72 | ||
@@ -106,10 +95,6 @@ export class AuthUser extends User implements ServerMyUserModel { | |||
106 | peertubeLocalStorage.removeItem(this.KEYS.USERNAME) | 95 | peertubeLocalStorage.removeItem(this.KEYS.USERNAME) |
107 | peertubeLocalStorage.removeItem(this.KEYS.ID) | 96 | peertubeLocalStorage.removeItem(this.KEYS.ID) |
108 | peertubeLocalStorage.removeItem(this.KEYS.ROLE) | 97 | peertubeLocalStorage.removeItem(this.KEYS.ROLE) |
109 | peertubeLocalStorage.removeItem(this.KEYS.NSFW_POLICY) | ||
110 | peertubeLocalStorage.removeItem(this.KEYS.WEBTORRENT_ENABLED) | ||
111 | peertubeLocalStorage.removeItem(this.KEYS.VIDEOS_HISTORY_ENABLED) | ||
112 | peertubeLocalStorage.removeItem(this.KEYS.AUTO_PLAY_VIDEO) | ||
113 | peertubeLocalStorage.removeItem(this.KEYS.EMAIL) | 98 | peertubeLocalStorage.removeItem(this.KEYS.EMAIL) |
114 | Tokens.flush() | 99 | Tokens.flush() |
115 | } | 100 | } |
diff --git a/client/src/app/core/theme/theme.service.ts b/client/src/app/core/theme/theme.service.ts index 2c5873cb3..3c066ca74 100644 --- a/client/src/app/core/theme/theme.service.ts +++ b/client/src/app/core/theme/theme.service.ts | |||
@@ -4,16 +4,15 @@ import { ServerService } from '@app/core/server' | |||
4 | import { environment } from '../../../environments/environment' | 4 | import { environment } from '../../../environments/environment' |
5 | import { PluginService } from '@app/core/plugins/plugin.service' | 5 | import { PluginService } from '@app/core/plugins/plugin.service' |
6 | import { ServerConfig, ServerConfigTheme } from '@shared/models' | 6 | import { ServerConfig, ServerConfigTheme } from '@shared/models' |
7 | import { peertubeLocalStorage } from '@app/shared/misc/peertube-web-storage' | ||
8 | import { first } from 'rxjs/operators' | 7 | import { first } from 'rxjs/operators' |
8 | import { User } from '@app/shared/users/user.model' | ||
9 | import { UserService } from '@app/shared/users/user.service' | ||
10 | import { LocalStorageService } from '@app/shared/misc/storage.service' | ||
11 | import { peertubeLocalStorage } from '@app/shared/misc/peertube-web-storage' | ||
9 | 12 | ||
10 | @Injectable() | 13 | @Injectable() |
11 | export class ThemeService { | 14 | export class ThemeService { |
12 | 15 | ||
13 | private static KEYS = { | ||
14 | LAST_ACTIVE_THEME: 'last_active_theme' | ||
15 | } | ||
16 | |||
17 | private oldThemeName: string | 16 | private oldThemeName: string |
18 | private themes: ServerConfigTheme[] = [] | 17 | private themes: ServerConfigTheme[] = [] |
19 | 18 | ||
@@ -24,8 +23,10 @@ export class ThemeService { | |||
24 | 23 | ||
25 | constructor ( | 24 | constructor ( |
26 | private auth: AuthService, | 25 | private auth: AuthService, |
26 | private userService: UserService, | ||
27 | private pluginService: PluginService, | 27 | private pluginService: PluginService, |
28 | private server: ServerService | 28 | private server: ServerService, |
29 | private localStorageService: LocalStorageService | ||
29 | ) {} | 30 | ) {} |
30 | 31 | ||
31 | initialize () { | 32 | initialize () { |
@@ -77,11 +78,11 @@ export class ThemeService { | |||
77 | private getCurrentTheme () { | 78 | private getCurrentTheme () { |
78 | if (this.themeFromLocalStorage) return this.themeFromLocalStorage.name | 79 | if (this.themeFromLocalStorage) return this.themeFromLocalStorage.name |
79 | 80 | ||
80 | if (this.auth.isLoggedIn()) { | 81 | const theme = this.auth.isLoggedIn() |
81 | const theme = this.auth.getUser().theme | 82 | ? this.auth.getUser().theme |
82 | if (theme !== 'instance-default') return theme | 83 | : this.userService.getAnonymousUser().theme |
83 | } | ||
84 | 84 | ||
85 | if (theme !== 'instance-default') return theme | ||
85 | return this.serverConfig.theme.default | 86 | return this.serverConfig.theme.default |
86 | } | 87 | } |
87 | 88 | ||
@@ -111,9 +112,9 @@ export class ThemeService { | |||
111 | 112 | ||
112 | this.pluginService.reloadLoadedScopes() | 113 | this.pluginService.reloadLoadedScopes() |
113 | 114 | ||
114 | peertubeLocalStorage.setItem(ThemeService.KEYS.LAST_ACTIVE_THEME, JSON.stringify(theme)) | 115 | this.localStorageService.setItem(User.KEYS.THEME, JSON.stringify(theme), false) |
115 | } else { | 116 | } else { |
116 | peertubeLocalStorage.removeItem(ThemeService.KEYS.LAST_ACTIVE_THEME) | 117 | this.localStorageService.removeItem(User.KEYS.THEME, false) |
117 | } | 118 | } |
118 | 119 | ||
119 | this.oldThemeName = currentTheme | 120 | this.oldThemeName = currentTheme |
@@ -126,6 +127,10 @@ export class ThemeService { | |||
126 | 127 | ||
127 | if (!this.auth.isLoggedIn()) { | 128 | if (!this.auth.isLoggedIn()) { |
128 | this.updateCurrentTheme() | 129 | this.updateCurrentTheme() |
130 | |||
131 | this.localStorageService.watch([User.KEYS.THEME]).subscribe( | ||
132 | () => this.updateCurrentTheme() | ||
133 | ) | ||
129 | } | 134 | } |
130 | 135 | ||
131 | this.auth.userInformationLoaded | 136 | this.auth.userInformationLoaded |
@@ -134,7 +139,7 @@ export class ThemeService { | |||
134 | } | 139 | } |
135 | 140 | ||
136 | private loadAndSetFromLocalStorage () { | 141 | private loadAndSetFromLocalStorage () { |
137 | const lastActiveThemeString = peertubeLocalStorage.getItem(ThemeService.KEYS.LAST_ACTIVE_THEME) | 142 | const lastActiveThemeString = this.localStorageService.getItem(User.KEYS.THEME) |
138 | if (!lastActiveThemeString) return | 143 | if (!lastActiveThemeString) return |
139 | 144 | ||
140 | try { | 145 | try { |