mirror of
https://github.com/KRTirtho/spotube.git
synced 2025-09-13 07:55:18 +00:00
uri_launch canLaunch interfering with flatpak bugfix
Change theme manually support
This commit is contained in:
parent
8acd6c106a
commit
00acdf598d
@ -1,4 +1,3 @@
|
|||||||
import 'package:flutter/cupertino.dart';
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:provider/provider.dart';
|
import 'package:provider/provider.dart';
|
||||||
import 'package:shared_preferences/shared_preferences.dart';
|
import 'package:shared_preferences/shared_preferences.dart';
|
||||||
@ -9,6 +8,8 @@ import 'package:spotube/helpers/server_ipc.dart';
|
|||||||
import 'package:spotube/models/LocalStorageKeys.dart';
|
import 'package:spotube/models/LocalStorageKeys.dart';
|
||||||
import 'package:spotube/provider/Auth.dart';
|
import 'package:spotube/provider/Auth.dart';
|
||||||
|
|
||||||
|
const redirectUri = "http://localhost:4304/auth/spotify/callback";
|
||||||
|
|
||||||
class Login extends StatefulWidget {
|
class Login extends StatefulWidget {
|
||||||
@override
|
@override
|
||||||
_LoginState createState() => _LoginState();
|
_LoginState createState() => _LoginState();
|
||||||
@ -31,7 +32,6 @@ class _LoginState extends State<Login> {
|
|||||||
}
|
}
|
||||||
final credentials = SpotifyApiCredentials(clientId, clientSecret);
|
final credentials = SpotifyApiCredentials(clientId, clientSecret);
|
||||||
final grant = SpotifyApi.authorizationCodeGrant(credentials);
|
final grant = SpotifyApi.authorizationCodeGrant(credentials);
|
||||||
const redirectUri = "http://localhost:4304/auth/spotify/callback";
|
|
||||||
|
|
||||||
final authUri = grant.getAuthorizationUrl(Uri.parse(redirectUri),
|
final authUri = grant.getAuthorizationUrl(Uri.parse(redirectUri),
|
||||||
scopes: spotifyScopes);
|
scopes: spotifyScopes);
|
||||||
|
@ -2,6 +2,7 @@ import 'package:flutter/material.dart';
|
|||||||
import 'package:provider/provider.dart';
|
import 'package:provider/provider.dart';
|
||||||
import 'package:shared_preferences/shared_preferences.dart';
|
import 'package:shared_preferences/shared_preferences.dart';
|
||||||
import 'package:spotube/components/PageWindowTitleBar.dart';
|
import 'package:spotube/components/PageWindowTitleBar.dart';
|
||||||
|
import 'package:spotube/main.dart';
|
||||||
import 'package:spotube/models/LocalStorageKeys.dart';
|
import 'package:spotube/models/LocalStorageKeys.dart';
|
||||||
import 'package:spotube/provider/Auth.dart';
|
import 'package:spotube/provider/Auth.dart';
|
||||||
import 'package:spotube/provider/UserPreferences.dart';
|
import 'package:spotube/provider/UserPreferences.dart';
|
||||||
@ -50,63 +51,100 @@ class _SettingsState extends State<Settings> {
|
|||||||
),
|
),
|
||||||
const SizedBox(height: 10),
|
const SizedBox(height: 10),
|
||||||
Padding(
|
Padding(
|
||||||
padding: const EdgeInsets.all(10),
|
padding: const EdgeInsets.all(16.0),
|
||||||
child: Row(
|
child: Column(
|
||||||
children: [
|
children: [
|
||||||
Expanded(
|
Row(
|
||||||
flex: 2,
|
children: [
|
||||||
child: Text(
|
Expanded(
|
||||||
"Genius Access Token",
|
flex: 2,
|
||||||
style: Theme.of(context).textTheme.subtitle1,
|
child: Text(
|
||||||
),
|
"Genius Access Token",
|
||||||
),
|
style: Theme.of(context).textTheme.subtitle1,
|
||||||
Expanded(
|
),
|
||||||
flex: 1,
|
|
||||||
child: TextField(
|
|
||||||
controller: _textEditingController,
|
|
||||||
decoration: InputDecoration(
|
|
||||||
hintText: preferences.geniusAccessToken,
|
|
||||||
),
|
),
|
||||||
),
|
Expanded(
|
||||||
|
flex: 1,
|
||||||
|
child: TextField(
|
||||||
|
controller: _textEditingController,
|
||||||
|
decoration: InputDecoration(
|
||||||
|
hintText: preferences.geniusAccessToken,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
Padding(
|
||||||
|
padding: const EdgeInsets.all(8.0),
|
||||||
|
child: ElevatedButton(
|
||||||
|
onPressed: _geniusAccessToken != null
|
||||||
|
? () async {
|
||||||
|
SharedPreferences localStorage =
|
||||||
|
await SharedPreferences.getInstance();
|
||||||
|
preferences
|
||||||
|
.setGeniusAccessToken(_geniusAccessToken);
|
||||||
|
localStorage.setString(
|
||||||
|
LocalStorageKeys.geniusAccessToken,
|
||||||
|
_geniusAccessToken!);
|
||||||
|
setState(() {
|
||||||
|
_geniusAccessToken = null;
|
||||||
|
});
|
||||||
|
_textEditingController?.text = "";
|
||||||
|
}
|
||||||
|
: null,
|
||||||
|
child: const Text("Save"),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
],
|
||||||
),
|
),
|
||||||
Padding(
|
const SizedBox(height: 10),
|
||||||
padding: const EdgeInsets.all(8.0),
|
Row(
|
||||||
child: ElevatedButton(
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||||
onPressed: _geniusAccessToken != null
|
children: [
|
||||||
? () async {
|
const Text("Theme"),
|
||||||
SharedPreferences localStorage =
|
DropdownButton<ThemeMode>(
|
||||||
await SharedPreferences.getInstance();
|
value: MyApp.of(context)?.getThemeMode(),
|
||||||
preferences
|
items: const [
|
||||||
.setGeniusAccessToken(_geniusAccessToken);
|
DropdownMenuItem(
|
||||||
localStorage.setString(
|
child: Text(
|
||||||
LocalStorageKeys.geniusAccessToken,
|
"Dark",
|
||||||
_geniusAccessToken!);
|
),
|
||||||
setState(() {
|
value: ThemeMode.dark,
|
||||||
_geniusAccessToken = null;
|
),
|
||||||
});
|
DropdownMenuItem(
|
||||||
_textEditingController?.text = "";
|
child: Text(
|
||||||
}
|
"Light",
|
||||||
: null,
|
),
|
||||||
child: const Text("Save"),
|
value: ThemeMode.light,
|
||||||
),
|
),
|
||||||
)
|
DropdownMenuItem(
|
||||||
|
child: Text("System"),
|
||||||
|
value: ThemeMode.system,
|
||||||
|
),
|
||||||
|
],
|
||||||
|
onChanged: (value) {
|
||||||
|
if (value != null) {
|
||||||
|
MyApp.of(context)?.setThemeMode(value);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
)
|
||||||
|
],
|
||||||
|
),
|
||||||
|
const SizedBox(height: 10),
|
||||||
|
Builder(builder: (context) {
|
||||||
|
var auth = context.read<Auth>();
|
||||||
|
return ElevatedButton(
|
||||||
|
child: const Text("Logout"),
|
||||||
|
onPressed: () async {
|
||||||
|
SharedPreferences localStorage =
|
||||||
|
await SharedPreferences.getInstance();
|
||||||
|
await localStorage.clear();
|
||||||
|
auth.logout();
|
||||||
|
Navigator.of(context).pop();
|
||||||
|
},
|
||||||
|
);
|
||||||
|
})
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
const SizedBox(height: 10),
|
|
||||||
Builder(builder: (context) {
|
|
||||||
var auth = context.read<Auth>();
|
|
||||||
return ElevatedButton(
|
|
||||||
child: const Text("Logout"),
|
|
||||||
onPressed: () async {
|
|
||||||
SharedPreferences localStorage =
|
|
||||||
await SharedPreferences.getInstance();
|
|
||||||
await localStorage.clear();
|
|
||||||
auth.logout();
|
|
||||||
Navigator.of(context).pop();
|
|
||||||
},
|
|
||||||
);
|
|
||||||
})
|
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
@ -4,10 +4,8 @@ import 'package:url_launcher/url_launcher.dart';
|
|||||||
|
|
||||||
Future<String?> connectIpc(String authUri, String redirectUri) async {
|
Future<String?> connectIpc(String authUri, String redirectUri) async {
|
||||||
try {
|
try {
|
||||||
if (await canLaunch(authUri)) {
|
print("[Launching]: $authUri");
|
||||||
print("[Launching]: $authUri");
|
await launch(authUri);
|
||||||
await launch(authUri);
|
|
||||||
}
|
|
||||||
|
|
||||||
HttpServer server =
|
HttpServer server =
|
||||||
await HttpServer.bind(InternetAddress.loopbackIPv4, 4304);
|
await HttpServer.bind(InternetAddress.loopbackIPv4, 4304);
|
||||||
@ -32,7 +30,9 @@ Future<String?> connectIpc(String authUri, String redirectUri) async {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error, stack) {
|
||||||
throw error;
|
print("[connectIpc]: $error");
|
||||||
|
print(stack);
|
||||||
|
rethrow;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -24,7 +24,52 @@ void main() async {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
class MyApp extends StatelessWidget {
|
class MyApp extends StatefulWidget {
|
||||||
|
static _MyAppState? of(BuildContext context) =>
|
||||||
|
context.findAncestorStateOfType<_MyAppState>();
|
||||||
|
@override
|
||||||
|
State<MyApp> createState() => _MyAppState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _MyAppState extends State<MyApp> {
|
||||||
|
ThemeMode _themeMode = ThemeMode.system;
|
||||||
|
|
||||||
|
@override
|
||||||
|
void initState() {
|
||||||
|
WidgetsBinding.instance?.addPostFrameCallback((timeStamp) async {
|
||||||
|
SharedPreferences localStorage = await SharedPreferences.getInstance();
|
||||||
|
String? themeMode = localStorage.getString(LocalStorageKeys.themeMode);
|
||||||
|
|
||||||
|
setState(() {
|
||||||
|
switch (themeMode) {
|
||||||
|
case "light":
|
||||||
|
_themeMode = ThemeMode.light;
|
||||||
|
break;
|
||||||
|
case "dark":
|
||||||
|
_themeMode = ThemeMode.dark;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
_themeMode = ThemeMode.system;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
super.initState();
|
||||||
|
}
|
||||||
|
|
||||||
|
void setThemeMode(ThemeMode themeMode) {
|
||||||
|
SharedPreferences.getInstance().then((localStorage) {
|
||||||
|
localStorage.setString(
|
||||||
|
LocalStorageKeys.themeMode, themeMode.toString().split(".").last);
|
||||||
|
setState(() {
|
||||||
|
_themeMode = themeMode;
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
ThemeMode getThemeMode() {
|
||||||
|
return _themeMode;
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return MultiProvider(
|
return MultiProvider(
|
||||||
@ -145,7 +190,7 @@ class MyApp extends StatelessWidget {
|
|||||||
unselectedIconTheme: const IconThemeData(opacity: 1),
|
unselectedIconTheme: const IconThemeData(opacity: 1),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
themeMode: ThemeMode.system,
|
themeMode: _themeMode,
|
||||||
home: const Home(),
|
home: const Home(),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
@ -5,4 +5,6 @@ abstract class LocalStorageKeys {
|
|||||||
static String refreshToken = 'refresh_token';
|
static String refreshToken = 'refresh_token';
|
||||||
static String expiration = "expiration";
|
static String expiration = "expiration";
|
||||||
static String geniusAccessToken = "genius_access_token";
|
static String geniusAccessToken = "genius_access_token";
|
||||||
|
|
||||||
|
static String themeMode = "theme_mode";
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user