Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion assets/translations/en-US.json
Original file line number Diff line number Diff line change
Expand Up @@ -200,5 +200,7 @@
"title_screen_recording_mac": "Screen Recording",
"description_screen_recording_mac": "This app would like to record this computer's screen. Grant access to this app in Security & Privacy preferences. located in System Preferences. If it doesn't exists please add manually or if it exists please delete it.",
"screen_recording_issued": "Screen recording not granted",
"note_description_screen_recording_mac": "Always remember to reopen this app after changing permissions."
"note_description_screen_recording_mac": "Always remember to reopen this app after changing permissions.",
"launch_at_startup": "Launch at Startup",
"subtitle_launch_at_startup": "Dipantau will start running automatically when you turn your computer on"
}
1 change: 1 addition & 0 deletions lib/core/util/shared_preferences_manager.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class SharedPreferencesManager {
static const keyIsEnableScreenshotNotification = 'is_enable_screenshot_notification';
static const keyAppearanceMode = 'appearance_mode';
static const keyBaseFilePathScreenshot = 'base_file_path_screenshot';
static const keyIsLaunchAtStartup = 'is_launch_at_startup';

SharedPreferencesManager();

Expand Down
56 changes: 56 additions & 0 deletions lib/feature/presentation/page/setting/setting_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import 'package:flutter/material.dart';
import 'package:flutter/scheduler.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:go_router/go_router.dart';
import 'package:launch_at_startup/launch_at_startup.dart';

class SettingPage extends StatefulWidget {
static const routePath = '/setting';
Expand All @@ -33,7 +34,9 @@ class _SettingPageState extends State<SettingPage> {
final helper = sl<Helper>();
final valueNotifierIsEnableScreenshotNotification = ValueNotifier(false);
final valueNotifierAppearanceMode = ValueNotifier(AppearanceMode.light);
final valueNotifierLaunchAtStartup = ValueNotifier(true);
final widgetHelper = WidgetHelper();
final sharedPreferencesManager = sl<SharedPreferencesManager>();

var hostname = '';
late AppearanceBloc appearanceBloc;
Expand All @@ -48,6 +51,9 @@ class _SettingPageState extends State<SettingPage> {

@override
void initState() {
launchAtStartup.isEnabled().then((value) {
valueNotifierLaunchAtStartup.value = value;
});
appearanceBloc = BlocProvider.of<AppearanceBloc>(context);
final strUserRole = sharedPreferencesManager.getString(SharedPreferencesManager.keyUserRole) ?? '';
userRole = strUserRole.fromStringUserRole;
Expand Down Expand Up @@ -99,6 +105,8 @@ class _SettingPageState extends State<SettingPage> {
const SizedBox(height: 8),
buildWidgetScreenshotNotification(),
const SizedBox(height: 16),
buildWidgetLaunchAtStartup(),
const SizedBox(height: 16),
buildWidgetSetHostName(),
const SizedBox(height: 16),
buildWidgetCheckForUpdate(),
Expand All @@ -113,8 +121,56 @@ class _SettingPageState extends State<SettingPage> {
);
}

Widget buildWidgetLaunchAtStartup() {
return Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'launch_at_startup'.tr(),
style: Theme.of(context).textTheme.bodyLarge,
),
Text(
'subtitle_launch_at_startup'.tr(),
style: Theme.of(context).textTheme.bodyMedium?.copyWith(
color: Colors.grey,
),
),
],
),
),
const SizedBox(width: 16),
ValueListenableBuilder(
valueListenable: valueNotifierLaunchAtStartup,
builder: (BuildContext context, bool value, _) {
return Switch.adaptive(
value: value,
onChanged: (newValue) async {
if (newValue) {
await launchAtStartup.enable();
} else {
await launchAtStartup.disable();
}
sharedPreferencesManager.putBool(
SharedPreferencesManager.keyIsLaunchAtStartup,
newValue,
);
valueNotifierLaunchAtStartup.value = newValue;
},
activeColor: Theme.of(context).colorScheme.primary,
);
},
),
],
);
}

Widget buildWidgetScreenshotNotification() {
return Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Expanded(
child: Column(
Expand Down
2 changes: 0 additions & 2 deletions lib/feature/presentation/page/splash/splash_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import 'package:dipantau_desktop_client/feature/presentation/widget/widget_custo
import 'package:dipantau_desktop_client/injection_container.dart';
import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';
import 'package:package_info_plus/package_info_plus.dart';

class SplashPage extends StatefulWidget {
static const routePath = '/splash';
Expand All @@ -26,7 +25,6 @@ class _SplashPageState extends State<SplashPage> {
super.initState();
Future.delayed(const Duration(seconds: 1)).then((_) async {
sharedPreferencesManager = await sl.getAsync<SharedPreferencesManager>();
packageInfo = await PackageInfo.fromPlatform();
if (!sharedPreferencesManager.isKeyExists(SharedPreferencesManager.keyAppearanceMode)) {
sharedPreferencesManager.putString(SharedPreferencesManager.keyAppearanceMode, AppearanceMode.light.name);
}
Expand Down
18 changes: 18 additions & 0 deletions lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'dart:io';
import 'dart:ui';

import 'package:auto_updater/auto_updater.dart';
Expand Down Expand Up @@ -31,6 +32,8 @@ import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:go_router/go_router.dart';
import 'package:google_fonts/google_fonts.dart';
import 'package:launch_at_startup/launch_at_startup.dart';
import 'package:package_info_plus/package_info_plus.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:window_manager/window_manager.dart';

Expand Down Expand Up @@ -68,6 +71,14 @@ void main() async {
autoUpdater.setFeedURL(feedURL);
autoUpdater.setScheduledCheckInterval(3600);

packageInfo = await PackageInfo.fromPlatform();

// Launch at startup
launchAtStartup.setup(
appName: packageInfo.appName,
appPath: Platform.resolvedExecutable,
);

// Easy localization
await EasyLocalization.ensureInitialized();

Expand Down Expand Up @@ -274,6 +285,13 @@ class _MyAppState extends State<MyApp> {
updateAppearanceMode(window, sharedPreferencesManager);
};
}

final isLaunchAtStartupExists =
sharedPreferencesManager.isKeyExists(SharedPreferencesManager.keyIsLaunchAtStartup);
if (!isLaunchAtStartupExists) {
await launchAtStartup.enable();
sharedPreferencesManager.putBool(SharedPreferencesManager.keyIsLaunchAtStartup, true);
}
});
super.initState();
}
Expand Down
16 changes: 16 additions & 0 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -557,6 +557,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "6.7.0"
launch_at_startup:
dependency: "direct main"
description:
name: launch_at_startup
sha256: "93fc5638e088290004fae358bae691486673d469957d461d9dae5b12248593eb"
url: "https://pub.dev"
source: hosted
version: "0.2.2"
lints:
dependency: transitive
description:
Expand Down Expand Up @@ -1218,6 +1226,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "5.0.3"
win32_registry:
dependency: transitive
description:
name: win32_registry
sha256: e4506d60b7244251bc59df15656a3093501c37fb5af02105a944d73eb95be4c9
url: "https://pub.dev"
source: hosted
version: "1.1.1"
window_manager:
dependency: "direct main"
description:
Expand Down
3 changes: 3 additions & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,9 @@ dependencies:
# on iOS or versionCode on Android.
package_info_plus: ^4.0.2

# This plugin allow Flutter desktop apps to Auto launch on startup / login.
launch_at_startup: ^0.2.2

dev_dependencies:
flutter_test:
sdk: flutter
Expand Down