Skip to content

Commit caaa0c8

Browse files
committed
Implement application profile as enum
1 parent 7fc9bdb commit caaa0c8

File tree

7 files changed

+23
-13
lines changed

7 files changed

+23
-13
lines changed

app/src/config.rs.in

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1+
use crate::controllers::ApplicationProfile;
2+
13
pub const APP_ID: &str = @APP_ID@;
24
pub const GETTEXT_PACKAGE: &str = @GETTEXT_PACKAGE@;
35
pub const LOCALEDIR: &str = @LOCALEDIR@;
46
pub const PKGDATADIR: &str = @PKGDATADIR@;
5-
pub const PROFILE: &str = @PROFILE@;
7+
pub const PROFILE: ApplicationProfile = ApplicationProfile::@PROFILE@;
68
pub const RESOURCES_FILE: &str = concat!(@PKGDATADIR@, "/resources.gresource");
79
pub const VERSION: &str = @VERSION@;

app/src/controllers/application.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,12 @@ use std::rc::Rc;
2525
//@TODO find a better place for this
2626
const TEST_SERVER_EMAIL: &str = "[email protected]";
2727

28+
#[derive(Debug, PartialEq)]
29+
pub enum ApplicationProfile {
30+
Default,
31+
Devel,
32+
}
33+
2834
#[derive(Debug)]
2935
pub enum ApplicationMessage {
3036
Setup {},
@@ -697,7 +703,7 @@ impl Application {
697703

698704
pub fn run(&self) -> glib::ExitCode {
699705
info!("Envoyer ({})", APP_ID);
700-
info!("Version: {} ({})", VERSION, PROFILE);
706+
info!("Version: {} ({:?})", VERSION, PROFILE);
701707
info!("Datadir: {}", PKGDATADIR);
702708

703709
ApplicationExtManual::run(self)

app/src/controllers/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ mod application;
22

33
pub use application::Application;
44
pub use application::ApplicationMessage;
5+
pub use application::ApplicationProfile;

app/src/main.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,16 @@ mod ui;
1919
#[rustfmt::skip]
2020
mod config;
2121

22+
use controllers::ApplicationProfile;
2223
use gettextrs::{gettext, LocaleCategory};
2324
use gtk::{gio, glib};
2425

2526
use adw;
2627
use adw::prelude::*;
2728

28-
use self::config::{GETTEXT_PACKAGE, LOCALEDIR, RESOURCES_FILE, PROFILE};
29+
use self::config::{GETTEXT_PACKAGE, LOCALEDIR, PROFILE, RESOURCES_FILE};
2930

30-
use log::{Level, LevelFilter, Metadata, Record, debug};
31+
use log::{debug, Level, LevelFilter, Metadata, Record};
3132

3233
struct SimpleLogger;
3334

@@ -67,9 +68,9 @@ fn main() -> glib::ExitCode {
6768

6869
let app = controllers::Application::default();
6970

70-
if PROFILE == "devel" {
71+
if PROFILE == ApplicationProfile::Devel {
7172
debug!("Detected development build");
72-
73+
7374
app.add_main_option(
7475
"with-test-server",
7576
b't'.into(),

app/src/meson.build

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1+
profile = get_option('profile')
2+
profile_ucfirst = profile[0].to_upper() + profile.substring(1)
3+
14
global_conf = configuration_data()
25
global_conf.set_quoted('APP_ID', application_id)
36
global_conf.set_quoted('PKGDATADIR', pkgdatadir)
4-
global_conf.set_quoted('PROFILE', profile)
7+
global_conf.set('PROFILE', profile_ucfirst)
58
global_conf.set_quoted('VERSION', version + version_suffix)
69
global_conf.set_quoted('GETTEXT_PACKAGE', gettext_package)
710
global_conf.set_quoted('LOCALEDIR', localedir)

app/src/ui/window.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use std::rc::Rc;
2020

2121
use crate::bindings;
2222
use crate::config::{APP_ID, PROFILE};
23-
use crate::controllers::{Application, ApplicationMessage};
23+
use crate::controllers::{Application, ApplicationMessage, ApplicationProfile};
2424
use crate::models;
2525
use crate::models::folder_conversations_list::row_data::ConversationRowData;
2626

@@ -115,8 +115,7 @@ mod imp {
115115
self.parent_constructed();
116116
let obj = self.obj();
117117

118-
// Devel Profile
119-
if PROFILE == "Devel" {
118+
if PROFILE == ApplicationProfile::Devel {
120119
obj.add_css_class("devel");
121120
}
122121

meson.build

+1-3
Original file line numberDiff line numberDiff line change
@@ -36,16 +36,14 @@ podir = meson.project_source_root() / 'po'
3636
gettext_package = meson.project_name()
3737

3838
if get_option('profile') == 'devel'
39-
profile = 'devel'
4039
vcs_tag = run_command('git', 'rev-parse', '--short', 'HEAD', check: false).stdout().strip()
4140
if vcs_tag == ''
4241
version_suffix = '-devel'
4342
else
4443
version_suffix = '-@0@'.format(vcs_tag)
4544
endif
46-
application_id = '@0@.@1@'.format(base_id, profile)
45+
application_id = '@0@.@1@'.format(base_id, get_option('profile'))
4746
else
48-
profile = ''
4947
version_suffix = ''
5048
application_id = base_id
5149
endif

0 commit comments

Comments
 (0)